Skip to content

Commit

Permalink
Exposer.ino
Browse files Browse the repository at this point in the history
Update example with some signals

Signed-off-by: Patrick José Pereira <[email protected]>
  • Loading branch information
patrickelectric committed Nov 14, 2016
1 parent b982e43 commit 2b4d2c3
Showing 1 changed file with 47 additions and 4 deletions.
51 changes: 47 additions & 4 deletions Exposer.ino
Original file line number Diff line number Diff line change
@@ -1,9 +1,13 @@
#include "exposer.h"
#include <math.h>

// Declare exposer
Exposer* exposer = &Exposer::self();

uint8_t led = 0;
const float ppi = 2*M_PI;

// Create some variables
uint8_t led = 0;
uint8_t testuint8 = 0;
uint16_t testuint16 = 0;
uint32_t testuint32 = 0;
Expand All @@ -17,8 +21,11 @@ unsigned long next;

void setup()
{
// Hardware initialization
Serial.begin(115200);
pinMode(13, OUTPUT);


exposer->registerVariable(VARNAME(led), Exposer::_uint8_t, &led);
exposer->registerVariable(VARNAME(testuint8), Exposer::_uint8_t, &testuint8);
exposer->registerVariable(VARNAME(testuint16), Exposer::_uint16_t, &testuint16);
Expand All @@ -34,12 +41,47 @@ void setup()

void loop()
{
// Get actual time
unsigned int now = millis();

digitalWrite(13,(testint8==-50));
// Create omega
float w1 = ppi*now/1000;
float w2 = ppi*now/2000;
float w3 = ppi*now/3000;
float w4 = ppi*now/4000;

// Update variables
testuint8 = 100*(sin(w1) + 1);
testuint16 = 100*(sin(w2 + ppi/4) + 1);
testuint32 = 100*(sin(w3 - ppi/4) + 1);
testint8 = 100*sin(w1);
testint16 = 100*sin(w2 + ppi/4);
testint32 = 100*sin(w3 - ppi/4);

// Create square wave
float tempLed = 0.0;
for (unsigned int i = 1; i < 20; i++)
{
tempLed += 50*(sin(ppi*(2*i-1)*now/6000.0)/(2*i+1));
}
tempLed *= 5/M_PI;
led = (uint8_t)(tempLed + 100.0);


// Create triangle wave
for (unsigned int i = testfloat = 0; i < 10; i++)
{
testfloat += pow(-1, i)*sin(ppi*(2*i+1)*now/6000.0)/pow(2*i+1, 2);
}
testfloat *= 100.0*(8/(M_PI*M_PI));

digitalWrite(13, (testint8 > 75));

// Run exposer
exposer->update();

if (millis()>next){
// Write something in serial monitor
if (now>next){
Serial.print("uint8:");Serial.println(testuint8);
Serial.print("uint16:");Serial.println(testuint16);
Serial.print("uint32:");Serial.println(testuint32);
Expand All @@ -48,8 +90,9 @@ void loop()
Serial.print("int32:");Serial.println(testint32);
Serial.print("float:");Serial.println(testfloat);
Serial.print("string:");Serial.println(teststring);

// Write something in 1s
next = millis()+1000;
}

}

0 comments on commit 2b4d2c3

Please sign in to comment.