This is test version of Pokemongo game. ELEC 2645 final project.

Dependencies:   Tone

Committer:
shalwego
Date:
Thu Apr 15 15:35:12 2021 +0000
Revision:
0:819c2d6a69ac
Issue about music playing

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shalwego 0:819c2d6a69ac 1 #ifndef JOYSTICK_H
shalwego 0:819c2d6a69ac 2 #define JOYSTICK_H
shalwego 0:819c2d6a69ac 3
shalwego 0:819c2d6a69ac 4 #include "mbed.h"
shalwego 0:819c2d6a69ac 5 #include "Utils.h"
shalwego 0:819c2d6a69ac 6
shalwego 0:819c2d6a69ac 7 // this value can be tuned to alter tolerance of joystick movement
shalwego 0:819c2d6a69ac 8 #define TOL 0.1f
shalwego 0:819c2d6a69ac 9 #define RAD2DEG 57.2957795131f
shalwego 0:819c2d6a69ac 10
shalwego 0:819c2d6a69ac 11
shalwego 0:819c2d6a69ac 12
shalwego 0:819c2d6a69ac 13 /** Joystick Class
shalwego 0:819c2d6a69ac 14 @author Dr Craig A. Evans, University of Leeds
shalwego 0:819c2d6a69ac 15 @brief Library for interfacing with analogue joystick
shalwego 0:819c2d6a69ac 16
shalwego 0:819c2d6a69ac 17 Example:
shalwego 0:819c2d6a69ac 18
shalwego 0:819c2d6a69ac 19 @code
shalwego 0:819c2d6a69ac 20
shalwego 0:819c2d6a69ac 21 #include "mbed.h"
shalwego 0:819c2d6a69ac 22 #include "Joystick.h"
shalwego 0:819c2d6a69ac 23
shalwego 0:819c2d6a69ac 24 // y x button
shalwego 0:819c2d6a69ac 25 Joystick joystick(PTB11,PTB10);
shalwego 0:819c2d6a69ac 26
shalwego 0:819c2d6a69ac 27 int main() {
shalwego 0:819c2d6a69ac 28
shalwego 0:819c2d6a69ac 29 joystick.init();
shalwego 0:819c2d6a69ac 30
shalwego 0:819c2d6a69ac 31 while(1) {
shalwego 0:819c2d6a69ac 32
shalwego 0:819c2d6a69ac 33 Vector2D coord = joystick.get_coord();
shalwego 0:819c2d6a69ac 34 printf("Coord = %f,%f\n",coord.x,coord.y);
shalwego 0:819c2d6a69ac 35
shalwego 0:819c2d6a69ac 36 Vector2D mapped_coord = joystick.get_mapped_coord();
shalwego 0:819c2d6a69ac 37 printf("Mapped coord = %f,%f\n",mapped_coord.x,mapped_coord.y);
shalwego 0:819c2d6a69ac 38
shalwego 0:819c2d6a69ac 39 float mag = joystick.get_mag();
shalwego 0:819c2d6a69ac 40 float angle = joystick.get_angle();
shalwego 0:819c2d6a69ac 41 printf("Mag = %f Angle = %f\n",mag,angle);
shalwego 0:819c2d6a69ac 42
shalwego 0:819c2d6a69ac 43 Direction d = joystick.get_direction();
shalwego 0:819c2d6a69ac 44 printf("Direction = %i\n",d);
shalwego 0:819c2d6a69ac 45
shalwego 0:819c2d6a69ac 46
shalwego 0:819c2d6a69ac 47 wait(0.5);
shalwego 0:819c2d6a69ac 48 }
shalwego 0:819c2d6a69ac 49
shalwego 0:819c2d6a69ac 50
shalwego 0:819c2d6a69ac 51 }
shalwego 0:819c2d6a69ac 52
shalwego 0:819c2d6a69ac 53 * @endcode
shalwego 0:819c2d6a69ac 54 */
shalwego 0:819c2d6a69ac 55 class Joystick
shalwego 0:819c2d6a69ac 56 {
shalwego 0:819c2d6a69ac 57 public:
shalwego 0:819c2d6a69ac 58
shalwego 0:819c2d6a69ac 59 // y-pot x-pot
shalwego 0:819c2d6a69ac 60 Joystick(PinName vertPin,PinName horizPin);
shalwego 0:819c2d6a69ac 61
shalwego 0:819c2d6a69ac 62 void init(); // needs to be called at start with joystick centred
shalwego 0:819c2d6a69ac 63 float get_mag(); // polar
shalwego 0:819c2d6a69ac 64 float get_angle(); // polar
shalwego 0:819c2d6a69ac 65 Vector2D get_coord(); // cartesian co-ordinates x,y
shalwego 0:819c2d6a69ac 66 Vector2D get_mapped_coord(); // x,y mapped to circle
shalwego 0:819c2d6a69ac 67 Direction get_direction(); // N,NE,E,SE etc.
shalwego 0:819c2d6a69ac 68 Polar get_polar(); // mag and angle in struct form
shalwego 0:819c2d6a69ac 69
shalwego 0:819c2d6a69ac 70 private:
shalwego 0:819c2d6a69ac 71
shalwego 0:819c2d6a69ac 72 AnalogIn *vert;
shalwego 0:819c2d6a69ac 73 AnalogIn *horiz;
shalwego 0:819c2d6a69ac 74
shalwego 0:819c2d6a69ac 75 // centred x,y values
shalwego 0:819c2d6a69ac 76 float _x0;
shalwego 0:819c2d6a69ac 77 float _y0;
shalwego 0:819c2d6a69ac 78
shalwego 0:819c2d6a69ac 79 };
shalwego 0:819c2d6a69ac 80
shalwego 0:819c2d6a69ac 81 #endif