/* Using a slide switch to turn the LED ON and OFF
https://github.com/ostad-ai/Arduino-Tutorial
*/
//The common contact of the slide switch is connected
//to the GROUNG by sliding the slider to the left,
//so the pin value at switch_pin becomes LOW.
//In contrast, by sliding the slider of switch to the right,
// it is disconnected. Since we define switch_pin as INPUT_PULLUP,
// it is read as HIGH if the pin is disconnected.
const int LED_pin=13, switch_pin=3;
void setup() {
// put your setup code here, to run once:
pinMode(LED_pin, OUTPUT);
pinMode(switch_pin, INPUT_PULLUP);
}
void loop() {
// put your main code here, to run repeatedly:
int switch_state=digitalRead(switch_pin);
digitalWrite(LED_pin, switch_state);
}