new songs added

This commit is contained in:
Jens Noack 2021-12-21 14:26:51 +01:00
parent b4a5f759e0
commit a3aa425379

View file

@ -32,20 +32,23 @@ void setup() {
taster_aussen_licht.begin(); taster_aussen_licht.begin();
taster_aussen_move.begin(); taster_aussen_move.begin();
taster_train_unten.begin(); //taster_train_unten.begin();
taster_train_oben.begin(); //taster_train_oben.begin();
taster_schiene.begin(); //taster_schiene.begin();
relais_wolke_schiene.begin(); relais_wolke_schiene.begin();
relais_spiegel.begin(); relais_spiegel.begin();
//relais_wolke.begin();
zugoben.begin(); zugoben.begin();
zugunten.begin(); zugunten.begin();
licht.begin(); licht.begin();
NVS.begin(); NVS.begin();
licht_all_count = NVS.getInt("licht"); licht_all_count = NVS.getInt("licht_cnt"); //1985
move_all_count = NVS.getInt("move"); delay(500);
disco_all_count = NVS.getInt("disco"); move_all_count = NVS.getInt("move_cnt"); //978
delay(500);
disco_all_count = NVS.getInt("disco_cnt"); //100
moni.init(); moni.init();
moni.setBrigthness(100); moni.setBrigthness(100);
@ -67,6 +70,7 @@ void setup() {
//blau led_back.setHS(32000,200); //blau led_back.setHS(32000,200);
led_back.setHS(9000,180); led_back.setHS(9000,180);
led_teich.setHS(40000,255); led_teich.setHS(40000,255);
} }
void loop() { void loop() {
@ -169,21 +173,12 @@ void szene_oh_tannebaum()
mp3_isused = true; mp3_isused = true;
tanne_state = TA_MIN_PLAYING; tanne_state = TA_MIN_PLAYING;
Serial.printf("All lights are ready for Oh Tannebaum\n"); Serial.printf("All lights are ready for Oh Tannebaum\n");
mp3ply.play_vol(SONG_OH_TANNEBAUM, TANNENBAUM_VOL); //mp3ply.play_vol(SONG_OH_TANNEBAUM, TANNENBAUM_VOL);
mp3ply.play_vol(SONG_WINTER, TANNENBAUM_VOL);
szene_time_ms = msecs; szene_time_ms = msecs;
} }
} }
break; break;
/*
case TA_START_PLAYING:
szene_time_ms = msecs;
if(mp3ply.is_playing() > 0)
{
tanne_state = TA_MIN_PLAYING;
Serial.printf("Oh Tannebaum is playing\n");
}
break;
*/
case TA_MIN_PLAYING: case TA_MIN_PLAYING:
taster_aussen_licht.reset(); taster_aussen_licht.reset();
if(msecs - szene_time_ms > 1000) if(msecs - szene_time_ms > 1000)
@ -320,9 +315,9 @@ void szene_tag_dorf()
unsigned int zugunten_error = 0; unsigned int zugunten_error = 0;
const unsigned int ZUGUNTEN_MAX_ERROR_COUNT = 5; const unsigned int ZUGUNTEN_MAX_ERROR_COUNT = 5;
const unsigned long ZUGUNTEN_DRIVES_TO_STATION_MS = 5000; const unsigned long ZUGUNTEN_DRIVES_TO_STATION_MS = 4300;
const unsigned long ZUGUNTEN_STOPPED_AT_STATION_MS = 5000; const unsigned long ZUGUNTEN_STOPPED_AT_STATION_MS = 5000;
const unsigned long ZUGUNTEN_MAX_TIME_TO_HOME_MS = 15000; ///timeout time const unsigned long ZUGUNTEN_MAX_TIME_TO_HOME_MS = 35000;///21000; ///timeout time
typedef enum {ZU_INIT = 0, ZU_AT_HOME , ZU_DRIVES_TO_STATION, ZU_STOPPES_AT_STATION, ZU_STOPPED_AT_STATION, ZU_DRIVES_HOME, ZU_STOPPES_AT_HOME, ZU_STOPPED_PLAYING, ZU_DONE} szene_zugunten_t; typedef enum {ZU_INIT = 0, ZU_AT_HOME , ZU_DRIVES_TO_STATION, ZU_STOPPES_AT_STATION, ZU_STOPPED_AT_STATION, ZU_DRIVES_HOME, ZU_STOPPES_AT_HOME, ZU_STOPPED_PLAYING, ZU_DONE} szene_zugunten_t;
szene_zugunten_t zugunten_state = ZU_INIT; szene_zugunten_t zugunten_state = ZU_INIT;
bool mp3_zugunten = false; bool mp3_zugunten = false;
@ -333,7 +328,7 @@ void move_zugunten()
{ {
case ZU_INIT: case ZU_INIT:
Serial.printf("Zugunten fährt\n"); Serial.printf("Zugunten fährt\n");
taster_train_unten.reset(); //taster_train_unten.reset();
if (zugunten_error > ZUGUNTEN_MAX_ERROR_COUNT) if (zugunten_error > ZUGUNTEN_MAX_ERROR_COUNT)
{ {
zugunten_state = ZU_DONE; zugunten_state = ZU_DONE;
@ -345,7 +340,8 @@ void move_zugunten()
if(mp3_isused == false) if(mp3_isused == false)
{ {
Serial.printf("Playing Eine Insel\n"); Serial.printf("Playing Eine Insel\n");
mp3ply.play_vol(SONG_EINE_INSEL, 20); //mp3ply.play_vol(SONG_EINE_INSEL, 20);
mp3ply.play_vol(SONG_WEIHNACHTSZEIT, 20);
mp3_zugunten = true; mp3_zugunten = true;
mp3_isused = true; mp3_isused = true;
} }
@ -356,7 +352,8 @@ void move_zugunten()
case ZU_AT_HOME: case ZU_AT_HOME:
szene_time_ms = msecs; szene_time_ms = msecs;
if(zugunten.fade_on() == false) if(zugunten.fade_on() == false)
zugunten_state = ZU_DRIVES_TO_STATION; //zugunten_state = ZU_DRIVES_TO_STATION;
zugunten_state = ZU_DRIVES_HOME;
break; break;
case ZU_DRIVES_TO_STATION: case ZU_DRIVES_TO_STATION:
if(msecs - szene_time_ms > ZUGUNTEN_DRIVES_TO_STATION_MS) if(msecs - szene_time_ms > ZUGUNTEN_DRIVES_TO_STATION_MS)
@ -378,13 +375,13 @@ void move_zugunten()
} }
break; break;
case ZU_DRIVES_HOME: case ZU_DRIVES_HOME:
if(zugunten.fade_on() == false) //if(zugunten.fade_on() == false)
if(taster_train_unten.pressed() == true || (msecs-szene_time_ms) > ZUGUNTEN_MAX_TIME_TO_HOME_MS) if( (msecs-szene_time_ms) > ZUGUNTEN_MAX_TIME_TO_HOME_MS ) //taster_train_unten.pressed() == true ||)
{ {
if( (msecs-szene_time_ms) > ZUGUNTEN_MAX_TIME_TO_HOME_MS) if( (msecs-szene_time_ms) > ZUGUNTEN_MAX_TIME_TO_HOME_MS)
{ {
Serial.printf("Train unten runs ins timeout while driving back at Home\n"); Serial.printf("Train unten runs ins timeout while driving back at Home\n");
zugunten_error++; // zugunten_error++;
} }
else{ else{
Serial.printf("Train unten back at Home pressed\n"); Serial.printf("Train unten back at Home pressed\n");
@ -422,11 +419,11 @@ void move_zugunten()
bool mp3_zugoben = false; bool mp3_zugoben = false;
unsigned int zugoben_error = 0; unsigned int zugoben_error = 0;
const unsigned int ZUGOBEN_MAX_ERROR_COUNT = 5; const unsigned int ZUGOBEN_MAX_ERROR_COUNT = 5;
const unsigned long ZUGOBEN_DRIVES_TO_BRIDGE_MS = 2000; const unsigned long ZUGOBEN_DRIVES_TO_BRIDGE_MS = 1000;
const unsigned long ZUGOBEN_DRIVES_ON_BRIDGE_MS = 2000; const unsigned long ZUGOBEN_DRIVES_ON_BRIDGE_MS = 5500;
const unsigned long ZUGOBEN_MAX_TIME_TO_HOME_MS = 10000; ///timeout time const unsigned long ZUGOBEN_MAX_TIME_TO_HOME_MS = 3*11550; ///timeout time
const uint8_t ZUGOBEN_SPEED_ON_BRIDGE = 80; const uint8_t ZUGOBEN_SPEED_ON_BRIDGE = 80;
typedef enum {ZO_INIT = 0, ZO_AT_HOME, ZO_DRIVES_TO_BRIDGE, ZO_DRIVES_SLOWDOWN_ON_BRIDGE, ZO_DRIVES_ON_BRIDGE, ZO_DRIVES_HOME, ZO_STOPPES_AT_HOME,ZO_STOPPED_PLAYING,ZO_DONE} szene_zugoben_t; typedef enum {ZO_INIT = 0, ZO_AT_HOME, ZO_DRIVES_HOME, ZO_STOPPES_AT_HOME,ZO_STOPPED_PLAYING,ZO_DONE} szene_zugoben_t;
szene_zugoben_t zugoben_state = ZO_INIT; szene_zugoben_t zugoben_state = ZO_INIT;
void move_zugoben() void move_zugoben()
{ {
@ -435,7 +432,7 @@ void move_zugoben()
{ {
case ZO_INIT: case ZO_INIT:
Serial.printf("Zugoben fährt\n"); Serial.printf("Zugoben fährt\n");
taster_train_oben.reset(); //taster_train_oben.reset();
if (zugoben_error > ZUGOBEN_MAX_ERROR_COUNT) if (zugoben_error > ZUGOBEN_MAX_ERROR_COUNT)
zugoben_state = ZO_STOPPES_AT_HOME; zugoben_state = ZO_STOPPES_AT_HOME;
else else
@ -443,7 +440,8 @@ void move_zugoben()
if(mp3_isused == false) if(mp3_isused == false)
{ {
Serial.printf("Playing Weihnachtsbahn\n"); Serial.printf("Playing Weihnachtsbahn\n");
mp3ply.play_vol(SONG_WEIHNACHTSBAHN, 20); //mp3ply.play_vol(SONG_WEIHNACHTSBAHN, 20);
mp3ply.play_vol(SONG_ZEIT_ANGEKOMMEN, 20);
mp3_zugoben = true; mp3_zugoben = true;
mp3_isused = true; mp3_isused = true;
} }
@ -455,32 +453,16 @@ void move_zugoben()
case ZO_AT_HOME: case ZO_AT_HOME:
szene_time_ms = msecs; szene_time_ms = msecs;
if(zugoben.fade_on() == false) if(zugoben.fade_on() == false)
zugoben_state = ZO_DRIVES_TO_BRIDGE;
break;
case ZO_DRIVES_TO_BRIDGE:
if(msecs - szene_time_ms > ZUGOBEN_DRIVES_TO_BRIDGE_MS)
zugoben_state = ZO_DRIVES_SLOWDOWN_ON_BRIDGE;
break;
case ZO_DRIVES_SLOWDOWN_ON_BRIDGE:
szene_time_ms = msecs;
if(zugoben.fade_down_to(ZUGOBEN_SPEED_ON_BRIDGE) == false)
zugoben_state = ZO_DRIVES_ON_BRIDGE;
break;
case ZO_DRIVES_ON_BRIDGE:
if(msecs - szene_time_ms > ZUGOBEN_DRIVES_ON_BRIDGE_MS)
{
zugoben_state = ZO_DRIVES_HOME; zugoben_state = ZO_DRIVES_HOME;
szene_time_ms = msecs;
}
break; break;
case ZO_DRIVES_HOME: case ZO_DRIVES_HOME:
if(zugoben.fade_on() == false) if(zugoben.fade_on() == false)
if(taster_train_oben.pressed() == true || (msecs-szene_time_ms) > ZUGOBEN_MAX_TIME_TO_HOME_MS) if( (msecs-szene_time_ms) > ZUGOBEN_MAX_TIME_TO_HOME_MS ) //||taster_train_oben.pressed() == true )
{ {
if((msecs-szene_time_ms) > ZUGOBEN_MAX_TIME_TO_HOME_MS) if((msecs-szene_time_ms) > ZUGOBEN_MAX_TIME_TO_HOME_MS)
{ {
Serial.printf("Train oben runs in time out while driving back at home\n"); Serial.printf("Train oben runs in time out while driving back at home\n");
zugoben_error++; // zugoben_error++;
} }
else else
{ {
@ -497,7 +479,7 @@ void move_zugoben()
case ZO_STOPPED_PLAYING: case ZO_STOPPED_PLAYING:
if(mp3_zugoben == true) if(mp3_zugoben == true)
{ {
if(mp3ply.fade_out() == false ) // && mp3ply.is_playing() == 0) if(mp3ply.fade_out() == false )
{ {
zugoben_state = ZO_DONE; zugoben_state = ZO_DONE;
mp3_isused = false; mp3_isused = false;
@ -518,7 +500,7 @@ void move_zugoben()
bool mp3_soben = false; bool mp3_soben = false;
unsigned int soben_error = 0; unsigned int soben_error = 0;
const unsigned int SOBEN_MAX_ERROR_COUNT = 5; const unsigned int SOBEN_MAX_ERROR_COUNT = 5;
const unsigned long SOBEN_MAX_DRIVES_TIME_MS = 30000; ///timeout time const unsigned long SOBEN_MAX_DRIVES_TIME_MS = 30400; ///timeout time
typedef enum {SO_INIT = 0, SO_AT_HOME, SO_DRIVES_HOME, SO_STOPPES_AT_HOME,SO_STOPPED_PLAYING, SO_DONE} szene_soben_t; typedef enum {SO_INIT = 0, SO_AT_HOME, SO_DRIVES_HOME, SO_STOPPES_AT_HOME,SO_STOPPED_PLAYING, SO_DONE} szene_soben_t;
szene_soben_t soben_state = SO_INIT; szene_soben_t soben_state = SO_INIT;
void move_schiene_oben() void move_schiene_oben()
@ -528,7 +510,7 @@ void move_schiene_oben()
{ {
case SO_INIT: case SO_INIT:
Serial.printf("Schiene oben fährt\n"); Serial.printf("Schiene oben fährt\n");
taster_schiene.reset(); //taster_schiene.reset();
if(soben_error > SOBEN_MAX_ERROR_COUNT) if(soben_error > SOBEN_MAX_ERROR_COUNT)
soben_state = SO_STOPPES_AT_HOME; soben_state = SO_STOPPES_AT_HOME;
else else
@ -536,7 +518,10 @@ void move_schiene_oben()
if(mp3_isused == false) if(mp3_isused == false)
{ {
Serial.printf("Playing Weihnachtsbäckerei\n"); Serial.printf("Playing Weihnachtsbäckerei\n");
mp3ply.play_vol(SONG_WEIHNACHTSBAECKEREI, 20); if( random(0, 2) == 0 )
mp3ply.play_vol(SONG_WEIHNACHTSBAECKEREI, 23);
else
mp3ply.play_vol(SONG_WEIHNACHTSTRAUM, 23);
mp3_soben = true; mp3_soben = true;
mp3_isused = true; mp3_isused = true;
} }
@ -548,14 +533,15 @@ void move_schiene_oben()
case SO_AT_HOME: case SO_AT_HOME:
szene_time_ms = millis(); szene_time_ms = millis();
relais_wolke_schiene.on(); relais_wolke_schiene.on();
//relais_wolke.on();
soben_state = SO_DRIVES_HOME; soben_state = SO_DRIVES_HOME;
break; break;
case SO_DRIVES_HOME: case SO_DRIVES_HOME:
if(taster_schiene.pressed() == true || (msecs-szene_time_ms) > SOBEN_MAX_DRIVES_TIME_MS) if( (msecs-szene_time_ms) > SOBEN_MAX_DRIVES_TIME_MS) //||taster_schiene.pressed() == true )
{ {
if((msecs-szene_time_ms) > SOBEN_MAX_DRIVES_TIME_MS) if((msecs-szene_time_ms) > SOBEN_MAX_DRIVES_TIME_MS)
{ {
soben_error++; // soben_error++;
Serial.printf("Schiene oben timeout while driving home.\n"); Serial.printf("Schiene oben timeout while driving home.\n");
} }
else else
@ -568,6 +554,7 @@ void move_schiene_oben()
break; break;
case SO_STOPPES_AT_HOME: case SO_STOPPES_AT_HOME:
relais_wolke_schiene.off(); relais_wolke_schiene.off();
//relais_wolke.off();
soben_state = SO_STOPPED_PLAYING; soben_state = SO_STOPPED_PLAYING;
break; break;
case SO_STOPPED_PLAYING: case SO_STOPPED_PLAYING:
@ -597,21 +584,24 @@ void disco()
disco_all_count++; disco_all_count++;
uint32_t stored_licht_state_flag = licht_state_flag; uint32_t stored_licht_state_flag = licht_state_flag;
uint8_t randSongNumber = random(0, 3); uint8_t randSongNumber = random(0, 4);
Serial.printf("Disco! Playing Song %d\n", randSongNumber); Serial.printf("Disco! Playing Song %d\n", randSongNumber);
switch(randSongNumber) switch(randSongNumber)
{ {
case 0: case 0:
mp3ply.play_vol(SONG_DISCO_LASTCHRISTMAS,20); mp3ply.play_vol(SONG_DISCO_LASTCHRISTMAS,25);
break; break;
case 1: case 1:
mp3ply.play_vol(SONG_DISCO_DOTHEYKNOWITSCHRISTMAS,20); mp3ply.play_vol(SONG_DISCO_DOTHEYKNOWITSCHRISTMAS,25);
break; break;
case 2: case 2:
mp3ply.play_vol(SONG_DISCO_MARYSBOYCHILD,20); mp3ply.play_vol(SONG_DISCO_MARYSBOYCHILD,25);
break; break;
case 3:
mp3ply.play_vol(SONG_DISCO_MERRY_CHRISTMAS,25);
break;
default: default:
mp3ply.play_vol(SONG_DISCO_LASTCHRISTMAS,20); mp3ply.play_vol(SONG_DISCO_LASTCHRISTMAS,25);
break; break;
} }
@ -695,7 +685,7 @@ void disco_licht()
led_back.theaterChaseRainbow(); led_back.theaterChaseRainbow();
licht.fade_off(); licht.fade_off();
relais_spiegel.off(); relais_spiegel.on();
rgb_leds.show(); rgb_leds.show();
} }
@ -732,27 +722,29 @@ void taster_abfrage()
} }
} }
uint8_t nvs_value = 0;
void updateNVS() void updateNVS()
{ {
static uint8_t value = 0; if(millis() - last_updated_NVS > 1000)
if(millis() - last_updated_NVS > 1000)
{ {
last_updated_NVS = millis(); last_updated_NVS = millis();
switch(value) switch(nvs_value)
{ {
case 0:
NVS.setInt("licht_cnt", licht_all_count);
break;
case 1: case 1:
NVS.setInt("licht", licht_all_count); NVS.setInt("move_cnt", move_all_count);
break; break;
case 2: case 2:
NVS.setInt("move", move_all_count); NVS.setInt("disco_cnt", disco_all_count);
break; break;
case 3:
NVS.setInt("disco",disco_all_count);
break;
default:
value = 0;
} }
value++; if(nvs_value == 2)
nvs_value = 0;
else
nvs_value++;
} }
} }