New Larson Scanner

This commit is contained in:
Juergen Jung 2017-02-14 20:39:52 +01:00
parent 6bb63c68bd
commit 3bf250e14a
1 changed files with 47 additions and 31 deletions

View File

@ -10,6 +10,7 @@
uint16_t effectI=0,effectJ=0,wait = 50; uint16_t effectI=0,effectJ=0,wait = 50;
unsigned long lastCall = 0; unsigned long lastCall = 0;
byte wPos = 0; byte wPos = 0;
uint8_t state = 0;
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800); Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
@ -98,42 +99,57 @@ void loopHandler() {
} }
else if (effect == "larson") { else if (effect == "larson") {
int SpeedDelay = 20; int SpeedDelay = 20;
int ReturnDelay = 50;
int EyeSize = 5; int EyeSize = 5;
uint32_t rgb[3] = {0}; uint32_t rgb[3] = {0};
switch(state){
case 0:
if(lastCall + wait < millis()){
state++;
}
break;
case 1:
for(int i = 0; i < pixels.numPixels()-EyeSize-2; i++) { for(int i = 0; i < pixels.numPixels()-EyeSize-2; i++) {
pixels.clear(); pixels.clear();
pixels.show();
getRGBValues(rgb,wheel(wPos)); getRGBValues(rgb,wheel(wPos));
pixels.setPixelColor(i, rgb[0]/10, rgb[1]/10, rgb[2]/10); pixels.setPixelColor(i, rgb[0]/10, rgb[1]/10, rgb[2]/10);
for(int j = 1; j <= EyeSize; j++) { for(int j = 1; j <= EyeSize; j++) {
pixels.setPixelColor(i+j, wheel(wPos++)); pixels.setPixelColor(i+j, wheel(wPos++));
} }
uint32_t rgb[3] = {0};
getRGBValues(rgb,wheel(wPos)); getRGBValues(rgb,wheel(wPos));
pixels.setPixelColor(i+EyeSize+1, rgb[0]/10, rgb[1]/10, rgb[2]/10); pixels.setPixelColor(i+EyeSize+1, rgb[0]/10, rgb[1]/10, rgb[2]/10);
pixels.show(); pixels.show();
delay(SpeedDelay); delay(SpeedDelay);
} }
delay(wait); lastCall = millis();
state++;
break;
case 2:
if(lastCall + wait < millis()){
state++;
}
break;
case 3:
for(int i = pixels.numPixels()-EyeSize-2; i > 0; i--) { for(int i = pixels.numPixels()-EyeSize-2; i > 0; i--) {
pixels.clear(); pixels.clear();
pixels.show();
getRGBValues(rgb,wheel(wPos)); getRGBValues(rgb,wheel(wPos));
pixels.setPixelColor(i, rgb[0]/10, rgb[1]/10, rgb[2]/10); 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++) { for(int j = 1; j <= EyeSize; j++) {
//pixels.setPixelColor(i+j, 255, 0, 0);
pixels.setPixelColor(i+j, wheel(wPos++)); pixels.setPixelColor(i+j, wheel(wPos++));
} }
pixels.setPixelColor(i+EyeSize+1, rgb[0]/10, rgb[1]/10, rgb[2]/10); pixels.setPixelColor(i+EyeSize+1, rgb[0]/10, rgb[1]/10, rgb[2]/10);
pixels.show(); pixels.show();
delay(SpeedDelay); delay(SpeedDelay);
} }
delay(wait); lastCall = millis();
state++;
break;
default:
state = 0;
}
} }
else if (effect == "randomfade") { else if (effect == "randomfade") {
if(lastCall + wait > millis()){ if(lastCall + wait > millis()){