From 77785f4e436a370c446bb0ab6c7c61f8e3062f29 Mon Sep 17 00:00:00 2001 From: rra Date: Tue, 22 Sep 2020 10:48:54 +0200 Subject: [PATCH] added dedicated normalized plotting function --- pointlights.ino | 33 +++++++++++++++++---------------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/pointlights.ino b/pointlights.ino index e2dcf85..8be9a71 100644 --- a/pointlights.ino +++ b/pointlights.ino @@ -33,9 +33,8 @@ void compose() { case INCREASE: brightness = increase_brightness(brightness, 1); - Serial.print("INCREASING "); - Serial.println(brightness); - + plot("INCREASING", brightness); + if (brightness > 250){ ledState = WAVE; } @@ -43,36 +42,30 @@ void compose() { case DECREASE: brightness = decrease_brightness(brightness, 0.5); - - Serial.print("DECREASING "); - Serial.println(brightness); + plot("DECREASING", brightness); if (brightness == 0){ ledState = OFF; } break; case WAVE: - Serial.print("WAVE "); - Serial.println(brightness); + plot("WAVE", brightness); doForMs(5000, wavyshine); // this you might want to do for number of pulses, rather than for duration ledState = DECREASE; break; case STAY: - Serial.print("STAY" ); - Serial.println(brightness); + plot("STAY", brightness); brightness = brightness; break; case ON: - Serial.print("ON" ); - Serial.println(brightness); + plot("ON", brightness); brightness = 255; break; case OFF: - Serial.print("OFF" ); - Serial.println(brightness); + plot("OFF", brightness); brightness = 0; doAfterMs(5000, goBackOn); break; @@ -86,12 +79,20 @@ void goBackOn(){ } void wavyshine(){ - Serial.print("WAVE "); - Serial.println(brightness); + plot("WAVE", brightness); brightness = sinewave(1000,256,0); // you can tweak the parameters of the sinewave analogWrite(ledPin, brightness); } +void plot(char *state, int brightness){ + // use this function to plot a graph. + // it will normalize the auto-scaling plotter + Serial.print(state); + Serial.print(", "); + Serial.print(brightness); + Serial.println(", 0, 300"); + } + int increase_brightness (int brightness, float velocity){ return brightness = brightness + 1 * velocity; }