diff --git a/include/leds.h b/include/leds.h index 9c15e5e..8cc92a0 100644 --- a/include/leds.h +++ b/include/leds.h @@ -46,12 +46,13 @@ class leds bool _fade_on(); uint16_t _rainbow_pixel, _rainbow_color; + uint16_t _blue_color, _blue_pixel; unsigned long _last_rainbowcycle = 0; uint32_t _wheel(byte pos); public: - enum led_update {UP_RAINBOW = 1, UP_FADE = 2}; + enum led_update {UP_RAINBOW = 1, UP_FADE = 2, UP_BLUE = 4}; leds(Adafruit_NeoPixel * stripe, uint32_t * state_flag, uint16_t state_mask, uint16_t H, uint8_t S, unsigned int pixel_first, unsigned int pixel_last ); ~leds(); @@ -69,10 +70,14 @@ class leds void rainbowCycle(); bool do_rainbowCycle(); void theaterChaseRainbow(); + void blueCycle(); + bool do_blueCycle(); }; leds::leds(Adafruit_NeoPixel * stripe, uint32_t * state_flag, uint16_t state_mask, uint16_t H, uint8_t S, unsigned int pixel_first, unsigned int pixel_last ) { + _blue_color = 0; + _blue_pixel = 0; _tcr_firstPixelHue = 0; _tcr_b = 0; _state_flag = state_flag; @@ -146,6 +151,11 @@ bool leds::update(led_update type) return(do_rainbowCycle()); } + if(type == UP_BLUE ) + { + return(do_blueCycle()); + } + if(type == UP_FADE) { return(do_fade()); @@ -169,6 +179,21 @@ bool leds::do_rainbowCycle() return(updated); } +bool leds::do_blueCycle() +{ + bool updated = false; + uint16_t curr_state = _state_mask & *_state_flag; + if(curr_state == 0) + { + clear(); + } + else + { + blueCycle(); + updated = true; + } + return(updated); +} bool leds::do_fade() { @@ -334,7 +359,31 @@ void leds::rainbowCycle() if(_rainbow_color >= 256*1) _rainbow_color = 0; for(size_t nr = 0; nr< _pixel_nr; ++nr) { - _pixels[nr].color = _wheel(((_rainbow_pixel * 256 / _pixel_nr) + _rainbow_color) & 255); + //_pixels[nr].color = _wheel(((_rainbow_pixel * 256 / _pixel_nr) + _rainbow_color) & 255); + _pixels[nr].color = _wheel(((nr * 256 / _pixel_nr) + _rainbow_color) & 255); + } + _setLeds(); + + + } +} + +void leds::blueCycle() +{ + if((millis() - _last_rainbowcycle) > 2*WAIT_RAINBOWCYCLE_MS) + { + //Serial.printf("Rainbow! Next color\n"); + _last_rainbowcycle = millis(); + _blue_color++; + if(_blue_color >= 3) + _blue_color = 0; + for(size_t nr = _blue_color; nr< _pixel_nr; nr = nr+3) { + if(_blue_pixel >= 3) + _blue_pixel = 0; + uint32_t color = _stripe->ColorHSV(38000,255, 2 + _blue_pixel*5); + //Serial.printf(" blue_color is %d, cnt is %d , color is %d, pixel is %d\n", _blue_color, _blue_pixel, color, nr); + _pixels[nr].color = color; + _blue_pixel++; } _setLeds(); } diff --git a/include/main.h b/include/main.h index 27b6536..6b32fcb 100644 --- a/include/main.h +++ b/include/main.h @@ -10,6 +10,7 @@ //eeprom flash; const unsigned long SZENE_TIMEOUT_TO_SET_TO_DEFAULT_MS = 600000; +const unsigned long MAX_DISCO_TIME = 120000; ///---- OLED ---- @@ -78,6 +79,7 @@ const size_t PIN_RGBLEDS = 19; Adafruit_NeoPixel rgb_leds(NUMRGBLEDS, PIN_RGBLEDS, NEO_GRB + NEO_KHZ800); enum led_t {LTANNE=1, LBACK=2, LBAUHOF=4, LTEICH=8, LBURG=16, LSTERNE1=32, LSTERNE2=64, LSTERNBILD1 = 128, LSTERNBILD2=256, LSTERNBILD3=512, LHAEUSER=1024, LSPIEGEL=2048}; +/* leds led_back(&rgb_leds, &licht_state_flag, LBACK, 5000,220, 0, 6 ); leds led_burg(&rgb_leds, &licht_state_flag, LBURG, 5000,220, 7, 9); leds led_teich(&rgb_leds, &licht_state_flag, LTEICH, 5000,220, 10, 16 ); @@ -88,8 +90,8 @@ leds led_sterne2(&rgb_leds, &licht_state_flag, LSTERNE2, 5000,220, 20, 20 ); leds led_sternbilder3(&rgb_leds, &licht_state_flag, LSTERNBILD3, 5000,220, 21, 21 ); leds led_bauhof(&rgb_leds, &licht_state_flag, LBAUHOF, 5000,220, 22, 24); leds led_tanne(&rgb_leds, &licht_state_flag, LTANNE, 5000,220, 25, 25 ); +*/ -/* leds led_back(&rgb_leds, &licht_state_flag, LBACK, 5000,220, 0, 69 ); leds led_burg(&rgb_leds, &licht_state_flag, LBURG, 5000,220, 70, 76); leds led_teich(&rgb_leds, &licht_state_flag, LTEICH, 5000,220, 77, 88 ); @@ -100,4 +102,4 @@ leds led_sterne2(&rgb_leds, &licht_state_flag, LSTERNE2, 5000,220, 95, 96 ); leds led_sternbilder3(&rgb_leds, &licht_state_flag, LSTERNBILD3, 5000,220, 97, 98 ); leds led_bauhof(&rgb_leds, &licht_state_flag, LBAUHOF, 5000,220, 99, 106); leds led_tanne(&rgb_leds, &licht_state_flag, LTANNE, 5000,220, 107, 108 ); -*/ + diff --git a/src/main.cpp b/src/main.cpp index 17f0da1..ed9b8f5 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -14,6 +14,8 @@ void move_zugunten(); void move_schiene_oben(); void show_counters(); void updateNVS(); +void disco(); +void disco_licht(); unsigned int licht_all_count = 0; @@ -65,7 +67,6 @@ void setup() { //blau led_back.setHS(32000,200); led_back.setHS(9000,180); led_teich.setHS(40000,255); - } void loop() { @@ -147,7 +148,7 @@ void set_moveszene() const byte TANNENBAUM_VOL = 20; const unsigned long TANNENBAUM_PLAY_MUSIC_MS = 135000; -typedef enum {TA_INIT = 0, TA_LIGHT_READY, TA_START_PLAYING ,TA_MIN_PLAYING,TA_PLAYING, TA_STOP_PLAYING, TA_FINSIHED} szene_tanne_t; +typedef enum {TA_INIT = 0, TA_LIGHT_READY, TA_MIN_PLAYING,TA_PLAYING, TA_STOP_PLAYING, TA_FINSIHED} szene_tanne_t; szene_tanne_t tanne_state = TA_INIT; void szene_oh_tannebaum() { @@ -166,12 +167,14 @@ void szene_oh_tannebaum() tanne_state = TA_FINSIHED; else{ mp3_isused = true; - tanne_state = TA_START_PLAYING; + tanne_state = TA_MIN_PLAYING; Serial.printf("All lights are ready for Oh Tannebaum\n"); mp3ply.play_vol(SONG_OH_TANNEBAUM, TANNENBAUM_VOL); + szene_time_ms = msecs; } } break; + /* case TA_START_PLAYING: szene_time_ms = msecs; if(mp3ply.is_playing() > 0) @@ -180,6 +183,7 @@ void szene_oh_tannebaum() Serial.printf("Oh Tannebaum is playing\n"); } break; + */ case TA_MIN_PLAYING: taster_aussen_licht.reset(); if(msecs - szene_time_ms > 1000) @@ -397,7 +401,7 @@ void move_zugunten() case ZU_STOPPED_PLAYING: if(mp3_zugunten == true) { - if(mp3ply.fade_out() == false && mp3ply.is_playing() == 0) + if(mp3ply.fade_out() == false ) //&& mp3ply.is_playing() == 0) { zugunten_state = ZU_DONE; mp3_isused = false; @@ -493,7 +497,7 @@ void move_zugoben() case ZO_STOPPED_PLAYING: if(mp3_zugoben == true) { - if(mp3ply.fade_out() == false && mp3ply.is_playing() == 0) + if(mp3ply.fade_out() == false ) // && mp3ply.is_playing() == 0) { zugoben_state = ZO_DONE; mp3_isused = false; @@ -569,7 +573,7 @@ void move_schiene_oben() case SO_STOPPED_PLAYING: if(mp3_soben == true) { - if(mp3ply.fade_out() == false && mp3ply.is_playing() == 0) + if(mp3ply.fade_out() == false ) //&& mp3ply.is_playing() == 0) { soben_state = SO_DONE; mp3_isused = false; @@ -587,6 +591,57 @@ void move_schiene_oben() } } +void disco() +{ + unsigned long disco_time = millis(); + disco_all_count++; + uint32_t stored_licht_state_flag = licht_state_flag; + + uint8_t randSongNumber = random(0, 3); + Serial.printf("Disco! Playing Song %d\n", randSongNumber); + switch(randSongNumber) + { + case 0: + mp3ply.play_vol(SONG_DISCO_LASTCHRISTMAS,20); + break; + case 1: + mp3ply.play_vol(SONG_DISCO_DOTHEYKNOWITSCHRISTMAS,20); + break; + case 2: + mp3ply.play_vol(SONG_DISCO_MARYSBOYCHILD,20); + break; + default: + mp3ply.play_vol(SONG_DISCO_LASTCHRISTMAS,20); + break; + } + + /* + while(mp3ply.is_playing() == 0) + { + disco_licht(); + Serial.printf("Waiting until MP3 player starts\n"); + delay(100); + } + */ + while(millis() - disco_time < MAX_DISCO_TIME) + { + disco_licht(); + Serial.printf("Playing Disco!!!\n"); + } + while(mp3ply.fade_out()==true) + {delay(100);} + Serial.printf("Disco done.\n"); + rgb_leds.clear(); + rgb_leds.show(); + licht_state_flag = 0; + licht_update(); + licht_state_flag = stored_licht_state_flag; + while( true == licht_update()) + {delay(1);} + taster_aussen_licht.reset(); + taster_aussen_move.reset(); +} + bool licht_update() { bool fade_updated = false; @@ -599,7 +654,7 @@ bool licht_update() rainbow_updated = led_tanne.update(leds::UP_RAINBOW) || rainbow_updated; fade_updated = led_bauhof.update() || fade_updated; fade_updated = led_burg.update() || fade_updated; - fade_updated = led_teich.update() || fade_updated; + rainbow_updated = led_teich.update(leds::UP_BLUE) || rainbow_updated; fade_updated = led_back.update() || fade_updated; if((licht_state_flag & LHAEUSER) == 0) @@ -644,56 +699,12 @@ void disco_licht() rgb_leds.show(); } -const unsigned long MAX_DISCO_TIME = 120000; + void taster_abfrage() { if(next_licht_szene_possible == true && next_move_szene_possible == true && digitalRead(PIN_TASTER_AUSSEN_LICHT) == LOW && digitalRead(PIN_TASTER_AUSSEN_MOVE) == LOW) { - unsigned long disco_time = millis(); - disco_all_count++; - uint32_t stored_licht_state_flag = licht_state_flag; - - uint8_t randSongNumber = random(0, 3); - Serial.printf("Disco! Playing Song %d\n", randSongNumber); - switch(randSongNumber) - { - case 0: - mp3ply.play_vol(SONG_DISCO_LASTCHRISTMAS,20); - break; - case 1: - mp3ply.play_vol(SONG_DISCO_DOTHEYKNOWITSCHRISTMAS,20); - break; - case 2: - mp3ply.play_vol(SONG_DISCO_MARYSBOYCHILD,20); - break; - default: - mp3ply.play_vol(SONG_DISCO_LASTCHRISTMAS,20); - break; - } - - while(mp3ply.is_playing() == 0) - { - disco_licht(); - Serial.printf("Waiting until MP3 player starts\n"); - delay(100); - } - while(millis() - disco_time < MAX_DISCO_TIME) - { - disco_licht(); - Serial.printf("Playing Disco!!!\n"); - } - while(mp3ply.fade_out()==true) - {delay(100);} - Serial.printf("Disco done.\n"); - rgb_leds.clear(); - rgb_leds.show(); - licht_state_flag = 0; - licht_update(); - licht_state_flag = stored_licht_state_flag; - while( true == licht_update()) - {delay(1);} - taster_aussen_licht.reset(); - taster_aussen_move.reset(); + disco(); } else {