From 2b4d2c37d12ece1906572b7d96492d8a8fcd8a10 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Patrick=20Jos=C3=A9=20Pereira?= Date: Sun, 13 Nov 2016 23:20:01 -0200 Subject: [PATCH] Exposer.ino MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Update example with some signals Signed-off-by: Patrick José Pereira --- Exposer.ino | 51 +++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 47 insertions(+), 4 deletions(-) diff --git a/Exposer.ino b/Exposer.ino index 0f1a305..be9db2a 100644 --- a/Exposer.ino +++ b/Exposer.ino @@ -1,9 +1,13 @@ #include "exposer.h" +#include +// 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; @@ -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); @@ -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); @@ -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; } } -