From 3bf250e14a100cd6dfa65e9ce6994c698f603ce8 Mon Sep 17 00:00:00 2001 From: Juergen Jung Date: Tue, 14 Feb 2017 20:39:52 +0100 Subject: [PATCH] New Larson Scanner --- esp-wemos-schild/esp-wemos-schild.ino | 78 ++++++++++++++++----------- 1 file changed, 47 insertions(+), 31 deletions(-) diff --git a/esp-wemos-schild/esp-wemos-schild.ino b/esp-wemos-schild/esp-wemos-schild.ino index 155be69..9fe0a74 100644 --- a/esp-wemos-schild/esp-wemos-schild.ino +++ b/esp-wemos-schild/esp-wemos-schild.ino @@ -10,6 +10,7 @@ uint16_t effectI=0,effectJ=0,wait = 50; unsigned long lastCall = 0; byte wPos = 0; +uint8_t state = 0; Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); @@ -98,42 +99,57 @@ void loopHandler() { } else if (effect == "larson") { int SpeedDelay = 20; - int ReturnDelay = 50; int EyeSize = 5; uint32_t rgb[3] = {0}; - for(int i = 0; i < pixels.numPixels()-EyeSize-2; i++) { - pixels.clear(); - pixels.show(); - getRGBValues(rgb,wheel(wPos)); - pixels.setPixelColor(i, rgb[0]/10, rgb[1]/10, rgb[2]/10); + switch(state){ + case 0: + if(lastCall + wait < millis()){ + state++; + } - for(int j = 1; j <= EyeSize; j++) { - pixels.setPixelColor(i+j, wheel(wPos++)); - } - uint32_t rgb[3] = {0}; - getRGBValues(rgb,wheel(wPos)); - pixels.setPixelColor(i+EyeSize+1, rgb[0]/10, rgb[1]/10, rgb[2]/10); - pixels.show(); - delay(SpeedDelay); + break; + case 1: + for(int i = 0; i < pixels.numPixels()-EyeSize-2; i++) { + pixels.clear(); + getRGBValues(rgb,wheel(wPos)); + pixels.setPixelColor(i, rgb[0]/10, rgb[1]/10, rgb[2]/10); + for(int j = 1; j <= EyeSize; j++) { + pixels.setPixelColor(i+j, wheel(wPos++)); + } + getRGBValues(rgb,wheel(wPos)); + pixels.setPixelColor(i+EyeSize+1, rgb[0]/10, rgb[1]/10, rgb[2]/10); + pixels.show(); + + delay(SpeedDelay); + } + lastCall = millis(); + state++; + break; + case 2: + if(lastCall + wait < millis()){ + state++; + } + break; + case 3: + for(int i = pixels.numPixels()-EyeSize-2; i > 0; i--) { + pixels.clear(); + getRGBValues(rgb,wheel(wPos)); + pixels.setPixelColor(i, rgb[0]/10, rgb[1]/10, rgb[2]/10); + for(int j = 1; j <= EyeSize; j++) { + pixels.setPixelColor(i+j, wheel(wPos++)); + } + pixels.setPixelColor(i+EyeSize+1, rgb[0]/10, rgb[1]/10, rgb[2]/10); + pixels.show(); + + delay(SpeedDelay); + } + lastCall = millis(); + state++; + break; + default: + state = 0; } - delay(wait); - - for(int i = pixels.numPixels()-EyeSize-2; i > 0; i--) { - pixels.clear(); - pixels.show(); - getRGBValues(rgb,wheel(wPos)); - pixels.setPixelColor(i, rgb[0]/10, rgb[1]/10, rgb[2]/10); - //pixels.setPixelColor(i, 255/10, 0, 0); - for(int j = 1; j <= EyeSize; j++) { - //pixels.setPixelColor(i+j, 255, 0, 0); - pixels.setPixelColor(i+j, wheel(wPos++)); - } - pixels.setPixelColor(i+EyeSize+1, rgb[0]/10, rgb[1]/10, rgb[2]/10); - pixels.show(); - delay(SpeedDelay); - } - delay(wait); } else if (effect == "randomfade") { if(lastCall + wait > millis()){