#define redled 0
#define blueled 1
#define greenled 2
int redledstate = LOW;
int blueledstate = LOW;
int greenledstate = LOW;
unsigned long currenttime = 0;
unsigned long prevredledtime = 0;
unsigned long prevblueledtime = 0;
unsigned long prevgreenledtime = 0;
const unsigned long delayredled = 1000;
const unsigned long delayblueled = 500;
const unsigned long delaygreenled = 250;
void blinkredled() {
if (currenttime - prevredledtime >= delayredled) {
prevredledtime = currenttime;
if (redledstate == LOW) {
redledstate = HIGH;
}
else {
redledstate = LOW;
}
digitalWrite (redled, redledstate);
}
}
void blinkblueled() {
if (currenttime - prevblueledtime >= delayblueled) {
prevblueledtime = currenttime;
if (blueledstate == LOW) {
blueledstate = HIGH;
}
else {
blueledstate = LOW;
}
digitalWrite (blueled, blueledstate);
}
}
void blinkgreenled() {
if (currenttime - prevgreenledtime >= delaygreenled) {
prevgreenledtime = currenttime;
if (greenledstate == LOW) {
greenledstate = HIGH;
}
else {
greenledstate = LOW;
}
digitalWrite (greenled, greenledstate);
}
}
void setup() {
pinMode (redled, OUTPUT);
}
void loop() {
currenttime = millis();
blinkredled();
blinkblueled();
blinkgreenled();
}