LED PUSH BUTTON

The code can be downloaded at :

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

include

define BUTTON_PIN 2 //harus di pin 2

define BUTTON_PIN1 3

byte sta;

define LED_PIN1 4

define LED_PIN2 5

define LED_PIN3 6

define LED_PIN4 7

define LED_PIN5 8

define LED_PIN6 9

define LED_PIN7 10

define LED_PIN8 11

int buttonState = 0;

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

pinMode(LED_PIN1, OUTPUT);
pinMode(LED_PIN2, OUTPUT);
pinMode(LED_PIN3, OUTPUT);
pinMode(LED_PIN4, OUTPUT);
pinMode(LED_PIN5, OUTPUT);
pinMode(LED_PIN6, OUTPUT);
pinMode(LED_PIN7, OUTPUT);
pinMode(LED_PIN8, OUTPUT);

pinMode(BUTTON_PIN, INPUT);
pinMode(BUTTON_PIN1, INPUT);
attachInterrupt(0, blinkLed, CHANGE);
}
unsigned long last = millis();
int on = 0;

void loop() {
buttonState = digitalRead(BUTTON_PIN1);
if (buttonState == HIGH) {

EEPROM.write(2, 1);   

}
else {
sta = EEPROM.read(2);
Serial.println(sta);

if(sta==0){
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);
}
if(sta==1){
digitalWrite(LED_PIN1, LOW);
digitalWrite(LED_PIN2, LOW);
digitalWrite(LED_PIN3, LOW);
digitalWrite(LED_PIN4, LOW);
digitalWrite(LED_PIN5, LOW);
digitalWrite(LED_PIN6, LOW);
digitalWrite(LED_PIN7, LOW);
digitalWrite(LED_PIN8, LOW);

delay(500);
digitalWrite(LED_PIN1, HIGH);
digitalWrite(LED_PIN8, HIGH);
delay(500);
digitalWrite(LED_PIN2, HIGH);
digitalWrite(LED_PIN7, HIGH);
delay(500);
digitalWrite(LED_PIN3, HIGH);
digitalWrite(LED_PIN6, HIGH);
delay(500);
digitalWrite(LED_PIN4, HIGH);
digitalWrite(LED_PIN5, HIGH);
delay(500);

}
}
}

void blinkLed() {
if (millis() – last > 250) {
EEPROM.write(2, 0);

}
last = millis(); 

}