source: arduino-1-6-7/trunk/fuentes/arduino-ide-amd64/examples/02.Digital/Button/Button.ino @ 4837

Last change on this file since 4837 was 4837, checked in by daduve, 2 years ago

Adding new version

File size: 1.3 KB
Line 
1/*
2  Button
3
4 Turns on and off a light emitting diode(LED) connected to digital
5 pin 13, when pressing a pushbutton attached to pin 2.
6
7
8 The circuit:
9 * LED attached from pin 13 to ground
10 * pushbutton attached to pin 2 from +5V
11 * 10K resistor attached to pin 2 from ground
12
13 * Note: on most Arduinos there is already an LED on the board
14 attached to pin 13.
15
16
17 created 2005
18 by DojoDave <http://www.0j0.org>
19 modified 30 Aug 2011
20 by Tom Igoe
21
22 This example code is in the public domain.
23
24 http://www.arduino.cc/en/Tutorial/Button
25 */
26
27// constants won't change. They're used here to
28// set pin numbers:
29const int buttonPin = 2;     // the number of the pushbutton pin
30const int ledPin =  13;      // the number of the LED pin
31
32// variables will change:
33int buttonState = 0;         // variable for reading the pushbutton status
34
35void setup() {
36  // initialize the LED pin as an output:
37  pinMode(ledPin, OUTPUT);
38  // initialize the pushbutton pin as an input:
39  pinMode(buttonPin, INPUT);
40}
41
42void loop() {
43  // read the state of the pushbutton value:
44  buttonState = digitalRead(buttonPin);
45
46  // check if the pushbutton is pressed.
47  // if it is, the buttonState is HIGH:
48  if (buttonState == HIGH) {
49    // turn LED on:
50    digitalWrite(ledPin, HIGH);
51  } else {
52    // turn LED off:
53    digitalWrite(ledPin, LOW);
54  }
55}
Note: See TracBrowser for help on using the repository browser.