// const int BUTTON_PIN = 7;
// const int LED_PIN = 5;
// int ledState = LOW;
// int lastButtonState;
// int currentButtonState;
// void setup() {
// Serial.begin(9600); // initialize serial
// pinMode(BUTTON_PIN, INPUT_PULLUP); // set arduino pin to input pull-up mode
// pinMode(LED_PIN, OUTPUT); // set arduino pin to output mode
// currentButtonState = digitalRead(BUTTON_PIN);
// // put your setup code here, to run once:
// }
// void loop() {
// lastButtonState = currentButtonState; // save the last state
// currentButtonState = digitalRead(BUTTON_PIN); // read new state
// if(lastButtonState == HIGH && currentButtonState == LOW) {
// // toggle state of LED
// ledState = !ledState;
// // control LED arccoding to the toggled state
// digitalWrite(LED_PIN, ledState);
// } // put your main code here, to run repeatedly:
// }
const int ledPin =6;
const int BUTTON_PIN=4;
int ledState = LOW; // ledState used to set the LED
int lastButtonState;
int currentButtonState;
unsigned long previousMillis = 0;
const long interval = 1000;
void setup() {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
currentButtonState = digitalRead(BUTTON_PIN);
}
void loop() {
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
if (ledState == LOW) {
ledState = HIGH;
} else {
ledState = LOW;
}
digitalWrite(ledPin, ledState);
}
}