5 int switchPin = 2; // switch is connected to pin 2
6 int val; // variable for reading the pin status
7 int buttonState; // variable to hold the last button state
8 int lightMode = 0; // State of the light
12 pinMode(switchPin, INPUT_PULLUP); // Set the switch pin as input
15 buttonState = digitalRead(switchPin); // read the initial state
21 val = digitalRead(switchPin); // read input value and store it in val
22 delay(100); // Debounce
23 if ((val != buttonState) && (val == HIGH)) { // check if the button is pressed
24 lightMode = 1 -lightMode ;
26 digitalWrite(LED,lightMode);
27 buttonState = val; // save the new state in our variable