test test test
snake-test/ELEC2645_ProjecT/Gamepad2/Gamepad.h@0:e4c5e6ec922e, 2020-05-25 (annotated)
- Committer:
- mohamedmoawya
- Date:
- Mon May 25 19:06:11 2020 +0000
- Revision:
- 0:e4c5e6ec922e
snake game tteest
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mohamedmoawya | 0:e4c5e6ec922e | 1 | #ifndef GAMEPAD_H |
mohamedmoawya | 0:e4c5e6ec922e | 2 | #define GAMEPAD_H |
mohamedmoawya | 0:e4c5e6ec922e | 3 | |
mohamedmoawya | 0:e4c5e6ec922e | 4 | #include <bitset> |
mohamedmoawya | 0:e4c5e6ec922e | 5 | |
mohamedmoawya | 0:e4c5e6ec922e | 6 | // Forward declaration of the classes that we use from the mbed library |
mohamedmoawya | 0:e4c5e6ec922e | 7 | // This avoids the need for us to include the huge mbed.h header inside our |
mohamedmoawya | 0:e4c5e6ec922e | 8 | // own library API |
mohamedmoawya | 0:e4c5e6ec922e | 9 | namespace mbed |
mohamedmoawya | 0:e4c5e6ec922e | 10 | { |
mohamedmoawya | 0:e4c5e6ec922e | 11 | class AnalogIn; |
mohamedmoawya | 0:e4c5e6ec922e | 12 | class InterruptIn; |
mohamedmoawya | 0:e4c5e6ec922e | 13 | class PwmOut; |
mohamedmoawya | 0:e4c5e6ec922e | 14 | class AnalogOut; |
mohamedmoawya | 0:e4c5e6ec922e | 15 | class Ticker; |
mohamedmoawya | 0:e4c5e6ec922e | 16 | class Timeout; |
mohamedmoawya | 0:e4c5e6ec922e | 17 | } |
mohamedmoawya | 0:e4c5e6ec922e | 18 | |
mohamedmoawya | 0:e4c5e6ec922e | 19 | #define TOL 0.1f |
mohamedmoawya | 0:e4c5e6ec922e | 20 | #define RAD2DEG 57.2957795131f |
mohamedmoawya | 0:e4c5e6ec922e | 21 | #define PI 3.14159265359 |
mohamedmoawya | 0:e4c5e6ec922e | 22 | |
mohamedmoawya | 0:e4c5e6ec922e | 23 | |
mohamedmoawya | 0:e4c5e6ec922e | 24 | /** Enum for direction */ |
mohamedmoawya | 0:e4c5e6ec922e | 25 | enum Direction { |
mohamedmoawya | 0:e4c5e6ec922e | 26 | CENTRE, /**< joystick centred */ |
mohamedmoawya | 0:e4c5e6ec922e | 27 | N, /**< pushed North (0)*/ |
mohamedmoawya | 0:e4c5e6ec922e | 28 | NE, /**< pushed North-East (45) */ |
mohamedmoawya | 0:e4c5e6ec922e | 29 | E, /**< pushed East (90) */ |
mohamedmoawya | 0:e4c5e6ec922e | 30 | SE, /**< pushed South-East (135) */ |
mohamedmoawya | 0:e4c5e6ec922e | 31 | S, /**< pushed South (180) */ |
mohamedmoawya | 0:e4c5e6ec922e | 32 | SW, /**< pushed South-West (225) */ |
mohamedmoawya | 0:e4c5e6ec922e | 33 | W, /**< pushed West (270) */ |
mohamedmoawya | 0:e4c5e6ec922e | 34 | NW /**< pushed North-West (315) */ |
mohamedmoawya | 0:e4c5e6ec922e | 35 | }; |
mohamedmoawya | 0:e4c5e6ec922e | 36 | |
mohamedmoawya | 0:e4c5e6ec922e | 37 | /** Vector 2D struct */ |
mohamedmoawya | 0:e4c5e6ec922e | 38 | struct Vector2D { |
mohamedmoawya | 0:e4c5e6ec922e | 39 | float x; /**< float for x value */ |
mohamedmoawya | 0:e4c5e6ec922e | 40 | float y; /**< float for y value */ |
mohamedmoawya | 0:e4c5e6ec922e | 41 | }; |
mohamedmoawya | 0:e4c5e6ec922e | 42 | |
mohamedmoawya | 0:e4c5e6ec922e | 43 | /** Polar coordinate struct */ |
mohamedmoawya | 0:e4c5e6ec922e | 44 | struct Polar { |
mohamedmoawya | 0:e4c5e6ec922e | 45 | float mag; /**< float for magnitude */ |
mohamedmoawya | 0:e4c5e6ec922e | 46 | float angle; /**< float for angle (in degrees) */ |
mohamedmoawya | 0:e4c5e6ec922e | 47 | }; |
mohamedmoawya | 0:e4c5e6ec922e | 48 | |
mohamedmoawya | 0:e4c5e6ec922e | 49 | /** Gamepad Class |
mohamedmoawya | 0:e4c5e6ec922e | 50 | * @brief Library for interfacing with ELEC2645 Gamepad PCB, University of Leeds |
mohamedmoawya | 0:e4c5e6ec922e | 51 | * @author Dr Craig A. Evans |
mohamedmoawya | 0:e4c5e6ec922e | 52 | * @author Dr Alex Valavanis |
mohamedmoawya | 0:e4c5e6ec922e | 53 | * @author Joshua Davy |
mohamedmoawya | 0:e4c5e6ec922e | 54 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 55 | class Gamepad |
mohamedmoawya | 0:e4c5e6ec922e | 56 | { |
mohamedmoawya | 0:e4c5e6ec922e | 57 | |
mohamedmoawya | 0:e4c5e6ec922e | 58 | private: |
mohamedmoawya | 0:e4c5e6ec922e | 59 | mbed::PwmOut *_led1; |
mohamedmoawya | 0:e4c5e6ec922e | 60 | mbed::PwmOut *_led2; |
mohamedmoawya | 0:e4c5e6ec922e | 61 | mbed::PwmOut *_led3; |
mohamedmoawya | 0:e4c5e6ec922e | 62 | mbed::PwmOut *_led4; |
mohamedmoawya | 0:e4c5e6ec922e | 63 | mbed::PwmOut *_led5; |
mohamedmoawya | 0:e4c5e6ec922e | 64 | mbed::PwmOut *_led6; |
mohamedmoawya | 0:e4c5e6ec922e | 65 | |
mohamedmoawya | 0:e4c5e6ec922e | 66 | mbed::InterruptIn *_button_A; |
mohamedmoawya | 0:e4c5e6ec922e | 67 | mbed::InterruptIn *_button_B; |
mohamedmoawya | 0:e4c5e6ec922e | 68 | mbed::InterruptIn *_button_X; |
mohamedmoawya | 0:e4c5e6ec922e | 69 | mbed::InterruptIn *_button_Y; |
mohamedmoawya | 0:e4c5e6ec922e | 70 | mbed::InterruptIn *_button_start; |
mohamedmoawya | 0:e4c5e6ec922e | 71 | |
mohamedmoawya | 0:e4c5e6ec922e | 72 | mbed::AnalogIn *_vert; |
mohamedmoawya | 0:e4c5e6ec922e | 73 | mbed::AnalogIn *_horiz; |
mohamedmoawya | 0:e4c5e6ec922e | 74 | |
mohamedmoawya | 0:e4c5e6ec922e | 75 | mbed::AnalogIn *_pot1; |
mohamedmoawya | 0:e4c5e6ec922e | 76 | mbed::AnalogIn *_pot2; |
mohamedmoawya | 0:e4c5e6ec922e | 77 | |
mohamedmoawya | 0:e4c5e6ec922e | 78 | mbed::AnalogOut *dac; |
mohamedmoawya | 0:e4c5e6ec922e | 79 | mbed::Ticker *ticker; |
mohamedmoawya | 0:e4c5e6ec922e | 80 | mbed::Timeout *timeout; |
mohamedmoawya | 0:e4c5e6ec922e | 81 | mbed::Timeout *note_timeout; |
mohamedmoawya | 0:e4c5e6ec922e | 82 | |
mohamedmoawya | 0:e4c5e6ec922e | 83 | // centred x,y values |
mohamedmoawya | 0:e4c5e6ec922e | 84 | float _x0; |
mohamedmoawya | 0:e4c5e6ec922e | 85 | float _y0; |
mohamedmoawya | 0:e4c5e6ec922e | 86 | |
mohamedmoawya | 0:e4c5e6ec922e | 87 | float *_sample_array; |
mohamedmoawya | 0:e4c5e6ec922e | 88 | const int *_notes; |
mohamedmoawya | 0:e4c5e6ec922e | 89 | const int *_durations; |
mohamedmoawya | 0:e4c5e6ec922e | 90 | |
mohamedmoawya | 0:e4c5e6ec922e | 91 | int _n; |
mohamedmoawya | 0:e4c5e6ec922e | 92 | int _melody_length; |
mohamedmoawya | 0:e4c5e6ec922e | 93 | volatile unsigned int _sample; |
mohamedmoawya | 0:e4c5e6ec922e | 94 | volatile unsigned int _note; |
mohamedmoawya | 0:e4c5e6ec922e | 95 | float _bpm; |
mohamedmoawya | 0:e4c5e6ec922e | 96 | bool _repeat; |
mohamedmoawya | 0:e4c5e6ec922e | 97 | |
mohamedmoawya | 0:e4c5e6ec922e | 98 | |
mohamedmoawya | 0:e4c5e6ec922e | 99 | public: |
mohamedmoawya | 0:e4c5e6ec922e | 100 | /** Constructor */ |
mohamedmoawya | 0:e4c5e6ec922e | 101 | Gamepad(); |
mohamedmoawya | 0:e4c5e6ec922e | 102 | |
mohamedmoawya | 0:e4c5e6ec922e | 103 | /** Initialise all peripherals and configure interrupts */ |
mohamedmoawya | 0:e4c5e6ec922e | 104 | void init(); |
mohamedmoawya | 0:e4c5e6ec922e | 105 | |
mohamedmoawya | 0:e4c5e6ec922e | 106 | /** Turn all LEDs on */ |
mohamedmoawya | 0:e4c5e6ec922e | 107 | void leds_on(); |
mohamedmoawya | 0:e4c5e6ec922e | 108 | |
mohamedmoawya | 0:e4c5e6ec922e | 109 | /** Turn all LEDs off */ |
mohamedmoawya | 0:e4c5e6ec922e | 110 | void leds_off(); |
mohamedmoawya | 0:e4c5e6ec922e | 111 | |
mohamedmoawya | 0:e4c5e6ec922e | 112 | /** Set all LEDs to duty-cycle |
mohamedmoawya | 0:e4c5e6ec922e | 113 | *@param value in range 0.0 to 1.0 |
mohamedmoawya | 0:e4c5e6ec922e | 114 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 115 | void leds(float val) const; |
mohamedmoawya | 0:e4c5e6ec922e | 116 | |
mohamedmoawya | 0:e4c5e6ec922e | 117 | /** Set LED to duty-cycle |
mohamedmoawya | 0:e4c5e6ec922e | 118 | *@param led number (0 to 5) |
mohamedmoawya | 0:e4c5e6ec922e | 119 | *@param value in range 0.0 to 1.0 |
mohamedmoawya | 0:e4c5e6ec922e | 120 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 121 | void led(int n,float val) const; |
mohamedmoawya | 0:e4c5e6ec922e | 122 | |
mohamedmoawya | 0:e4c5e6ec922e | 123 | /** Read potentiometer 1 value |
mohamedmoawya | 0:e4c5e6ec922e | 124 | *@returns potentiometer value in range 0.0 to 1.0 |
mohamedmoawya | 0:e4c5e6ec922e | 125 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 126 | float read_pot1() const; |
mohamedmoawya | 0:e4c5e6ec922e | 127 | |
mohamedmoawya | 0:e4c5e6ec922e | 128 | /** Read potentiometer 2 value |
mohamedmoawya | 0:e4c5e6ec922e | 129 | *@returns potentiometer value in range 0.0 to 1.0 |
mohamedmoawya | 0:e4c5e6ec922e | 130 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 131 | float read_pot2() const; |
mohamedmoawya | 0:e4c5e6ec922e | 132 | |
mohamedmoawya | 0:e4c5e6ec922e | 133 | /** Get magnitude of joystick movement |
mohamedmoawya | 0:e4c5e6ec922e | 134 | * @returns value in range 0.0 to 1.0 |
mohamedmoawya | 0:e4c5e6ec922e | 135 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 136 | float get_mag(); |
mohamedmoawya | 0:e4c5e6ec922e | 137 | |
mohamedmoawya | 0:e4c5e6ec922e | 138 | /** Get angle of joystick movement |
mohamedmoawya | 0:e4c5e6ec922e | 139 | * @returns value in range 0.0 to 359.9. 0.0 corresponds to N, 180.0 to S. -1.0 is central |
mohamedmoawya | 0:e4c5e6ec922e | 140 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 141 | float get_angle(); |
mohamedmoawya | 0:e4c5e6ec922e | 142 | |
mohamedmoawya | 0:e4c5e6ec922e | 143 | /** Gets joystick direction |
mohamedmoawya | 0:e4c5e6ec922e | 144 | * @returns an enum: CENTRE, N, NE, E, SE, S, SW, W, NW, |
mohamedmoawya | 0:e4c5e6ec922e | 145 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 146 | Direction get_direction(); // N,NE,E,SE etc. |
mohamedmoawya | 0:e4c5e6ec922e | 147 | |
mohamedmoawya | 0:e4c5e6ec922e | 148 | /** Gets raw cartesian co-ordinates of joystick |
mohamedmoawya | 0:e4c5e6ec922e | 149 | * @returns a struct with x,y members, each in the range 0.0 to 1.0 |
mohamedmoawya | 0:e4c5e6ec922e | 150 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 151 | Vector2D get_coord(); // cartesian co-ordinates x,y |
mohamedmoawya | 0:e4c5e6ec922e | 152 | |
mohamedmoawya | 0:e4c5e6ec922e | 153 | /** Gets cartesian coordinates mapped to circular grid |
mohamedmoawya | 0:e4c5e6ec922e | 154 | * @returns a struct with x,y members, each in the range 0.0 to 1.0 |
mohamedmoawya | 0:e4c5e6ec922e | 155 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 156 | Vector2D get_mapped_coord(); // x,y mapped to circle |
mohamedmoawya | 0:e4c5e6ec922e | 157 | |
mohamedmoawya | 0:e4c5e6ec922e | 158 | /** Gets polar coordinates of the joystick |
mohamedmoawya | 0:e4c5e6ec922e | 159 | * @returns a struct contains mag and angle |
mohamedmoawya | 0:e4c5e6ec922e | 160 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 161 | Polar get_polar(); // mag and angle in struct form |
mohamedmoawya | 0:e4c5e6ec922e | 162 | |
mohamedmoawya | 0:e4c5e6ec922e | 163 | |
mohamedmoawya | 0:e4c5e6ec922e | 164 | /** Resets all button states. Useful for calling inbetween scenes |
mohamedmoawya | 0:e4c5e6ec922e | 165 | * where you do not want button presses from the previous scene effecting |
mohamedmoawya | 0:e4c5e6ec922e | 166 | * the current scene |
mohamedmoawya | 0:e4c5e6ec922e | 167 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 168 | void reset_buttons(); |
mohamedmoawya | 0:e4c5e6ec922e | 169 | |
mohamedmoawya | 0:e4c5e6ec922e | 170 | /** Returns true if A has been pressed |
mohamedmoawya | 0:e4c5e6ec922e | 171 | * @returns a bool corresponding to A being pressed |
mohamedmoawya | 0:e4c5e6ec922e | 172 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 173 | |
mohamedmoawya | 0:e4c5e6ec922e | 174 | bool A_pressed(); |
mohamedmoawya | 0:e4c5e6ec922e | 175 | |
mohamedmoawya | 0:e4c5e6ec922e | 176 | /** Returns true if A is held |
mohamedmoawya | 0:e4c5e6ec922e | 177 | * @returns a bool corresponding to A being held |
mohamedmoawya | 0:e4c5e6ec922e | 178 | * |
mohamedmoawya | 0:e4c5e6ec922e | 179 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 180 | bool A_held(); |
mohamedmoawya | 0:e4c5e6ec922e | 181 | |
mohamedmoawya | 0:e4c5e6ec922e | 182 | |
mohamedmoawya | 0:e4c5e6ec922e | 183 | /** Returns true if B has been pressed |
mohamedmoawya | 0:e4c5e6ec922e | 184 | * @returns a bool corresponding to B being pressed |
mohamedmoawya | 0:e4c5e6ec922e | 185 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 186 | bool B_pressed(); |
mohamedmoawya | 0:e4c5e6ec922e | 187 | |
mohamedmoawya | 0:e4c5e6ec922e | 188 | /** Returns true if B is held |
mohamedmoawya | 0:e4c5e6ec922e | 189 | * @returns a bool corresponding to B being held |
mohamedmoawya | 0:e4c5e6ec922e | 190 | * |
mohamedmoawya | 0:e4c5e6ec922e | 191 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 192 | bool B_held(); |
mohamedmoawya | 0:e4c5e6ec922e | 193 | |
mohamedmoawya | 0:e4c5e6ec922e | 194 | /** Returns true if B has been pressed |
mohamedmoawya | 0:e4c5e6ec922e | 195 | * @returns a bool corresponding to B being pressed |
mohamedmoawya | 0:e4c5e6ec922e | 196 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 197 | bool X_pressed(); |
mohamedmoawya | 0:e4c5e6ec922e | 198 | |
mohamedmoawya | 0:e4c5e6ec922e | 199 | /** Returns true if X is held |
mohamedmoawya | 0:e4c5e6ec922e | 200 | * @returns a bool corresponding to X being held |
mohamedmoawya | 0:e4c5e6ec922e | 201 | * |
mohamedmoawya | 0:e4c5e6ec922e | 202 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 203 | bool X_held(); |
mohamedmoawya | 0:e4c5e6ec922e | 204 | |
mohamedmoawya | 0:e4c5e6ec922e | 205 | /** Returns true if Y has been pressed |
mohamedmoawya | 0:e4c5e6ec922e | 206 | * @returns a bool corresponding to Y being pressed |
mohamedmoawya | 0:e4c5e6ec922e | 207 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 208 | bool Y_pressed(); |
mohamedmoawya | 0:e4c5e6ec922e | 209 | |
mohamedmoawya | 0:e4c5e6ec922e | 210 | /** Returns true if Y is held |
mohamedmoawya | 0:e4c5e6ec922e | 211 | * @returns a bool corresponding to Y being held |
mohamedmoawya | 0:e4c5e6ec922e | 212 | * |
mohamedmoawya | 0:e4c5e6ec922e | 213 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 214 | bool Y_held(); |
mohamedmoawya | 0:e4c5e6ec922e | 215 | |
mohamedmoawya | 0:e4c5e6ec922e | 216 | |
mohamedmoawya | 0:e4c5e6ec922e | 217 | /** Returns true if start has been pressed |
mohamedmoawya | 0:e4c5e6ec922e | 218 | * @returns a bool corresponding to start being pressed |
mohamedmoawya | 0:e4c5e6ec922e | 219 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 220 | bool start_pressed(); |
mohamedmoawya | 0:e4c5e6ec922e | 221 | |
mohamedmoawya | 0:e4c5e6ec922e | 222 | /** Returns true if start is held |
mohamedmoawya | 0:e4c5e6ec922e | 223 | * @returns a bool corresponding to start being held |
mohamedmoawya | 0:e4c5e6ec922e | 224 | * |
mohamedmoawya | 0:e4c5e6ec922e | 225 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 226 | bool start_held(); |
mohamedmoawya | 0:e4c5e6ec922e | 227 | |
mohamedmoawya | 0:e4c5e6ec922e | 228 | /** Play a single tone for the specifed duration |
mohamedmoawya | 0:e4c5e6ec922e | 229 | *@param note frequency (in Hz) |
mohamedmoawya | 0:e4c5e6ec922e | 230 | *@param duration (in s) |
mohamedmoawya | 0:e4c5e6ec922e | 231 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 232 | void tone(const float frequency,const float duration); |
mohamedmoawya | 0:e4c5e6ec922e | 233 | |
mohamedmoawya | 0:e4c5e6ec922e | 234 | /** Play a melody |
mohamedmoawya | 0:e4c5e6ec922e | 235 | *@param length of note array |
mohamedmoawya | 0:e4c5e6ec922e | 236 | *@param array of note frequencies (in Hz) - 0 treated as a rest |
mohamedmoawya | 0:e4c5e6ec922e | 237 | *@param array of note durations (4 corresponds to 1/4, 8 is 1/8 etc.) |
mohamedmoawya | 0:e4c5e6ec922e | 238 | *@param beats per minute |
mohamedmoawya | 0:e4c5e6ec922e | 239 | *@param whether to repeat or play just once |
mohamedmoawya | 0:e4c5e6ec922e | 240 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 241 | void play_melody(int length,const int *notes,const int *durations,float bpm,bool repeat); |
mohamedmoawya | 0:e4c5e6ec922e | 242 | |
mohamedmoawya | 0:e4c5e6ec922e | 243 | /** Set the BPM of the melody |
mohamedmoawya | 0:e4c5e6ec922e | 244 | *@param beats per minute |
mohamedmoawya | 0:e4c5e6ec922e | 245 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 246 | void set_bpm(float bpm); |
mohamedmoawya | 0:e4c5e6ec922e | 247 | |
mohamedmoawya | 0:e4c5e6ec922e | 248 | /** Write an analog voltage to the speaker |
mohamedmoawya | 0:e4c5e6ec922e | 249 | *@param voltage in range 0.0 to 1.0 (corresponds 0.0 to 3.3 V) |
mohamedmoawya | 0:e4c5e6ec922e | 250 | */ |
mohamedmoawya | 0:e4c5e6ec922e | 251 | void write_dac(float val); |
mohamedmoawya | 0:e4c5e6ec922e | 252 | |
mohamedmoawya | 0:e4c5e6ec922e | 253 | int random_gen(int upper, int lower); |
mohamedmoawya | 0:e4c5e6ec922e | 254 | |
mohamedmoawya | 0:e4c5e6ec922e | 255 | |
mohamedmoawya | 0:e4c5e6ec922e | 256 | |
mohamedmoawya | 0:e4c5e6ec922e | 257 | |
mohamedmoawya | 0:e4c5e6ec922e | 258 | private: |
mohamedmoawya | 0:e4c5e6ec922e | 259 | |
mohamedmoawya | 0:e4c5e6ec922e | 260 | volatile bool A_fall; |
mohamedmoawya | 0:e4c5e6ec922e | 261 | void A_fall_interrupt(); |
mohamedmoawya | 0:e4c5e6ec922e | 262 | |
mohamedmoawya | 0:e4c5e6ec922e | 263 | volatile bool B_fall; |
mohamedmoawya | 0:e4c5e6ec922e | 264 | void B_fall_interrupt(); |
mohamedmoawya | 0:e4c5e6ec922e | 265 | |
mohamedmoawya | 0:e4c5e6ec922e | 266 | volatile bool X_fall; |
mohamedmoawya | 0:e4c5e6ec922e | 267 | void X_fall_interrupt(); |
mohamedmoawya | 0:e4c5e6ec922e | 268 | |
mohamedmoawya | 0:e4c5e6ec922e | 269 | volatile bool Y_fall; |
mohamedmoawya | 0:e4c5e6ec922e | 270 | void Y_fall_interrupt(); |
mohamedmoawya | 0:e4c5e6ec922e | 271 | |
mohamedmoawya | 0:e4c5e6ec922e | 272 | volatile bool start_fall; |
mohamedmoawya | 0:e4c5e6ec922e | 273 | void start_fall_interrupt(); |
mohamedmoawya | 0:e4c5e6ec922e | 274 | |
mohamedmoawya | 0:e4c5e6ec922e | 275 | // Tone functions |
mohamedmoawya | 0:e4c5e6ec922e | 276 | void ticker_isr(); |
mohamedmoawya | 0:e4c5e6ec922e | 277 | void timeout_isr(); |
mohamedmoawya | 0:e4c5e6ec922e | 278 | void note_timeout_isr(); |
mohamedmoawya | 0:e4c5e6ec922e | 279 | void play_next_note(); |
mohamedmoawya | 0:e4c5e6ec922e | 280 | |
mohamedmoawya | 0:e4c5e6ec922e | 281 | |
mohamedmoawya | 0:e4c5e6ec922e | 282 | |
mohamedmoawya | 0:e4c5e6ec922e | 283 | }; |
mohamedmoawya | 0:e4c5e6ec922e | 284 | |
mohamedmoawya | 0:e4c5e6ec922e | 285 | // Note definitions from Arduino.cc |
mohamedmoawya | 0:e4c5e6ec922e | 286 | #define NOTE_B0 31 |
mohamedmoawya | 0:e4c5e6ec922e | 287 | #define NOTE_C1 33 |
mohamedmoawya | 0:e4c5e6ec922e | 288 | #define NOTE_CS1 35 |
mohamedmoawya | 0:e4c5e6ec922e | 289 | #define NOTE_D1 37 |
mohamedmoawya | 0:e4c5e6ec922e | 290 | #define NOTE_DS1 39 |
mohamedmoawya | 0:e4c5e6ec922e | 291 | #define NOTE_E1 41 |
mohamedmoawya | 0:e4c5e6ec922e | 292 | #define NOTE_F1 44 |
mohamedmoawya | 0:e4c5e6ec922e | 293 | #define NOTE_FS1 46 |
mohamedmoawya | 0:e4c5e6ec922e | 294 | #define NOTE_G1 49 |
mohamedmoawya | 0:e4c5e6ec922e | 295 | #define NOTE_GS1 52 |
mohamedmoawya | 0:e4c5e6ec922e | 296 | #define NOTE_A1 55 |
mohamedmoawya | 0:e4c5e6ec922e | 297 | #define NOTE_AS1 58 |
mohamedmoawya | 0:e4c5e6ec922e | 298 | #define NOTE_B1 62 |
mohamedmoawya | 0:e4c5e6ec922e | 299 | #define NOTE_C2 65 |
mohamedmoawya | 0:e4c5e6ec922e | 300 | #define NOTE_CS2 69 |
mohamedmoawya | 0:e4c5e6ec922e | 301 | #define NOTE_D2 73 |
mohamedmoawya | 0:e4c5e6ec922e | 302 | #define NOTE_DS2 78 |
mohamedmoawya | 0:e4c5e6ec922e | 303 | #define NOTE_E2 82 |
mohamedmoawya | 0:e4c5e6ec922e | 304 | #define NOTE_F2 87 |
mohamedmoawya | 0:e4c5e6ec922e | 305 | #define NOTE_FS2 93 |
mohamedmoawya | 0:e4c5e6ec922e | 306 | #define NOTE_G2 98 |
mohamedmoawya | 0:e4c5e6ec922e | 307 | #define NOTE_GS2 104 |
mohamedmoawya | 0:e4c5e6ec922e | 308 | #define NOTE_A2 110 |
mohamedmoawya | 0:e4c5e6ec922e | 309 | #define NOTE_AS2 117 |
mohamedmoawya | 0:e4c5e6ec922e | 310 | #define NOTE_B2 123 |
mohamedmoawya | 0:e4c5e6ec922e | 311 | #define NOTE_C3 131 |
mohamedmoawya | 0:e4c5e6ec922e | 312 | #define NOTE_CS3 139 |
mohamedmoawya | 0:e4c5e6ec922e | 313 | #define NOTE_D3 147 |
mohamedmoawya | 0:e4c5e6ec922e | 314 | #define NOTE_DS3 156 |
mohamedmoawya | 0:e4c5e6ec922e | 315 | #define NOTE_E3 165 |
mohamedmoawya | 0:e4c5e6ec922e | 316 | #define NOTE_F3 175 |
mohamedmoawya | 0:e4c5e6ec922e | 317 | #define NOTE_FS3 185 |
mohamedmoawya | 0:e4c5e6ec922e | 318 | #define NOTE_G3 196 |
mohamedmoawya | 0:e4c5e6ec922e | 319 | #define NOTE_GS3 208 |
mohamedmoawya | 0:e4c5e6ec922e | 320 | #define NOTE_A3 220 |
mohamedmoawya | 0:e4c5e6ec922e | 321 | #define NOTE_AS3 233 |
mohamedmoawya | 0:e4c5e6ec922e | 322 | #define NOTE_B3 247 |
mohamedmoawya | 0:e4c5e6ec922e | 323 | #define NOTE_C4 262 |
mohamedmoawya | 0:e4c5e6ec922e | 324 | #define NOTE_CS4 277 |
mohamedmoawya | 0:e4c5e6ec922e | 325 | #define NOTE_D4 294 |
mohamedmoawya | 0:e4c5e6ec922e | 326 | #define NOTE_DS4 311 |
mohamedmoawya | 0:e4c5e6ec922e | 327 | #define NOTE_E4 330 |
mohamedmoawya | 0:e4c5e6ec922e | 328 | #define NOTE_F4 349 |
mohamedmoawya | 0:e4c5e6ec922e | 329 | #define NOTE_FS4 370 |
mohamedmoawya | 0:e4c5e6ec922e | 330 | #define NOTE_G4 392 |
mohamedmoawya | 0:e4c5e6ec922e | 331 | #define NOTE_GS4 415 |
mohamedmoawya | 0:e4c5e6ec922e | 332 | #define NOTE_A4 440 |
mohamedmoawya | 0:e4c5e6ec922e | 333 | #define NOTE_AS4 466 |
mohamedmoawya | 0:e4c5e6ec922e | 334 | #define NOTE_B4 494 |
mohamedmoawya | 0:e4c5e6ec922e | 335 | #define NOTE_C5 523 |
mohamedmoawya | 0:e4c5e6ec922e | 336 | #define NOTE_CS5 554 |
mohamedmoawya | 0:e4c5e6ec922e | 337 | #define NOTE_D5 587 |
mohamedmoawya | 0:e4c5e6ec922e | 338 | #define NOTE_DS5 622 |
mohamedmoawya | 0:e4c5e6ec922e | 339 | #define NOTE_E5 659 |
mohamedmoawya | 0:e4c5e6ec922e | 340 | #define NOTE_F5 698 |
mohamedmoawya | 0:e4c5e6ec922e | 341 | #define NOTE_FS5 740 |
mohamedmoawya | 0:e4c5e6ec922e | 342 | #define NOTE_G5 784 |
mohamedmoawya | 0:e4c5e6ec922e | 343 | #define NOTE_GS5 831 |
mohamedmoawya | 0:e4c5e6ec922e | 344 | #define NOTE_A5 880 |
mohamedmoawya | 0:e4c5e6ec922e | 345 | #define NOTE_AS5 932 |
mohamedmoawya | 0:e4c5e6ec922e | 346 | #define NOTE_B5 988 |
mohamedmoawya | 0:e4c5e6ec922e | 347 | #define NOTE_C6 1047 |
mohamedmoawya | 0:e4c5e6ec922e | 348 | #define NOTE_CS6 1109 |
mohamedmoawya | 0:e4c5e6ec922e | 349 | #define NOTE_D6 1175 |
mohamedmoawya | 0:e4c5e6ec922e | 350 | #define NOTE_DS6 1245 |
mohamedmoawya | 0:e4c5e6ec922e | 351 | #define NOTE_E6 1319 |
mohamedmoawya | 0:e4c5e6ec922e | 352 | #define NOTE_F6 1397 |
mohamedmoawya | 0:e4c5e6ec922e | 353 | #define NOTE_FS6 1480 |
mohamedmoawya | 0:e4c5e6ec922e | 354 | #define NOTE_G6 1568 |
mohamedmoawya | 0:e4c5e6ec922e | 355 | #define NOTE_GS6 1661 |
mohamedmoawya | 0:e4c5e6ec922e | 356 | #define NOTE_A6 1760 |
mohamedmoawya | 0:e4c5e6ec922e | 357 | #define NOTE_AS6 1865 |
mohamedmoawya | 0:e4c5e6ec922e | 358 | #define NOTE_B6 1976 |
mohamedmoawya | 0:e4c5e6ec922e | 359 | #define NOTE_C7 2093 |
mohamedmoawya | 0:e4c5e6ec922e | 360 | #define NOTE_CS7 2217 |
mohamedmoawya | 0:e4c5e6ec922e | 361 | #define NOTE_D7 2349 |
mohamedmoawya | 0:e4c5e6ec922e | 362 | #define NOTE_DS7 2489 |
mohamedmoawya | 0:e4c5e6ec922e | 363 | #define NOTE_E7 2637 |
mohamedmoawya | 0:e4c5e6ec922e | 364 | #define NOTE_F7 2794 |
mohamedmoawya | 0:e4c5e6ec922e | 365 | #define NOTE_FS7 2960 |
mohamedmoawya | 0:e4c5e6ec922e | 366 | #define NOTE_G7 3136 |
mohamedmoawya | 0:e4c5e6ec922e | 367 | #define NOTE_GS7 3322 |
mohamedmoawya | 0:e4c5e6ec922e | 368 | #define NOTE_A7 3520 |
mohamedmoawya | 0:e4c5e6ec922e | 369 | #define NOTE_AS7 3729 |
mohamedmoawya | 0:e4c5e6ec922e | 370 | #define NOTE_B7 3951 |
mohamedmoawya | 0:e4c5e6ec922e | 371 | #define NOTE_C8 4186 |
mohamedmoawya | 0:e4c5e6ec922e | 372 | #define NOTE_CS8 4435 |
mohamedmoawya | 0:e4c5e6ec922e | 373 | #define NOTE_D8 4699 |
mohamedmoawya | 0:e4c5e6ec922e | 374 | #define NOTE_DS8 4978 |
mohamedmoawya | 0:e4c5e6ec922e | 375 | |
mohamedmoawya | 0:e4c5e6ec922e | 376 | #endif |