2 * Switch and LED test program
5 int ledPin = 12; // LED is connected to pin 12
6 int switchPin = 2; // switch is connected to pin 2
7 int val; // variable for reading the pin status
11 pinMode(ledPin, OUTPUT); // Set the LED pin as output
12 pinMode(switchPin, INPUT); // Set the switch pin as input
17 val = digitalRead(switchPin); // read input value and store it in val
18 if (val == LOW) { // check if the button is pressed
19 digitalWrite(ledPin, HIGH); // turn LED on
21 if (val == HIGH) { // check if the button is not pressed
22 digitalWrite(ledPin, LOW); // turn LED off