File tree Expand file tree Collapse file tree 1 file changed +15
-4
lines changed
build/shared/examples/2.Digital/DigitalIputPullup Expand file tree Collapse file tree 1 file changed +15
-4
lines changed Original file line number Diff line number Diff line change 66
77 The circuit:
88 * Momentary switch attached from pin 2 to ground
9+ * Built-in LED on pin 13
910
1011 Unlike pinMode(INPUT), there is no pull-down resistor necessary. An internal
1112 20K-ohm resistor is pulled to 5V. This configuration causes the input to
@@ -24,7 +25,8 @@ void setup(){
2425 // start serial connection
2526 Serial.begin (9600 );
2627 // 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);
2830
2931}
3032
@@ -33,9 +35,18 @@ void loop(){
3335 int sensorVal = digitalRead (2 );
3436 // print out the value of the pushbutton
3537 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+ }
3949}
4050
4151
52+
You can’t perform that action at this time.
0 commit comments