TWO PUSH BUTTON LED

The code can be downloaded at :

https://github.com/triantara/ARDUINO-TRIANTARA/blob/main/TWO%20BUTTON%20LED%20SWICH.zip

include

define BUTTON_PIN 2 //must be on pin 2

volatile byte ledState = LOW;
byte sta;
int buttonPushCounter;
const int buttonPin = 7;
int buttonState = 0;

define LED_PIN1 3

define LED_PIN2 4

define LED_PIN3 5

define LED_PIN4 6

void setup() {
Serial.begin(9600);

pinMode(LED_PIN1, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
pinMode(LED_PIN3, OUTPUT);
pinMode(LED_PIN4, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
pinMode(buttonPin, INPUT);
attachInterrupt(0, blinkLed, CHANGE);

}
unsigned long last = millis();
int on = 0;
void(* resetFunc) (void) = 0;

void loop() {
buttonState = digitalRead(buttonPin);
sta = EEPROM.read(2);
Serial.print(sta);
Serial.print(” “);
Serial.println(buttonPushCounter);
if(sta==0){
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
}
if(sta==1){
digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
}

if(sta==2){
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
}
if(sta==3){
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, HIGH);
digitalWrite(LED_PIN4, LOW);
}
if(sta==4){
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, HIGH);
}

if (buttonState == HIGH) {

EEPROM.write(2, 0); 
resetFunc(); 

}

}

void blinkLed() {
if (millis() – last > 250) {
buttonPushCounter++;

if (buttonPushCounter % 5 == 0) {
EEPROM.write(2, 0);
}
if (buttonPushCounter % 5 == 1) {
EEPROM.write(2, 1);
}
if (buttonPushCounter % 5 == 2){
EEPROM.write(2, 2);
}
if (buttonPushCounter % 5 == 3) {
EEPROM.write(2, 3);
}
if (buttonPushCounter % 5 == 4) {
EEPROM.write(2, 4);
}

}
last = millis(); 

}