mirror of https://github.com/noisymime/Arduino.git
Added DigitalInputPullup example by Scott Fitzgerald
This commit is contained in:
parent
7f11df115d
commit
b2fe779ec0
|
@ -0,0 +1,39 @@
|
||||||
|
/*
|
||||||
|
Input Pullup Serial
|
||||||
|
|
||||||
|
This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
|
||||||
|
digital input on pin 2 and prints the results to the serial monitor.
|
||||||
|
|
||||||
|
The circuit:
|
||||||
|
* Momentary switch attached from pin 2 to ground
|
||||||
|
|
||||||
|
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
|
||||||
|
20K-ohm resistor is pulled to 5V. This configuration causes the input to
|
||||||
|
read HIGH when the switch is open, and LOW when it is closed.
|
||||||
|
|
||||||
|
created 14 March 2012
|
||||||
|
by Scott Fitzgerald
|
||||||
|
|
||||||
|
This example code is in the public domain
|
||||||
|
|
||||||
|
*/
|
||||||
|
|
||||||
|
void setup(){
|
||||||
|
//start serial connection
|
||||||
|
Serial.begin(9600);
|
||||||
|
//configure pin2 as an input and enable the internal pull-up resistor
|
||||||
|
pinMode(2, INPUT_PULLUP);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop(){
|
||||||
|
//read the pushbutton value into a variable
|
||||||
|
int sensorVal = digitalRead(2);
|
||||||
|
//print out the value of the pushbutton
|
||||||
|
Serial.println(sensorVal);
|
||||||
|
//brief delay
|
||||||
|
delay(10);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue