mirror of
https://github.com/arduino/Arduino.git
synced 2025-01-29 18:52:13 +01:00
Added LED to InputPullup example
This commit is contained in:
parent
81b6ca2d61
commit
1b58e45f74
@ -6,6 +6,7 @@
|
||||
|
||||
The circuit:
|
||||
* Momentary switch attached from pin 2 to ground
|
||||
* Built-in LED on pin 13
|
||||
|
||||
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
|
||||
@ -24,7 +25,8 @@ void setup(){
|
||||
//start serial connection
|
||||
Serial.begin(9600);
|
||||
//configure pin2 as an input and enable the internal pull-up resistor
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
pinMode(2, INPUT_PULLUP);
|
||||
pinMode(13, OUTPUT);
|
||||
|
||||
}
|
||||
|
||||
@ -33,9 +35,18 @@ void loop(){
|
||||
int sensorVal = digitalRead(2);
|
||||
//print out the value of the pushbutton
|
||||
Serial.println(sensorVal);
|
||||
//brief delay
|
||||
delay(10);
|
||||
|
||||
|
||||
// Keep in mind the pullup means the pushbutton's
|
||||
// logic is inverted. It goes HIGH when it's pressed,
|
||||
// and LOW when it's not. Turn on pin 13 when the
|
||||
// button's pressed, and off when it's not:
|
||||
if (sensorVal == HIGH) {
|
||||
digitalWrite(13, LOW);
|
||||
}
|
||||
else {
|
||||
digitalWrite(13, HIGH);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user