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. | |
| void | tone (float frequency, float duration) |
| Play tone on piezo (NOTE: Frequencys below 1kHz can damage the speaker) | |
| 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. | |
Detailed Description
Gamepad Class.
Library for interfacing with ELEC2645 Gamepad PCB, University of Leeds
Definition at line 52 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 258 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 213 of file Gamepad.cpp.
| bool B_held | ( | ) |
Returns true if B is held.
- Returns:
- a bool corresponding to B being held
Definition at line 263 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 222 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 172 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 303 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 178 of file Gamepad.cpp.
| float get_mag | ( | ) |
Get magnitude of joystick movement.
- Returns:
- value in range 0.0 to 1.0
Definition at line 165 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 322 of file Gamepad.cpp.
| Polar get_polar | ( | ) |
Gets polar coordinates of the joystick.
- Returns:
- a struct contains mag and angle
Definition at line 335 of file Gamepad.cpp.
| void init | ( | ) |
Initialise all peripherals and configure interrupts.
Definition at line 42 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 102 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 81 of file Gamepad.cpp.
| void leds_off | ( | ) |
Turn all LEDs off.
Definition at line 71 of file Gamepad.cpp.
| void leds_on | ( | ) |
Turn all LEDs on.
Definition at line 76 of file Gamepad.cpp.
| float read_pot1 | ( | ) | const |
Read potentiometer 1 value.
- Returns:
- potentiometer value in range 0.0 to 1.0
Definition at line 138 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 143 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 209 of file Gamepad.cpp.
| bool start_held | ( | ) |
Returns true if start is held.
- Returns:
- a bool corresponding to start being held
Definition at line 275 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 | ( | float | frequency, |
| float | duration | ||
| ) |
Play tone on piezo (NOTE: Frequencys below 1kHz can damage the speaker)
- Parameters:
-
frequency in Hz duration of tone in seconds
Definition at line 148 of file Gamepad.cpp.
| bool X_held | ( | ) |
Returns true if X is held.
- Returns:
- a bool corresponding to X being held
Definition at line 267 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 231 of file Gamepad.cpp.
| bool Y_held | ( | ) |
Returns true if Y is held.
- Returns:
- a bool corresponding to Y being held
Definition at line 271 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 240 of file Gamepad.cpp.
Generated on Sat Jul 16 2022 16:00:56 by
1.7.2