]> git.piffa.net Git - arduino/blob - books/ArduinoNextSteps-master/ArduinoNextSteps/sketch_01_03_paperclip/sketch_01_03_paperclip.ino
first commit
[arduino] / books / ArduinoNextSteps-master / ArduinoNextSteps / sketch_01_03_paperclip / sketch_01_03_paperclip.ino
1 // sketch 01_03_paperclip
2 int ledPin = 13;
3 int switchPin = 7;
4
5 void setup()
6 {
7   pinMode(ledPin, OUTPUT);
8   pinMode(switchPin, INPUT_PULLUP);
9 }
10
11 void loop()
12 {
13   if (digitalRead(switchPin) == LOW)
14   {
15     flash(100);
16   }
17   else
18   {
19     flash(500);
20   }
21 }
22
23 void flash(int delayPeriod)
24 {
25   digitalWrite(ledPin, HIGH);
26   delay(delayPeriod);
27   digitalWrite(ledPin, LOW);
28   delay(delayPeriod);
29 }