// Pin setup
int ledRed = 12;
int Button = 7;
int ledOn = 10;
int ledBlue = 8;
// Delay setup
const long interval1 = 1000; // time of delay in MS
const long interval2 = 500; // time of delay in MS
int Clock1 = LOW; //
int Clock2 = LOW; //
int Clock3 = LOW; // Off 1500ms On 500ms
unsigned long previousMillis1 = 0; //
unsigned long previousMillis2 = 0; //
unsigned long previousMillis3 = 0;
// button setup
bool MB = true;
void setup() {
Serial.begin(9600); // open the serial port at 9600 bps:
pinMode(ledRed, OUTPUT);
pinMode(ledOn, OUTPUT);
pinMode(ledBlue, OUTPUT);
pinMode(Button, INPUT);
}
void loop() {
// Setup for the Clock / delay
unsigned long currentMillis = millis();
if (currentMillis - previousMillis1 >= interval1) {
previousMillis1 = currentMillis;
if (Clock1 == LOW) {
Clock1 = HIGH;
} else {
Clock1 = LOW;
}
}
if (currentMillis - previousMillis2 >= interval2) {
previousMillis2 = currentMillis;
if (Clock2 == LOW) {
Clock2 = HIGH;
} else {
Clock2 = LOW;
}
}
// Clock 3
if (Clock1 == HIGH && Clock2 == HIGH) {
Clock3 = HIGH;
} else {
Clock3 = LOW;
}
currentMillis = millis();
// Button Merker
if (currentMillis >= previousMillis3 + 1000 && digitalRead(Button) == HIGH) {
previousMillis3 = currentMillis;
if (MB == true) {
MB = false;
} else {
MB = true;
}
}
// LED code
if (MB == true) {
digitalWrite(ledRed, Clock1);
digitalWrite(ledBlue, Clock2);
digitalWrite(ledOn, LOW);
}
else {
digitalWrite(ledRed, LOW);
digitalWrite(ledBlue, LOW);
digitalWrite(ledOn, !Clock3);
}
}