1
0
mirror of https://github.com/arduino/Arduino.git synced 2024-12-04 15:24:12 +01:00
Arduino/build/shared/examples/01.Basics/DigitalReadSerial/DigitalReadSerial.ino

30 lines
732 B
Arduino
Raw Normal View History

/*
DigitalReadSerial
Reads a digital input on pin 2, prints the result to the serial monitor
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:
void setup() {
2012-04-16 13:58:55 +02:00
// initialize serial communication at 9600 bits per second:
Serial.begin(9600);
2012-04-16 13:58:55 +02:00
// make the pushbutton's pin an input:
pinMode(pushButton, INPUT);
}
2012-04-16 13:58:55 +02:00
// the loop routine runs over and over again forever:
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);
delay(1); // delay in between reads for stability
}