File tree 1 file changed +39
-0
lines changed
build/shared/examples/2.Digital/DigitalIputPullup
1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change
1
+ /*
2
+ Input Pullup Serial
3
+
4
+ This example demonstrates the use of pinMode(INPUT_PULLUP). It reads a
5
+ digital input on pin 2 and prints the results to the serial monitor.
6
+
7
+ The circuit:
8
+ * Momentary switch attached from pin 2 to ground
9
+
10
+ Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
11
+ 20K-ohm resistor is pulled to 5V. This configuration causes the input to
12
+ read HIGH when the switch is open, and LOW when it is closed.
13
+
14
+ created 14 March 2012
15
+ by Scott Fitzgerald
16
+
17
+ This example code is in the public domain
18
+
19
+ */
20
+
21
+ void setup (){
22
+ // start serial connection
23
+ Serial.begin (9600 );
24
+ // configure pin2 as an input and enable the internal pull-up resistor
25
+ pinMode (2 , INPUT_PULLUP);
26
+
27
+ }
28
+
29
+ void loop (){
30
+ // read the pushbutton value into a variable
31
+ int sensorVal = digitalRead (2 );
32
+ // print out the value of the pushbutton
33
+ Serial.println (sensorVal);
34
+ // brief delay
35
+ delay (10 );
36
+
37
+ }
38
+
39
+
You can’t perform that action at this time.
0 commit comments