so in dieser Art:
Code:uint32_t starttime; void setup() { // put your setup code here, to run once: Serial.begin(115200); delay(3000); Serial.println("Serial started"); starttime=millis(); // start countdown } void setBGColor(uint32_t myColor){ } // eigene Funktion verwenden! void setcolor(uint32_t timesec) { uint32_t myColor2, myColor1, myColor0; // Color-Werte definieren! if(timesec>20) { setBGColor(myColor2); Serial.println("myColor2"); } else if(timesec<=5 && timesec>=0 ) { setBGColor(myColor0); Serial.println("myColor0"); } else if(timesec<=20 && timesec>0) { setBGColor(myColor0); Serial.println("myColor1"); } } uint32_t countdowntime=20; // sec countdown; void loop() { static int32_t passedsec, oldpassedsec=0, dtimesec=-1; passedsec= (millis()-starttime)/1000; if(oldpassedsec!=passedsec && passedsec<=countdowntime) { dtimesec=countdowntime-passedsec; Serial.println(dtimesec); setcolor(dtimesec); oldpassedsec=passedsec; if(dtimesec==0 && countdowntime==20) { countdowntime=120; starttime=millis(); } } // *SNIP* // do anything important // *SNIP* delay(1); // yield }







Zitieren

Lesezeichen