File tree 1 file changed +15
-4
lines changed
build/shared/examples/2.Digital/DigitalIputPullup
1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 6
6
7
7
The circuit:
8
8
* Momentary switch attached from pin 2 to ground
9
+ * Built-in LED on pin 13
9
10
10
11
Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
11
12
20K-ohm resistor is pulled to 5V. This configuration causes the input to
@@ -24,7 +25,8 @@ void setup(){
24
25
// start serial connection
25
26
Serial.begin (9600 );
26
27
// configure pin2 as an input and enable the internal pull-up resistor
27
- pinMode (2 , INPUT_PULLUP);
28
+ pinMode (2 , INPUT_PULLUP);
29
+ pinMode (13 , OUTPUT);
28
30
29
31
}
30
32
@@ -33,9 +35,18 @@ void loop(){
33
35
int sensorVal = digitalRead (2 );
34
36
// print out the value of the pushbutton
35
37
Serial.println (sensorVal);
36
- // brief delay
37
- delay (10 );
38
-
38
+
39
+ // Keep in mind the pullup means the pushbutton's
40
+ // logic is inverted. It goes HIGH when it's pressed,
41
+ // and LOW when it's not. Turn on pin 13 when the
42
+ // button's pressed, and off when it's not:
43
+ if (sensorVal == HIGH) {
44
+ digitalWrite (13 , LOW);
45
+ }
46
+ else {
47
+ digitalWrite (13 , HIGH);
48
+ }
39
49
}
40
50
41
51
52
+
You can’t perform that action at this time.
0 commit comments