Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Gamepad Class Reference
#include <Gamepad.h>
Public Member Functions | |
| Gamepad () | |
| Constructor. | |
| void | init () |
| Initialise all peripherals and configure interrupts. | |
| void | leds_on () |
| Turn all LEDs on. | |
| void | leds_off () |
| Turn all LEDs off. | |
| void | leds (float val) const |
| Set all LEDs to duty-cycle. | |
| void | led (int n, float val) const |
| Set LED to duty-cycle. | |
| float | read_pot1 () const |
| Read potentiometer 1 value. | |
| float | read_pot2 () const |
| Read potentiometer 2 value. | |
| float | read_adc () const |
| Read padc value. | |
| float | get_mag () |
| Get magnitude of joystick movement. | |
| float | get_angle () |
| Get angle of joystick movement. | |
| Direction | get_direction () |
| Gets joystick direction. | |
| Vector2D | get_coord () |
| Gets raw cartesian co-ordinates of joystick. | |
| Vector2D | get_mapped_coord () |
| Gets cartesian coordinates mapped to circular grid. | |
| Polar | get_polar () |
| Gets polar coordinates of the joystick. | |
| void | reset_buttons () |
| Resets all button states. | |
| bool | A_pressed () |
| Returns true if A has been pressed. | |
| bool | A_held () |
| Returns true if A is held. | |
| bool | B_pressed () |
| Returns true if B has been pressed. | |
| bool | B_held () |
| Returns true if B is held. | |
| bool | X_pressed () |
| Returns true if B has been pressed. | |
| bool | X_held () |
| Returns true if X is held. | |
| bool | Y_pressed () |
| Returns true if Y has been pressed. | |
| bool | Y_held () |
| Returns true if Y is held. | |
| bool | start_pressed () |
| Returns true if start has been pressed. | |
| bool | start_held () |
| Returns true if start is held. | |
| void | tone (const float frequency, const float duration) |
| Play a single tone for the specifed duration. | |
| void | play_melody (int length, const int *notes, const int *durations, float bpm, bool repeat) |
| Play a melody. | |
| void | set_bpm (float bpm) |
| Set the BPM of the melody. | |
| void | write_dac (float val) |
| Write an analog voltage to the speaker. | |
Detailed Description
Gamepad Class.
Library for interfacing with ELEC2645 Gamepad PCB, University of Leeds
Definition at line 55 of file Gamepad.h.
Constructor & Destructor Documentation
| Gamepad | ( | ) |
Constructor.
Definition at line 6 of file Gamepad.cpp.
Member Function Documentation
| bool A_held | ( | ) |
Returns true if A is held.
- Returns:
- a bool corresponding to A being held
Definition at line 259 of file Gamepad.cpp.
| bool A_pressed | ( | ) |
Returns true if A has been pressed.
- Returns:
- a bool corresponding to A being pressed
Definition at line 209 of file Gamepad.cpp.
| bool B_held | ( | ) |
Returns true if B is held.
- Returns:
- a bool corresponding to B being held
Definition at line 265 of file Gamepad.cpp.
| bool B_pressed | ( | ) |
Returns true if B has been pressed.
- Returns:
- a bool corresponding to B being pressed
Definition at line 219 of file Gamepad.cpp.
| float get_angle | ( | ) |
Get angle of joystick movement.
- Returns:
- value in range 0.0 to 359.9. 0.0 corresponds to N, 180.0 to S. -1.0 is central
Definition at line 167 of file Gamepad.cpp.
| Vector2D get_coord | ( | ) |
Gets raw cartesian co-ordinates of joystick.
- Returns:
- a struct with x,y members, each in the range 0.0 to 1.0
Definition at line 293 of file Gamepad.cpp.
| Direction get_direction | ( | ) |
Gets joystick direction.
- Returns:
- an enum: CENTRE, N, NE, E, SE, S, SW, W, NW,
Definition at line 173 of file Gamepad.cpp.
| float get_mag | ( | ) |
Get magnitude of joystick movement.
- Returns:
- value in range 0.0 to 1.0
Definition at line 160 of file Gamepad.cpp.
| Vector2D get_mapped_coord | ( | ) |
Gets cartesian coordinates mapped to circular grid.
- Returns:
- a struct with x,y members, each in the range 0.0 to 1.0
Definition at line 308 of file Gamepad.cpp.
| Polar get_polar | ( | ) |
Gets polar coordinates of the joystick.
- Returns:
- a struct contains mag and angle
Definition at line 321 of file Gamepad.cpp.
| void init | ( | ) |
Initialise all peripherals and configure interrupts.
Definition at line 40 of file Gamepad.cpp.
| void led | ( | int | n, |
| float | val | ||
| ) | const |
Set LED to duty-cycle.
- Parameters:
-
led number (0 to 5) value in range 0.0 to 1.0
Definition at line 108 of file Gamepad.cpp.
| void leds | ( | float | val ) | const |
Set all LEDs to duty-cycle.
- Parameters:
-
value in range 0.0 to 1.0
Definition at line 87 of file Gamepad.cpp.
| void leds_off | ( | ) |
Turn all LEDs off.
Definition at line 77 of file Gamepad.cpp.
| void leds_on | ( | ) |
Turn all LEDs on.
Definition at line 82 of file Gamepad.cpp.
| void play_melody | ( | int | length, |
| const int * | notes, | ||
| const int * | durations, | ||
| float | bpm, | ||
| bool | repeat | ||
| ) |
Play a melody.
- Parameters:
-
length of note array array of note frequencies (in Hz) - 0 treated as a rest array of note durations (4 corresponds to 1/4, 8 is 1/8 etc.) beats per minute whether to repeat or play just once
Definition at line 398 of file Gamepad.cpp.
| float read_adc | ( | ) | const |
| float read_pot1 | ( | ) | const |
Read potentiometer 1 value.
- Returns:
- potentiometer value in range 0.0 to 1.0
Definition at line 144 of file Gamepad.cpp.
| float read_pot2 | ( | ) | const |
Read potentiometer 2 value.
- Returns:
- potentiometer value in range 0.0 to 1.0
Definition at line 149 of file Gamepad.cpp.
| void reset_buttons | ( | ) |
Resets all button states.
Useful for calling inbetween scenes where you do not want button presses from the previous scene effecting the current scene
Definition at line 204 of file Gamepad.cpp.
| void set_bpm | ( | float | bpm ) |
| bool start_held | ( | ) |
Returns true if start is held.
- Returns:
- a bool corresponding to start being held
Definition at line 280 of file Gamepad.cpp.
| bool start_pressed | ( | ) |
Returns true if start has been pressed.
- Returns:
- a bool corresponding to start being pressed
Definition at line 249 of file Gamepad.cpp.
| void tone | ( | const float | frequency, |
| const float | duration | ||
| ) |
Play a single tone for the specifed duration.
- Parameters:
-
note frequency (in Hz) duration (in s)
Definition at line 383 of file Gamepad.cpp.
| void write_dac | ( | float | val ) |
Write an analog voltage to the speaker.
- Parameters:
-
voltage in range 0.0 to 1.0 (corresponds 0.0 to 3.3 V)
Definition at line 412 of file Gamepad.cpp.
| bool X_held | ( | ) |
Returns true if X is held.
- Returns:
- a bool corresponding to X being held
Definition at line 270 of file Gamepad.cpp.
| bool X_pressed | ( | ) |
Returns true if B has been pressed.
- Returns:
- a bool corresponding to B being pressed
Definition at line 229 of file Gamepad.cpp.
| bool Y_held | ( | ) |
Returns true if Y is held.
- Returns:
- a bool corresponding to Y being held
Definition at line 275 of file Gamepad.cpp.
| bool Y_pressed | ( | ) |
Returns true if Y has been pressed.
- Returns:
- a bool corresponding to Y being pressed
Definition at line 239 of file Gamepad.cpp.
Generated on Fri Aug 5 2022 06:55:08 by
1.7.2