| 1 |
/* |
| 2 |
DigitalReadSerial |
| 3 |
|
| 4 |
Reads a digital input on pin 2, prints the result to the Serial Monitor |
| 5 |
|
| 6 |
This example code is in the public domain. |
| 7 |
|
| 8 |
https://www.arduino.cc/en/Tutorial/BuiltInExamples/DigitalReadSerial |
| 9 |
*/ |
| 10 |
|
| 11 |
// digital pin 2 has a pushbutton attached to it. Give it a name: |
| 12 |
int pushButton = 2; |
| 13 |
|
| 14 |
// the setup routine runs once when you press reset: |
| 15 |
void setup() { |
| 16 |
// initialize serial communication at 9600 bits per second: |
| 17 |
Serial.begin(9600); |
| 18 |
// make the pushbutton's pin an input: |
| 19 |
pinMode(pushButton, INPUT); |
| 20 |
} |
| 21 |
|
| 22 |
// the loop routine runs over and over again forever: |
| 23 |
void loop() { |
| 24 |
// read the input pin: |
| 25 |
int buttonState = digitalRead(pushButton); |
| 26 |
// print out the state of the button: |
| 27 |
Serial.println(buttonState); |
| 28 |
delay(1); // delay in between reads for stability |
| 29 |
} |