/* Program 2-7 Reading SW and use it to control the LED. */ const int LED = 13; /* LED internally connected*/ const int SW1 = 3; /* use pin 3 for SW1 externally connected */ int mySW = 0; /* mySW status*/ void setup() { /* configure input output pins for switch and LED */ pinMode(LED, OUTPUT); pinMode(SW1, INPUT); } void loop() { /* read switch and use the value to set LED */ mySW=digitalRead(SW1); if (mySW==0) digitalWrite(LED, 0); else digitalWrite(LED, 1); }