Library for ELEC2645 Gamepad PCB. University of Leeds Version 2 January 2020
Dependents: ELEC2645_Ticker_WAV ELEC2645_Project_username ELEC2645_Project_el18vgt ELEC2645_Project_el17oc11 ... more
Gamepad.h
- Committer:
- eencae
- Date:
- 2017-02-06
- Revision:
- 4:bafb7f483e93
- Parent:
- 3:964a6d95acdd
- Child:
- 5:ce5eae9ee934
File content as of revision 4:bafb7f483e93:
#ifndef GAMEPAD_H #define GAMEPAD_H #include "mbed.h" #define TOL 0.1f #define RAD2DEG 57.2957795131f enum Direction { CENTRE, // 0 N, // 1 NE, // 2 E, // 3 SE, // 4 S, // 5 SW, // 6 W, // 7 NW // 8 }; struct Vector2D { float x; float y; }; struct Polar { float mag; float angle; }; class Gamepad { public: Gamepad(); ~Gamepad(); void init(); void leds_on(); void leds_off(); void fade_leds(float val); float read_pot(); void tone(float frequency, float duration); bool a_pressed(); bool b_pressed(); bool x_pressed(); bool y_pressed(); bool l_pressed(); bool r_pressed(); bool back_pressed(); bool start_pressed(); bool joystick_pressed(); float get_mag(); float get_angle(); Direction get_direction(); // N,NE,E,SE etc. private: PwmOut *led_1; PwmOut *led_2; PwmOut *led_3; PwmOut *led_4; PwmOut *led_5; PwmOut *led_6; InterruptIn *button_A; InterruptIn *button_B; InterruptIn *button_X; InterruptIn *button_Y; InterruptIn *button_back; InterruptIn *button_start; InterruptIn *button_L; InterruptIn *button_R; InterruptIn *button_joystick; AnalogIn *vert; AnalogIn *horiz; PwmOut *buzzer; AnalogIn *pot; Timeout *timeout; void init_buttons(); void tone_off(); void a_isr(); void b_isr(); void x_isr(); void y_isr(); void l_isr(); void r_isr(); void back_isr(); void start_isr(); void joy_isr(); Vector2D get_coord(); // cartesian co-ordinates x,y Vector2D get_mapped_coord(); // x,y mapped to circle Polar get_polar(); // mag and angle in struct form bool a_flag,b_flag,x_flag,y_flag,l_flag,r_flag,back_flag,start_flag,joy_flag; // centred x,y values float _x0; float _y0; }; #endif