Objective: In this activity you'll learn how to connect a joystick to an Arduino board and use its push button feature to implement a "stop" button for a program that is running. The code: The pre-placed code blocks set up pin 13 (the red LED) for output and pin 2 (the joystick's B pin) for input. The code then turns on the red LED and starts a loop that keeps reading the joystick's B pin until it gets a nonzero "high" or "1" signal, indicating that the joystick button was pushed. (The B pin has a "low" or "0" value when not being pushed.) The loop then ends and the final code block turns off the LED. Connections (see diagram below): The joystick has five pins: Y, X, B, VCC, and GND. Using male-to-female wires, connect the VCC and GND pins to the 5V and one of the GND pins, respectively, in the Power section of the Arduino. Connect the B (button) pin to digital pin 2 on the Arduino. For this activity we don't need the X and Y pins (the blue and green wires). For the LED module (not shown on the diagram), plug in its B, G, and R pins to digital pins 11, 12, and 13, respectively, on the Arduino, with the module's "-" pin going in the GND pin.
|
Grid Size: S M L | Simple View: | MinView: |
Coord: x-axis y-axis | Grid Lines: x-axis y-axis | |||
Grid: | 12x12 inches | 24x24 inches | 36x36 inches | |
72x72 inches | 96x96 inches | 192x192 inches | ||
1x1 inches | 2x2 inches | Fraction: | ||
xy-Range: | ||||
|
||||
|
||||
Quad: | 1 Quadrant | 4 Quadrants | 1&4 Quadrants | |
Units: | US Customary | Metric | Ruler: |
Labels: |
|
|
|
Font
px
|
|
Tics Lines: |
|
Width
px
|
Hash Lines: |
|
Width
px
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
(
,
in
) in
|
|
degrees
|
|
|
Modify the code so that it uses the green or blue LED instead of the red one. |
|
|
|||||||||||
|
|||||||||||