Page 40
The buttons we used here are similar to the buttons in
most video game controllers.
Circuit 2
Arduino Code:
5
Troubleshooting:
Light Not Turning On
The pushbutton is square, and because of this it is easy to
put it in the wrong way. Give it a 90 degree twist and see
if it starts working.
Underwhelmed
No worries, these circuits are all super stripped down to
make playing with the components easy, but once you
throw them together the sky is the limit.
You should see the LED turn on
if you press either button, and off
if you press both buttons. (See the
code to find out why!) If it isn't
working, make sure you have
assembled the circuit correctly
and verified and uploaded the
code to your board or see the
troubleshooting tips below.
Code to Note:
Real World Application:
Open Arduino IDE
//
File > Examples > SIK Guide >
Circuit # 5
What You Should See:
The digital pins can be used as inputs as well as outputs.
Before you do either, you need to tell the RedBoard
which direction you're going.
pinMode(button2Pin, INPUT);
Because we've connected the button to GND, it will read LOW when
it's being pressed. Here we're using the "equivalence" operator ("==")
to see if the button is being pressed.
if (button1State == LOW)
To read a digital input, you use the digitalRead()
function. It will return HIGH if there's 5V present at the
pin, or LOW if there's 0V present at the pin.
button1State = digitalRead(button1Pin);
IOREF
RES
ET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9
8
7
~6
~5
4
~3
2
1
0
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOG IN
DIGIT
AL (PWM~)
ON
ISP
TX
RX
IOREF
RES
ET
RESET
7-15V
SCL
SDA
AREF
GND
13
12
~11
~10
~9
8
7
~6
~5
4
~3
2
1
0
TX
RX
13
3.3V
5V
GND
GND
VIN
A0
A1
A2
A3
A4
A5
POWER
ANALOG IN
DIGIT
AL (PWM~)
ON
ISP
TX
RX
LEARN. SHARE. HACK.
Содержание RedBoard
Страница 13: ...Page 11...