]> git.piffa.net Git - sketchbook_andrea/blob - basic/switch_LED_2/switch_LED_2.ino
PWM
[sketchbook_andrea] / basic / switch_LED_2 / switch_LED_2.ino
1 /*
2  *  Switch and LED test program
3  */
4  
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
8
9
10 void setup() {
11   pinMode(ledPin, OUTPUT);      // Set the LED pin as output
12   pinMode(switchPin, INPUT);    // Set the switch pin as input
13 }
14
15
16 void loop(){
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
20   }
21   if (val == HIGH) {              // check if the button is not pressed
22     digitalWrite(ledPin, LOW);    // turn LED off
23   }
24 }