From 0492ceafa97f665120422eedc138b752085c31f8 Mon Sep 17 00:00:00 2001 From: Fabiano Riccardi Date: Sun, 16 Dec 2018 16:08:10 +0100 Subject: [PATCH] Typos and messages in examples, keywords.txt is consistent to Arduino specifications Signed-off-by: Fabiano Riccardi --- .../1_dimmable_light/1_dimmable_light.ino | 2 +- .../2_dimmable_lights/2_dimmable_lights.ino | 3 +- .../3_dimmable_light_5_light.ino | 5 +- .../4_dimmable_manager_n_lights.ino | 4 +- .../5_8_lights_effects/5_8_lights_effects.ino | 140 ++++++++++-------- examples/5_8_lights_effects/effect.cpp | 78 ++++++---- examples/5_8_lights_effects/effect.h | 3 +- keywords.txt | 20 +-- 8 files changed, 150 insertions(+), 105 deletions(-) diff --git a/examples/1_dimmable_light/1_dimmable_light.ino b/examples/1_dimmable_light/1_dimmable_light.ino index 8ea3d3a..8f7c22e 100644 --- a/examples/1_dimmable_light/1_dimmable_light.ino +++ b/examples/1_dimmable_light/1_dimmable_light.ino @@ -12,7 +12,7 @@ void setup() { Serial.begin(115200); while(!Serial); Serial.println(); - Serial.println("Test HARDWARE timer for dimmer on ESP8266"); + Serial.println("Dimmer for ESP8266"); Serial.print("Init the dimmable light class... "); DimmableLight::setSyncPin(syncPin); diff --git a/examples/2_dimmable_lights/2_dimmable_lights.ino b/examples/2_dimmable_lights/2_dimmable_lights.ino index 338af5a..2eee7aa 100644 --- a/examples/2_dimmable_lights/2_dimmable_lights.ino +++ b/examples/2_dimmable_lights/2_dimmable_lights.ino @@ -13,7 +13,8 @@ void setup() { Serial.begin(115200); while(!Serial); Serial.println(); - Serial.println("Test HARDWARE timer for dimmer on ESP8266"); + Serial.println("Example for Dimmable Lights for ESP8266"); + Serial.println(); Serial.print("Init the dimmable light class... "); DimmableLight::setSyncPin(syncPin); diff --git a/examples/3_dimmable_light_5_light/3_dimmable_light_5_light.ino b/examples/3_dimmable_light_5_light/3_dimmable_light_5_light.ino index 2480e66..6ef4688 100644 --- a/examples/3_dimmable_light_5_light/3_dimmable_light_5_light.ino +++ b/examples/3_dimmable_light_5_light/3_dimmable_light_5_light.ino @@ -1,5 +1,5 @@ /** - * In this example you will see a number of effect on multiple indipendent + * In this example you will see a number of effects on different indipendent * dimmable lights. To switch between effect, (un)comment the proper line * in the setup function. * @@ -23,7 +23,8 @@ void setup() { Serial.begin(115200); while(!Serial); Serial.println(); - Serial.println("Test HARDWARE timer for dimmer on ESP8266"); + Serial.println("Third example Dimmable Lights for ESP8266"); + Serial.println(); Serial.print("Init the dimmable light class... "); DimmableLight::setSyncPin(syncPin); diff --git a/examples/4_dimmable_manager_n_lights/4_dimmable_manager_n_lights.ino b/examples/4_dimmable_manager_n_lights/4_dimmable_manager_n_lights.ino index 4e28077..00e794c 100644 --- a/examples/4_dimmable_manager_n_lights/4_dimmable_manager_n_lights.ino +++ b/examples/4_dimmable_manager_n_lights/4_dimmable_manager_n_lights.ino @@ -1,5 +1,5 @@ /** - * This advance example aims to show how to use the Dimmable Light Manager. + * This advanced example aims to show how to use the Dimmable Light Manager. * Basically it gives you the ability to add a friendly/logic name to a Dimmable Light. * * The main parameters to configure accordingly to your hardware settings are: @@ -74,7 +74,7 @@ void setup() { if(dlm.add(String("light") + (i+1), pins[i])){ Serial.println(String(" ") + (i+1) + "-th light added correctly"); }else{ - Serial.println(" Light isn't added, probably this was is already used..."); + Serial.println(" Light isn't added, probably this name was already used..."); } } diff --git a/examples/5_8_lights_effects/5_8_lights_effects.ino b/examples/5_8_lights_effects/5_8_lights_effects.ino index e35bf38..2f71f32 100644 --- a/examples/5_8_lights_effects/5_8_lights_effects.ino +++ b/examples/5_8_lights_effects/5_8_lights_effects.ino @@ -12,7 +12,71 @@ SerialCommand serialCmd; int effectSelected = -1; void unrecognized(){ - Serial.println("Command not recognized"); + Serial.println("Command not recognized"); + serialCmd.clearBuffer(); +} + +void selectEffect(unsigned char effectId){ + if(effectSelected != effectId){ + effectSelected = effectId; + + switch(effectSelected){ + case 0: + Serial.println("##New Effect Selected## Equal"); + doEqual(); + break; + case 1: + Serial.println("##New Effect Selected## Equal On Off"); + doEqualOnOff(); + break; + case 2: + Serial.println("##New Effect Selected## Dim Specific Step"); + doDimSpecificStep(); + break; + case 3: + Serial.println("##New Effect Selected## Range Limit"); + doRangeLimit(); + break; + case 4: + Serial.println("##New Effect Selected## Near Values"); + doNearValues(); + break; + case 5: + Serial.println("##New Effect Selected## Dim Mixed"); + doDimMixed(); + break; + case 6: + Serial.println("##New Effect Selected## Dim Sweep Equal"); + doDimSweepEqual(); + break; + case 7: + Serial.println("##New Effect Selected## On Off Sweep"); + doOnOffSweep(); + break; + case 8: + Serial.println("##New Effect Selected## Inverted Dim"); + doInvertedDim(); + break; + case 9: + Serial.println("##New Effect Selected## Circular Swipe"); + doCircularSwipe(); + break; + case 10: + Serial.println("##New Effect Selected## Random Bri"); + doRandomBri(); + break; + case 11: + Serial.println("##New Effect Selected## Random Bri Peehole"); + doRandomBriPeehole(); + break; + case 12: + Serial.println("##New Effect Selected## Random Push Extreme Values"); + doRandomPushExtremeValues(); + break; + default: + Serial.println("Effect ID not implemented"); + } + } } void setup() { @@ -22,11 +86,6 @@ void setup() { Serial.println("Starting the example effect"); Serial.print("Init the dimmable light class... "); - - lights=(DimmableLight**)malloc(sizeof(DimmableLight)*N_LIGHTS); - for(int i=0;isetBrightness(briLevels[brightnessStep]); + lights[i].setBrightness(briLevels[brightnessStep]); } brightnessStep++; @@ -33,7 +33,7 @@ void doEqualOnOff(){ static uint8_t brightnessStep=0; Serial.println(String("Dimming at: ") + briLevels[brightnessStep] + "/255"); for(int i=0;isetBrightness(briLevels[brightnessStep]); + lights[i].setBrightness(briLevels[brightnessStep]); } brightnessStep++; @@ -53,9 +53,9 @@ void doDimSpecificStep(void){ static int briLevels3[]={80,150}; static uint8_t brightnessStep=0; Serial.println(String("Dimming at: ") + briLevels1[brightnessStep] + " and " + briLevels2[brightnessStep] + " and " + briLevels3[brightnessStep] +" /255"); - lights[1]->setBrightness(briLevels1[brightnessStep]); - lights[2]->setBrightness(briLevels2[brightnessStep]); - lights[3]->setBrightness(briLevels3[brightnessStep]); + lights[1].setBrightness(briLevels1[brightnessStep]); + lights[2].setBrightness(briLevels2[brightnessStep]); + lights[3].setBrightness(briLevels3[brightnessStep]); brightnessStep++; if(brightnessStep==sizeof(briLevels1)/sizeof(briLevels1[0])){ @@ -74,9 +74,9 @@ void doRangeLimit(void){ static int briLevels3[]={100,100}; static uint8_t brightnessStep=0; Serial.println(String("Dimming at: ") + briLevels1[brightnessStep] + " and " + briLevels2[brightnessStep] + " and " + briLevels3[brightnessStep] +" /255"); - lights[1]->setBrightness(briLevels1[brightnessStep]); - lights[2]->setBrightness(briLevels2[brightnessStep]); - lights[3]->setBrightness(briLevels3[brightnessStep]); + lights[1].setBrightness(briLevels1[brightnessStep]); + lights[2].setBrightness(briLevels2[brightnessStep]); + lights[3].setBrightness(briLevels3[brightnessStep]); brightnessStep++; if(brightnessStep==sizeof(briLevels1)/sizeof(briLevels1[0])){ @@ -95,9 +95,9 @@ void doNearValues(void){ static int briLevels3[]={72,73}; static uint8_t brightnessStep=0; Serial.println(String("Dimming at: ") + briLevels1[brightnessStep] + " and " + briLevels2[brightnessStep] + " and " + briLevels3[brightnessStep] +" /255"); - lights[1]->setBrightness(briLevels1[brightnessStep]); - lights[2]->setBrightness(briLevels2[brightnessStep]); - lights[3]->setBrightness(briLevels3[brightnessStep]); + lights[1].setBrightness(briLevels1[brightnessStep]); + lights[2].setBrightness(briLevels2[brightnessStep]); + lights[3].setBrightness(briLevels3[brightnessStep]); brightnessStep++; if(brightnessStep==sizeof(briLevels1)/sizeof(briLevels1[0])){ @@ -115,11 +115,11 @@ void doDimMixed(void){ static uint8_t brightnessStep=1; static bool up = true; - lights[1]->setBrightness(brightnessStep); + lights[1].setBrightness(brightnessStep); int b2 = 105; - lights[2]->setBrightness(b2); + lights[2].setBrightness(b2); int b3 = -((int)brightnessStep-255); - lights[3]->setBrightness(b3); + lights[3].setBrightness(b3); Serial.println(String("Dimming at: ") + brightnessStep + " " + b2 + " " + b3 + "/255"); if(brightnessStep==255 && up){ @@ -148,7 +148,7 @@ void doDimSweepEqual(void){ static uint8_t brightnessStep=1; static bool up = true; for(int i=0;isetBrightness(brightnessStep); + lights[i].setBrightness(brightnessStep); } Serial.println(String("Dimming at: ") + brightnessStep + "/255"); @@ -172,9 +172,9 @@ void doOnOffSweep(){ for(int i=0;isetBrightness(255); + lights[i].setBrightness(255); }else{ - lights[i]->setBrightness(0); + lights[i].setBrightness(0); } } @@ -196,9 +196,9 @@ void doInvertedDim(void){ for(int i=0;isetBrightness(brightnessStep); + lights[i].setBrightness(brightnessStep); }else{ - lights[i]->setBrightness(oppositeBrightness); + lights[i].setBrightness(oppositeBrightness); } } Serial.println(String("Dimming at: ") + brightnessStep + " " + oppositeBrightness + "/255"); @@ -271,7 +271,7 @@ void doCircularSwipe(void){ // Alternatively, you can use the function conversionPow(..) instead conversion(..) for(int i=0;isetBrightness(conversion(tap(brightnessStep+32*i,512))); + lights[i].setBrightness(conversion(tap(brightnessStep+32*i,512))); } brightnessStep++; @@ -286,7 +286,7 @@ void doRandomBri(){ for(int i=0;isetBrightness(bri); + lights[i].setBrightness(bri); } dim.once(period,doRandomBri); } @@ -296,21 +296,21 @@ void doRandomBri(){ */ void doRandomBriPeehole(){ const float period = 0.7; - const uint16_t step = 10; + const uint16_t briStep = 10; const uint16_t totStep = 16; static uint16_t iteration = 0; - for(int i=0;i=totStep-3){ bri = 127; }else{ - bri = random(0 + step* iteration,256 - step*iteration); + bri = random(0 + briStep*iteration, 256-briStep*iteration); } - Serial.print(bri);Serial.print(" "); - lights[i]->setBrightness(bri); + Serial.print(String(bri) + " "); + lights[i].setBrightness(bri); } Serial.println(); @@ -318,5 +318,27 @@ void doRandomBriPeehole(){ if(iteration==totStep){ iteration=0; } - dim.once(period,doRandomBriPeehole); + dim.once(period, doRandomBriPeehole); +} + +/** + * The variance of random number is restricted around the mean value step after step + */ +void doRandomPushExtremeValues(){ + const float period = 1; + const uint16_t briStep = 10; + + for(int i=0; i