Luke O. Cartwright 201225242
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. | |
| void | write_u16 (unsigned short val) |
| Writes 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 255 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 205 of file Gamepad.cpp.
| bool B_held | ( | ) |
Returns true if B is held.
- Returns:
- a bool corresponding to B being held
Definition at line 261 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 215 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 163 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 289 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 169 of file Gamepad.cpp.
| float get_mag | ( | ) |
Get magnitude of joystick movement.
- Returns:
- value in range 0.0 to 1.0
Definition at line 156 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 304 of file Gamepad.cpp.
| Polar get_polar | ( | ) |
Gets polar coordinates of the joystick.
- Returns:
- a struct contains mag and angle
Definition at line 317 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 395 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 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 200 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 276 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 245 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 380 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 409 of file Gamepad.cpp.
| void write_u16 | ( | unsigned short | val ) |
Writes analog voltage to the speaker.
- Parameters:
-
voltage in range 0 to 65535 (corresponds 0.0 to 3.3 V)
Definition at line 420 of file Gamepad.cpp.
| bool X_held | ( | ) |
Returns true if X is held.
- Returns:
- a bool corresponding to X being held
Definition at line 266 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 225 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 235 of file Gamepad.cpp.
Generated on Tue Jul 12 2022 19:25:36 by
1.7.2