Professional Documents
Culture Documents
Digital Input
00101001100
001000011001
00111001100
???
ANGLE 1 0 ???
90
0
How to make digital output
Down Up
LOW HIGH
HIGH and LOW input voltages
in INPUT_PULLUP mode
HIGH LOW
5V
3V
???
1.5V
0V
Wiring a button
2 Modes:
INPUT
INPUT_PULLUP
Full explanation of different wiring methods is
demonstrated here: http://gammon.com.au/switches
INPUT Wire the button with two branches:
This is the schematic symbol
for a button or switch
+5V
Pin 2 GND
The button / circuit is OPEN
+5V
+5V
+5V Pin 2
Opposite of your intuition
HIGH
LOW
Coding for a button
The Arduino will read the button state only
when the code says to.
Sample
In global space: Constant - this value may not ever change in this program
In loop function:
int button1State; These variables are “local” to the loop function, their
int button2State; values will be assigned later - they’re just given a type
and a name
Next: Set your digital input pin to
INPUT_PULLUP mode
void setup() {
}
In your code for circuit 5:
read both button states and assign to the
button1State and button2State variables.
void loop()
{
int button1State; digitalRead command
int button2State; On this button pin
do that
}
Otherwise do that other thing
else
}
if( LOW && HIGH || HIGH && LOW )
“AND” “OR”
“AND”
{ THEN...
digitalWrite(ledPin,HIGH);
} else { OTHERWISE
digitalWrite(ledPin,LOW);
}