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 | 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 254 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 204 of file Gamepad.cpp.
bool B_held | ( | ) |
Returns true if B is held.
- Returns:
- a bool corresponding to B being held
Definition at line 260 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 214 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 162 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 288 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 168 of file Gamepad.cpp.
float get_mag | ( | ) |
Get magnitude of joystick movement.
- Returns:
- value in range 0.0 to 1.0
Definition at line 155 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 303 of file Gamepad.cpp.
Polar get_polar | ( | ) |
Gets polar coordinates of the joystick.
- Returns:
- a struct contains mag and angle
Definition at line 316 of file Gamepad.cpp.
void init | ( | ) |
Initialise all peripherals and configure interrupts.
Definition at line 39 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 107 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 86 of file Gamepad.cpp.
void leds_off | ( | ) |
Turn all LEDs off.
Definition at line 76 of file Gamepad.cpp.
void leds_on | ( | ) |
Turn all LEDs on.
Definition at line 81 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 393 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 143 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 148 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 199 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 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 244 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 378 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 407 of file Gamepad.cpp.
bool X_held | ( | ) |
Returns true if X is held.
- Returns:
- a bool corresponding to X being held
Definition at line 265 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 224 of file Gamepad.cpp.
bool Y_held | ( | ) |
Returns true if Y is held.
- Returns:
- a bool corresponding to Y being held
Definition at line 270 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 234 of file Gamepad.cpp.
Generated on Wed Jul 27 2022 16:36:33 by
