#define LED_PIN 13
#define BUTTON_PIN 8
#define LED1_PIN 3
#define BUTTON1_PIN 2
byte lastButtonState = LOW;
byte ledState = LOW;
byte lastButton1State = LOW;
byte led1State = LOW;
unsigned long debounceDuration = 100; // millis
unsigned long lastTimeButtonStateChanged = 0;
unsigned long debounce1Duration = 100; // millis
unsigned long lastTimeButton1StateChanged = 0;
void setup() {
pinMode(LED_PIN, OUTPUT);
pinMode(BUTTON_PIN, INPUT);
pinMode(LED1_PIN, OUTPUT);
pinMode(BUTTON1_PIN, INPUT);
}
void loop() {
if (millis() - lastTimeButtonStateChanged > debounceDuration) {
byte buttonState = digitalRead(BUTTON_PIN);
if (buttonState != lastButtonState) {
lastTimeButtonStateChanged = millis();
lastButtonState = buttonState;
if (buttonState == LOW) {
ledState = (ledState == HIGH) ? LOW: HIGH;
digitalWrite(LED_PIN, ledState);
}
}
}
if (millis() - lastTimeButton1StateChanged > debounce1Duration) {
byte button1State = digitalRead(BUTTON1_PIN);
if (button1State != lastButton1State) {
lastTimeButton1StateChanged = millis();
lastButton1State = button1State;
if (button1State == LOW) {
led1State = (led1State == HIGH) ? LOW: HIGH;
digitalWrite(LED1_PIN, led1State);
}
}
}
}