const int receiverPin = A0; // IR receiver or button input
const int ledPin = 12; // LED output pin
bool ledState = false; // Current state of the LED
bool lastButtonState = LOW; // Previous button state
bool currentButtonState;
void setup() {
pinMode(ledPin, OUTPUT); // Set LED pin as output
pinMode(receiverPin, INPUT); // Set receiver pin as input
}
void loop() {
currentButtonState = digitalRead(receiverPin);
// Detect rising edge: LOW -> HIGH
if (currentButtonState == HIGH && lastButtonState == LOW) {
ledState = !ledState; // Toggle LED state
digitalWrite(ledPin, ledState ? HIGH : LOW);
delay(200); // Debounce delay to prevent bouncing
}
lastButtonState = currentButtonState;
}