Library for ELEC2645 Gamepad PCB. University of Leeds
Dependents: Project_MaZe1_copy Labirint Game_Controller_Project 200943373MAZE ... more
Gamepad.h
- Committer:
- eencae
- Date:
- 2017-02-06
- Revision:
- 5:ce5eae9ee934
- Parent:
- 4:bafb7f483e93
- Child:
- 6:b1c3dfe67f7d
File content as of revision 5:ce5eae9ee934:
#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. 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 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(); 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