Hallo,
das ihr da nicht selbst nach suchen könnt...
// each "event" (LED) gets their own tracking variable
unsigned long previousMillisTonLED=0;
unsigned long previousMillisPauseLED=0;
// different intervals for each LED
int intervalTonLED = 500;
int intervalPauseLED = 1000;
// each LED gets a state varaible
boolean PauseLEDstate = false; // the LED will turn ON in the first iteration of loop()
boolean TonLEDstate = false; // need to seed the light to be OFF
void setup() {
pinMode(13, OUTPUT);
pinMode(12, OUTPUT);
}
void loop() {
// get current time stamp
// only need one for both if-statements
unsigned long currentMillis = millis();
// time to toggle LED on Pin 12?
if ((unsigned long)(currentMillis - previousMillisTonLED) >= intervalTonLED) {
TonLEDstate = !TonLEDstate;
digitalWrite(12, TonLEDstate);
// save current time to pin 12's previousMillis
previousMillisTonLED = currentMillis;
}
// time to toggle LED on Pin 13?
if ((unsigned long)(currentMillis - previousMillisPauseLED) >= intervalPauseLED) {
PauseLEDstate = !PauseLEDstate;
digitalWrite(13, PauseLEDstate);
// save current time to pin 12's previousMillis
previousMillisPauseLED = currentMillis;
}
}
Gruß und Spaß
Andreas