Experiment 3: Read joystick pushbutton switches
Steps
Read moreThe pushbutton switches are simply connected to Arduino digital I/O pins as shown in the table below:
When Key A is pressed a digital signal will be sent to D2 and so on. We will use the digitalRead() function to determine the state of the buttons.
Since there are no resistors connected to these buttons on joystick shield you have to enable pull up resistors on your Arduino. Below is the code to enable the pullup resistors and read the digital values.
Whenever a user presses a pushbutton, the Arduino will display the button value on the serial monitor.
- Attach your joystick shield over arduino board.
- Connect your arduino board to your PC.
- Led will light on your joystick shield showing that it’s working properly.
- Write the sketch and compile it before uploading to your board (it's good practice to compile your sketch before uploading).
- After the sketch is uploaded, run serial monitor to observe the values.
- Press any button on your joystick and it will display which button is pressed.
Comments