2011-08-30 21:33:32 +02:00
|
|
|
/*
|
|
|
|
DigitalReadSerial
|
2013-10-21 09:58:40 +02:00
|
|
|
Reads a digital input on pin 2, prints the result to the serial monitor
|
|
|
|
|
2011-08-30 21:33:32 +02:00
|
|
|
This example code is in the public domain.
|
|
|
|
*/
|
|
|
|
|
2012-04-16 13:58:55 +02:00
|
|
|
// digital pin 2 has a pushbutton attached to it. Give it a name:
|
|
|
|
int pushButton = 2;
|
|
|
|
|
|
|
|
// the setup routine runs once when you press reset:
|
2011-08-30 21:33:32 +02:00
|
|
|
void setup() {
|
2012-04-16 13:58:55 +02:00
|
|
|
// initialize serial communication at 9600 bits per second:
|
2011-08-30 21:33:32 +02:00
|
|
|
Serial.begin(9600);
|
2012-04-16 13:58:55 +02:00
|
|
|
// make the pushbutton's pin an input:
|
|
|
|
pinMode(pushButton, INPUT);
|
2011-08-30 21:33:32 +02:00
|
|
|
}
|
|
|
|
|
2012-04-16 13:58:55 +02:00
|
|
|
// the loop routine runs over and over again forever:
|
2011-08-30 21:33:32 +02:00
|
|
|
void loop() {
|
2012-04-16 13:58:55 +02:00
|
|
|
// read the input pin:
|
|
|
|
int buttonState = digitalRead(pushButton);
|
|
|
|
// print out the state of the button:
|
|
|
|
Serial.println(buttonState);
|
2012-04-19 16:39:34 +02:00
|
|
|
delay(1); // delay in between reads for stability
|
2011-08-30 21:33:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|