Wall dodging game utilising a joystick and Nokia 5110 LCD display

Dependencies:   N5110 mbed

Committer:
el14moh
Date:
Fri Apr 22 23:29:43 2016 +0000
Revision:
1:26ebbb94cf36
Parent:
0:6b29f9c29a2a
Child:
2:602e9bb053a0
About to attempt to implement invunrability

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el14moh 0:6b29f9c29a2a 1 /* Joystick
el14moh 0:6b29f9c29a2a 2 Max Hamilton
el14moh 0:6b29f9c29a2a 3
el14moh 0:6b29f9c29a2a 4 My project will be designing a game in which the player must avoid a number
el14moh 0:6b29f9c29a2a 5 of obstacles coming from different locations for as long as possible
el14moh 0:6b29f9c29a2a 6
el14moh 0:6b29f9c29a2a 7 Week 19 Code - Initial test of mbed screen and initilisations
el14moh 0:6b29f9c29a2a 8 Week 20 Code - Add code to move a player controlled ball around the screen
el14moh 0:6b29f9c29a2a 9 Week 21 Code - Add code to generate and move an obstacle down the screen
el14moh 0:6b29f9c29a2a 10
el14moh 0:6b29f9c29a2a 11 Week 22 Code - Significant progress over easter holiday
el14moh 0:6b29f9c29a2a 12 - Diagonal directions added to joystick
el14moh 0:6b29f9c29a2a 13 - Collisions implemented. Game over triggers if character hits a wall
el14moh 0:6b29f9c29a2a 14 - Walls/obstacles developed greatly
el14moh 0:6b29f9c29a2a 15 - Obstacle extended into full wall. Wall structs created and walls travel from all sides of the screen
el14moh 0:6b29f9c29a2a 16 - Walls start of appearing from one side of the screen. As time goes on, more will appear from differnt sides, with multiple walls on screen at once
el14moh 0:6b29f9c29a2a 17 - Cooldown added to walls to ensure a new one will not instantly appear from a side that another wall has just travelled to.
el14moh 0:6b29f9c29a2a 18 - visual warning on screen when walls are about to appear from a new direction
el14moh 0:6b29f9c29a2a 19 - Game now keeps track of score and displays it at the end of the game
el14moh 0:6b29f9c29a2a 20 - Intro screen added
el14moh 0:6b29f9c29a2a 21
el14moh 0:6b29f9c29a2a 22 */
el14moh 0:6b29f9c29a2a 23
el14moh 0:6b29f9c29a2a 24 #include "mbed.h"
el14moh 0:6b29f9c29a2a 25 #include "N5110.h"
el14moh 0:6b29f9c29a2a 26 #include "tones.h"
el14moh 0:6b29f9c29a2a 27
el14moh 0:6b29f9c29a2a 28 #define DIRECTION_TOLERANCE 0.05 // tolerance of joystick direction
el14moh 0:6b29f9c29a2a 29 #define PLAYERRADIUS 2 // size of player ball
el14moh 0:6b29f9c29a2a 30 #define GAMESPEED 20 // game timer speed
el14moh 0:6b29f9c29a2a 31 #define JOYSPEED 20 // rate at which the joystick is read
el14moh 0:6b29f9c29a2a 32 #define PI 3.14159265359
el14moh 0:6b29f9c29a2a 33
el14moh 0:6b29f9c29a2a 34 // VCC, SCE, RST, D/C, MOSI, SCLK, LED
el14moh 0:6b29f9c29a2a 35 N5110 lcd (PTD3 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3);
el14moh 0:6b29f9c29a2a 36
el14moh 0:6b29f9c29a2a 37 AnalogIn backlight(PTB2); // pot to control brightness
el14moh 0:6b29f9c29a2a 38 DigitalIn button(PTB3); // joystick button object
el14moh 0:6b29f9c29a2a 39 AnalogIn xPot(PTB11); // joystick x direction object
el14moh 0:6b29f9c29a2a 40 AnalogIn yPot(PTB10); // joystick y direction object
el14moh 0:6b29f9c29a2a 41 DigitalOut buzzer(PTA2); // buzzer object
el14moh 0:6b29f9c29a2a 42
el14moh 0:6b29f9c29a2a 43 Ticker pollJoystick; // timer to regularly read the joystick
el14moh 0:6b29f9c29a2a 44 Ticker game_timer; // timer to regularly update the screen
el14moh 0:6b29f9c29a2a 45 Timer noteTimer; // timer for note tones
el14moh 0:6b29f9c29a2a 46
el14moh 0:6b29f9c29a2a 47 Serial serial(USBTX,USBRX); // Serial for debug
el14moh 0:6b29f9c29a2a 48
el14moh 0:6b29f9c29a2a 49 // create enumerated type (0,1,2,3 etc. for direction)
el14moh 0:6b29f9c29a2a 50 enum DirectionName {
el14moh 0:6b29f9c29a2a 51 UP,
el14moh 0:6b29f9c29a2a 52 DOWN,
el14moh 0:6b29f9c29a2a 53 LEFT,
el14moh 0:6b29f9c29a2a 54 RIGHT,
el14moh 0:6b29f9c29a2a 55 UPRIGHT, // Diagonally up + right
el14moh 0:6b29f9c29a2a 56 UPLEFT, // Diagonally up + left
el14moh 0:6b29f9c29a2a 57 DOWNRIGHT, // Diagonally down + right
el14moh 0:6b29f9c29a2a 58 DOWNLEFT, // Diagonally down + left
el14moh 0:6b29f9c29a2a 59 CENTRE,
el14moh 0:6b29f9c29a2a 60 UNKNOWN
el14moh 0:6b29f9c29a2a 61 };
el14moh 0:6b29f9c29a2a 62
el14moh 0:6b29f9c29a2a 63 typedef struct JoyStick Joystick; // struct for Joystick
el14moh 0:6b29f9c29a2a 64 typedef struct Wall Wall; // struct for Walls
el14moh 0:6b29f9c29a2a 65
el14moh 0:6b29f9c29a2a 66 struct JoyStick {
el14moh 0:6b29f9c29a2a 67 float x; // current x value
el14moh 0:6b29f9c29a2a 68 float x0; // 'centred' x value
el14moh 0:6b29f9c29a2a 69 float y; // current y value
el14moh 0:6b29f9c29a2a 70 float y0; // 'centred' y value
el14moh 0:6b29f9c29a2a 71 int button; // button state (assume pull-down used, so 1 = pressed, 0 = unpressed)
el14moh 0:6b29f9c29a2a 72 DirectionName direction; // current direction
el14moh 0:6b29f9c29a2a 73 };
el14moh 0:6b29f9c29a2a 74
el14moh 0:6b29f9c29a2a 75 struct Wall {
el14moh 0:6b29f9c29a2a 76 int x; // x-coordinate of wall (realtive to centre of the gap)
el14moh 0:6b29f9c29a2a 77 int y; // y-coordinate of wall (relative to centre of the gap)
el14moh 0:6b29f9c29a2a 78 DirectionName direction; // Direction the wall travels in
el14moh 0:6b29f9c29a2a 79 int random; // randomly generated integer to determine when a wall begins to travel
el14moh 0:6b29f9c29a2a 80 int cooldown; // stops a wall respawning before a certain amount of time
el14moh 1:26ebbb94cf36 81 volatile bool moveFlag; // flag to determine if wall is on screen
el14moh 1:26ebbb94cf36 82 volatile bool genFlag; // flag to determine if wall has been generated
el14moh 0:6b29f9c29a2a 83 };
el14moh 0:6b29f9c29a2a 84
el14moh 0:6b29f9c29a2a 85 // struct variable for joystick
el14moh 0:6b29f9c29a2a 86 Joystick joystick;
el14moh 0:6b29f9c29a2a 87 // struct variable for moving walls
el14moh 0:6b29f9c29a2a 88 Wall leftwall;
el14moh 0:6b29f9c29a2a 89 Wall rightwall;
el14moh 0:6b29f9c29a2a 90 Wall downwall;
el14moh 0:6b29f9c29a2a 91 Wall upwall;
el14moh 0:6b29f9c29a2a 92
el14moh 0:6b29f9c29a2a 93 void calibrateJoystick(); // read default positions of the joystick to calibrate later readings
el14moh 0:6b29f9c29a2a 94 void updateJoystick(); // reads direction the joystick has been moved
el14moh 0:6b29f9c29a2a 95 void initDisplay(); // initialises the LCD display
el14moh 0:6b29f9c29a2a 96 void game_timer_isr(); // sets flag for timer interrupt
el14moh 0:6b29f9c29a2a 97 void moveBall(); // reads joystick direction and moves position of the player
el14moh 0:6b29f9c29a2a 98 void moveWall(); // moves walls along the screen
el14moh 0:6b29f9c29a2a 99 void checkCollision(); // checks for any collisions (i.e. player has hit a wall or side of the screen)
el14moh 0:6b29f9c29a2a 100 void updateScreen(); // refreshes the screen, redraws player and walls
el14moh 0:6b29f9c29a2a 101 void warning(); // flashes screen when a new wall is ready to appear
el14moh 0:6b29f9c29a2a 102 void init_serial(); // sets baud rate for serial
el14moh 0:6b29f9c29a2a 103 void debug(); // prints for debug purposes
el14moh 0:6b29f9c29a2a 104
el14moh 0:6b29f9c29a2a 105 float refresh_rate = GAMESPEED; // how often to update display (Hz)
el14moh 0:6b29f9c29a2a 106 float g_dt = 1.0F/refresh_rate; // global to store time step (F makes it a float, gets rid of compiler warning)
el14moh 0:6b29f9c29a2a 107 volatile int g_timer_flag = 0; // flag for timer interrupt
el14moh 0:6b29f9c29a2a 108 int printFlag = 0; // flag for printing
el14moh 1:26ebbb94cf36 109 volatile int game_over_flag = 0; // flag to signal game over
el14moh 0:6b29f9c29a2a 110 int game_start_flag = 0; // flag to start the game
el14moh 0:6b29f9c29a2a 111 int i = 42; // x-coordinate value of player
el14moh 0:6b29f9c29a2a 112 int j = 24; // y-coordinate value of player
el14moh 0:6b29f9c29a2a 113 int counter = 0; // number of times code has looped
el14moh 0:6b29f9c29a2a 114
el14moh 0:6b29f9c29a2a 115
el14moh 0:6b29f9c29a2a 116
el14moh 0:6b29f9c29a2a 117 int main()
el14moh 0:6b29f9c29a2a 118 {
el14moh 0:6b29f9c29a2a 119 init_serial();
el14moh 0:6b29f9c29a2a 120 srand(time(NULL)); // generate seed for random number generation
el14moh 0:6b29f9c29a2a 121 calibrateJoystick();
el14moh 0:6b29f9c29a2a 122 pollJoystick.attach(&updateJoystick,1.0/JOYSPEED); // read joystick (JOYSPEED) times per second
el14moh 0:6b29f9c29a2a 123 initDisplay();
el14moh 0:6b29f9c29a2a 124
el14moh 0:6b29f9c29a2a 125
el14moh 0:6b29f9c29a2a 126 wait (1.0);
el14moh 0:6b29f9c29a2a 127
el14moh 0:6b29f9c29a2a 128 game_timer.attach(&game_timer_isr,g_dt);
el14moh 0:6b29f9c29a2a 129
el14moh 0:6b29f9c29a2a 130 while(1) {
el14moh 0:6b29f9c29a2a 131
el14moh 0:6b29f9c29a2a 132 lcd.printString("Dodgemania",13,2); // Print game title on screen
el14moh 0:6b29f9c29a2a 133 wait (2.5);
el14moh 0:6b29f9c29a2a 134 for (int z=0; z<88; z++) {
el14moh 0:6b29f9c29a2a 135 lcd.drawCircle(z,20,4,1);
el14moh 0:6b29f9c29a2a 136
el14moh 0:6b29f9c29a2a 137 lcd.clearPixel(z-3,16);
el14moh 0:6b29f9c29a2a 138 lcd.clearPixel(z-4,17);
el14moh 0:6b29f9c29a2a 139 lcd.clearPixel(z-4,18);
el14moh 0:6b29f9c29a2a 140 lcd.clearPixel(z-5,19);
el14moh 0:6b29f9c29a2a 141 lcd.clearPixel(z-5,20);
el14moh 0:6b29f9c29a2a 142 lcd.clearPixel(z-5,21);
el14moh 0:6b29f9c29a2a 143 lcd.clearPixel(z-4,22);
el14moh 0:6b29f9c29a2a 144 lcd.clearPixel(z-4,23);
el14moh 0:6b29f9c29a2a 145 lcd.clearPixel(z-3,24);
el14moh 0:6b29f9c29a2a 146 lcd.refresh();
el14moh 0:6b29f9c29a2a 147 wait(0.01);
el14moh 0:6b29f9c29a2a 148 }
el14moh 0:6b29f9c29a2a 149
el14moh 0:6b29f9c29a2a 150 lcd.clear();
el14moh 0:6b29f9c29a2a 151 wait(0.5);
el14moh 0:6b29f9c29a2a 152
el14moh 0:6b29f9c29a2a 153 lcd.inverseMode();
el14moh 0:6b29f9c29a2a 154 wait(0.2);
el14moh 0:6b29f9c29a2a 155 lcd.normalMode();
el14moh 0:6b29f9c29a2a 156
el14moh 0:6b29f9c29a2a 157 lcd.printString("Press button",6,2);
el14moh 0:6b29f9c29a2a 158 lcd.printString("to start",18,3);
el14moh 0:6b29f9c29a2a 159
el14moh 0:6b29f9c29a2a 160 while(game_start_flag == 0) { // replace with interrupt?
el14moh 0:6b29f9c29a2a 161 if(button) {
el14moh 0:6b29f9c29a2a 162 game_start_flag = 1;
el14moh 0:6b29f9c29a2a 163 lcd.clear();
el14moh 0:6b29f9c29a2a 164 wait(0.5);
el14moh 0:6b29f9c29a2a 165 }
el14moh 0:6b29f9c29a2a 166 }
el14moh 0:6b29f9c29a2a 167
el14moh 0:6b29f9c29a2a 168 lcd.inverseMode();
el14moh 0:6b29f9c29a2a 169 wait(0.2);
el14moh 0:6b29f9c29a2a 170 lcd.normalMode();
el14moh 0:6b29f9c29a2a 171
el14moh 0:6b29f9c29a2a 172 // Draw game border
el14moh 0:6b29f9c29a2a 173 lcd.drawLine(2,2,81,2,1);
el14moh 0:6b29f9c29a2a 174 lcd.drawLine(2,2,2,45,1);
el14moh 0:6b29f9c29a2a 175 lcd.drawLine(81,2,81,45,1);
el14moh 0:6b29f9c29a2a 176 lcd.drawLine(2,45,81,45,1);
el14moh 0:6b29f9c29a2a 177
el14moh 0:6b29f9c29a2a 178 lcd.drawLine(0,0,83,0,1);
el14moh 0:6b29f9c29a2a 179 lcd.drawLine(0,0,0,47,1);
el14moh 0:6b29f9c29a2a 180 lcd.drawLine(83,0,83,47,1);
el14moh 0:6b29f9c29a2a 181 lcd.drawLine(0,47,83,47,1);
el14moh 0:6b29f9c29a2a 182
el14moh 0:6b29f9c29a2a 183 lcd.refresh();
el14moh 0:6b29f9c29a2a 184
el14moh 0:6b29f9c29a2a 185 // Countdown
el14moh 0:6b29f9c29a2a 186 wait(0.5);
el14moh 0:6b29f9c29a2a 187 lcd.printString("3",40,2);
el14moh 0:6b29f9c29a2a 188 wait(0.5);
el14moh 0:6b29f9c29a2a 189 lcd.drawRect(10,10,64,28,2);
el14moh 0:6b29f9c29a2a 190 lcd.refresh();
el14moh 0:6b29f9c29a2a 191 wait(0.5);
el14moh 0:6b29f9c29a2a 192 lcd.printString("2",40,2);
el14moh 0:6b29f9c29a2a 193 wait(0.5);
el14moh 0:6b29f9c29a2a 194 lcd.drawRect(10,10,64,28,2);
el14moh 0:6b29f9c29a2a 195 lcd.refresh();
el14moh 0:6b29f9c29a2a 196 wait(0.5);
el14moh 0:6b29f9c29a2a 197 lcd.printString("1",40,2);
el14moh 0:6b29f9c29a2a 198 wait(0.5);
el14moh 0:6b29f9c29a2a 199 lcd.drawRect(10,10,64,28,2);
el14moh 0:6b29f9c29a2a 200 lcd.refresh();
el14moh 0:6b29f9c29a2a 201 wait(0.5);
el14moh 0:6b29f9c29a2a 202 lcd.drawRect(10,10,64,28,2);
el14moh 0:6b29f9c29a2a 203 lcd.refresh();
el14moh 0:6b29f9c29a2a 204 lcd.printString("Go!",36,2);
el14moh 0:6b29f9c29a2a 205 wait(0.5);
el14moh 0:6b29f9c29a2a 206 lcd.drawRect(10,10,64,28,2);
el14moh 0:6b29f9c29a2a 207 lcd.refresh();
el14moh 0:6b29f9c29a2a 208
el14moh 0:6b29f9c29a2a 209
el14moh 0:6b29f9c29a2a 210 leftwall.y = rand() % 27+8;
el14moh 0:6b29f9c29a2a 211 rightwall.y = rand() % 27+8;
el14moh 0:6b29f9c29a2a 212 downwall.x = rand() % 27+8;
el14moh 0:6b29f9c29a2a 213 upwall.x = rand() % 27+8;
el14moh 0:6b29f9c29a2a 214 rightwall.cooldown = 61;
el14moh 0:6b29f9c29a2a 215
el14moh 0:6b29f9c29a2a 216 while (game_over_flag == 0) {
el14moh 0:6b29f9c29a2a 217
el14moh 0:6b29f9c29a2a 218 if ( g_timer_flag ) { // ticker interrupt
el14moh 0:6b29f9c29a2a 219 g_timer_flag = 0; // clear flag
el14moh 0:6b29f9c29a2a 220 moveWall();
el14moh 0:6b29f9c29a2a 221 moveBall();
el14moh 1:26ebbb94cf36 222
el14moh 0:6b29f9c29a2a 223 checkCollision();
el14moh 1:26ebbb94cf36 224
el14moh 0:6b29f9c29a2a 225 updateScreen();
el14moh 0:6b29f9c29a2a 226 warning();
el14moh 0:6b29f9c29a2a 227 debug();
el14moh 0:6b29f9c29a2a 228
el14moh 0:6b29f9c29a2a 229 counter++; // increment counter each cycle (approx. 20 points a second)
el14moh 0:6b29f9c29a2a 230
el14moh 0:6b29f9c29a2a 231 // wall cooldowns increased. N.B these are set to 0 when a wall finishes moving
el14moh 0:6b29f9c29a2a 232 leftwall.cooldown++;
el14moh 0:6b29f9c29a2a 233 rightwall.cooldown++;
el14moh 0:6b29f9c29a2a 234 downwall.cooldown++;
el14moh 0:6b29f9c29a2a 235 upwall.cooldown++;
el14moh 0:6b29f9c29a2a 236 }
el14moh 0:6b29f9c29a2a 237 sleep();
el14moh 0:6b29f9c29a2a 238 }
el14moh 0:6b29f9c29a2a 239
el14moh 0:6b29f9c29a2a 240 lcd.inverseMode();
el14moh 0:6b29f9c29a2a 241 wait(0.1);
el14moh 0:6b29f9c29a2a 242 lcd.normalMode();
el14moh 0:6b29f9c29a2a 243 wait(2.0);
el14moh 0:6b29f9c29a2a 244 lcd.clear();
el14moh 0:6b29f9c29a2a 245 wait(0.2);
el14moh 0:6b29f9c29a2a 246
el14moh 0:6b29f9c29a2a 247 lcd.drawRect(11,5,62,11,0);
el14moh 0:6b29f9c29a2a 248 lcd.printString("Game Over!",14,1);
el14moh 0:6b29f9c29a2a 249 lcd.refresh();
el14moh 0:6b29f9c29a2a 250
el14moh 0:6b29f9c29a2a 251 wait(1.0);
el14moh 0:6b29f9c29a2a 252 lcd.drawRect(11,21,62,21,0);
el14moh 0:6b29f9c29a2a 253 lcd.printString("Score:",14,3);
el14moh 0:6b29f9c29a2a 254 char buffer[14];
el14moh 0:6b29f9c29a2a 255 int length = sprintf(buffer,"%d",counter);
el14moh 0:6b29f9c29a2a 256 if (counter <= 999999999) { // 999999999 is highest number that fits in score display box
el14moh 0:6b29f9c29a2a 257 lcd.printString(buffer,14,4);
el14moh 0:6b29f9c29a2a 258 } else {
el14moh 0:6b29f9c29a2a 259 lcd.printString ("Too High!",14,4); // if score is too large to fit in box (unlikely!)
el14moh 0:6b29f9c29a2a 260 }
el14moh 0:6b29f9c29a2a 261 lcd.refresh();
el14moh 0:6b29f9c29a2a 262
el14moh 0:6b29f9c29a2a 263 wait(5.0);
el14moh 0:6b29f9c29a2a 264 lcd.inverseMode();
el14moh 0:6b29f9c29a2a 265 wait(0.2);
el14moh 0:6b29f9c29a2a 266 lcd.normalMode();
el14moh 0:6b29f9c29a2a 267 lcd.clear();
el14moh 0:6b29f9c29a2a 268
el14moh 0:6b29f9c29a2a 269 return 0;
el14moh 0:6b29f9c29a2a 270 }
el14moh 0:6b29f9c29a2a 271
el14moh 0:6b29f9c29a2a 272 }
el14moh 0:6b29f9c29a2a 273
el14moh 0:6b29f9c29a2a 274 void moveBall() // reads joystick direction and moves position of the player
el14moh 0:6b29f9c29a2a 275 {
el14moh 0:6b29f9c29a2a 276 if (joystick.direction == UP) {
el14moh 0:6b29f9c29a2a 277 j-=1;
el14moh 0:6b29f9c29a2a 278 } else if (joystick.direction == DOWN) {
el14moh 0:6b29f9c29a2a 279 j+=1;
el14moh 0:6b29f9c29a2a 280 } else if (joystick.direction == LEFT) {
el14moh 0:6b29f9c29a2a 281 i-=1;
el14moh 0:6b29f9c29a2a 282 } else if (joystick.direction == RIGHT) {
el14moh 0:6b29f9c29a2a 283 i+=1;
el14moh 0:6b29f9c29a2a 284 } else if (joystick.direction == UPRIGHT) {
el14moh 0:6b29f9c29a2a 285 j-=1;
el14moh 0:6b29f9c29a2a 286 i+=1;
el14moh 0:6b29f9c29a2a 287 } else if (joystick.direction == UPLEFT) {
el14moh 0:6b29f9c29a2a 288 j-=1;
el14moh 0:6b29f9c29a2a 289 i-=1;
el14moh 0:6b29f9c29a2a 290 } else if (joystick.direction == DOWNRIGHT) {
el14moh 0:6b29f9c29a2a 291 j+=1;
el14moh 0:6b29f9c29a2a 292 i+=1;
el14moh 0:6b29f9c29a2a 293 } else if (joystick.direction == DOWNLEFT) {
el14moh 0:6b29f9c29a2a 294 j+=1;
el14moh 0:6b29f9c29a2a 295 i-=1;
el14moh 0:6b29f9c29a2a 296 }
el14moh 0:6b29f9c29a2a 297 }
el14moh 0:6b29f9c29a2a 298
el14moh 0:6b29f9c29a2a 299 void moveWall() // moves walls along the screen
el14moh 0:6b29f9c29a2a 300 {
el14moh 0:6b29f9c29a2a 301 leftwall.random = rand()%20;
el14moh 0:6b29f9c29a2a 302 rightwall.random = rand()%20;
el14moh 0:6b29f9c29a2a 303 downwall.random = rand()%50;
el14moh 0:6b29f9c29a2a 304 upwall.random = rand()%50;
el14moh 0:6b29f9c29a2a 305
el14moh 0:6b29f9c29a2a 306 // LEFT WALL
el14moh 0:6b29f9c29a2a 307 if (leftwall.moveFlag == 1) { // if wall is moving
el14moh 0:6b29f9c29a2a 308 leftwall.x-=1; // move wall left
el14moh 0:6b29f9c29a2a 309 if (leftwall.x<3) { // if wall hits a border
el14moh 0:6b29f9c29a2a 310 leftwall.moveFlag = 0; // stop wall moving
el14moh 0:6b29f9c29a2a 311 leftwall.cooldown = 0; // reset the cooldown for the wall
el14moh 0:6b29f9c29a2a 312 }
el14moh 0:6b29f9c29a2a 313 } else { // if wall has stopped moving
el14moh 0:6b29f9c29a2a 314 if (leftwall.genFlag == 0) { // if a new wall HASN'T been generated
el14moh 0:6b29f9c29a2a 315 leftwall.y = rand() % 27+8; // make new random y-coordinate
el14moh 0:6b29f9c29a2a 316 leftwall.x = 82; // reset x-coordinate to rightmost position
el14moh 0:6b29f9c29a2a 317 leftwall.genFlag = 1; // wall has been generated
el14moh 0:6b29f9c29a2a 318 } else { // if a new wall HAS been generated
el14moh 0:6b29f9c29a2a 319 if (leftwall.cooldown > 80) { // if a new wall hasnt started moving in 4 seconds, force it to move
el14moh 0:6b29f9c29a2a 320 leftwall.moveFlag = 1;
el14moh 0:6b29f9c29a2a 321 leftwall.genFlag = 0;
el14moh 0:6b29f9c29a2a 322 } else if ((leftwall.random == 1)&&(rightwall.cooldown > 60)) { // if wall starts moving again
el14moh 0:6b29f9c29a2a 323 leftwall.moveFlag = 1; // start wall moving
el14moh 0:6b29f9c29a2a 324 leftwall.genFlag = 0; // clear 'wall generated' flag
el14moh 0:6b29f9c29a2a 325 } else { // else if wall has not started moving again
el14moh 0:6b29f9c29a2a 326 leftwall.moveFlag = 0; // wall is stopped
el14moh 0:6b29f9c29a2a 327 }
el14moh 0:6b29f9c29a2a 328 }
el14moh 0:6b29f9c29a2a 329 }
el14moh 0:6b29f9c29a2a 330
el14moh 0:6b29f9c29a2a 331 // RIGHT WALL
el14moh 0:6b29f9c29a2a 332 if (counter > 200) {
el14moh 0:6b29f9c29a2a 333 if (rightwall.moveFlag == 1) {
el14moh 0:6b29f9c29a2a 334 rightwall.x+=1;
el14moh 0:6b29f9c29a2a 335 if (rightwall.x>80) {
el14moh 0:6b29f9c29a2a 336 rightwall.moveFlag = 0;
el14moh 0:6b29f9c29a2a 337 rightwall.cooldown = 0;
el14moh 0:6b29f9c29a2a 338 }
el14moh 0:6b29f9c29a2a 339 } else {
el14moh 0:6b29f9c29a2a 340 if ((rightwall.genFlag == 0)) {
el14moh 0:6b29f9c29a2a 341 rightwall.y = rand() % 27+8;
el14moh 0:6b29f9c29a2a 342 rightwall.x = 1;
el14moh 0:6b29f9c29a2a 343 rightwall.genFlag = 1;
el14moh 0:6b29f9c29a2a 344 } else {
el14moh 0:6b29f9c29a2a 345 if (rightwall.cooldown > 80) {
el14moh 0:6b29f9c29a2a 346 rightwall.moveFlag = 1;
el14moh 0:6b29f9c29a2a 347 rightwall.genFlag = 0;
el14moh 0:6b29f9c29a2a 348 } else if ((rightwall.random == 1) && (leftwall.cooldown > 60)) {
el14moh 0:6b29f9c29a2a 349 rightwall.moveFlag = 1;
el14moh 0:6b29f9c29a2a 350 rightwall.genFlag = 0;
el14moh 0:6b29f9c29a2a 351 } else {
el14moh 0:6b29f9c29a2a 352 rightwall.moveFlag = 0;
el14moh 0:6b29f9c29a2a 353 }
el14moh 0:6b29f9c29a2a 354 }
el14moh 0:6b29f9c29a2a 355 }
el14moh 0:6b29f9c29a2a 356 }
el14moh 0:6b29f9c29a2a 357
el14moh 0:6b29f9c29a2a 358 // DOWN WALL
el14moh 0:6b29f9c29a2a 359 if (counter > 600) {
el14moh 0:6b29f9c29a2a 360 if (downwall.moveFlag == 1) {
el14moh 0:6b29f9c29a2a 361 if (upwall.cooldown > 60) {
el14moh 0:6b29f9c29a2a 362 if (counter % 2 == 1) { // horizontal walls move half the speed of vertical walls
el14moh 0:6b29f9c29a2a 363 downwall.y+=1;
el14moh 0:6b29f9c29a2a 364 }
el14moh 0:6b29f9c29a2a 365 }
el14moh 0:6b29f9c29a2a 366 if (downwall.y>44) {
el14moh 0:6b29f9c29a2a 367 downwall.moveFlag = 0;
el14moh 0:6b29f9c29a2a 368 }
el14moh 0:6b29f9c29a2a 369 } else {
el14moh 0:6b29f9c29a2a 370 if (downwall.genFlag == 0) {
el14moh 0:6b29f9c29a2a 371 downwall.x = rand() % 63+8;
el14moh 0:6b29f9c29a2a 372 downwall.y = 1;
el14moh 0:6b29f9c29a2a 373 downwall.genFlag = 1;
el14moh 0:6b29f9c29a2a 374 } else {
el14moh 0:6b29f9c29a2a 375 if (downwall.cooldown > 80) {
el14moh 0:6b29f9c29a2a 376 downwall.moveFlag = 1;
el14moh 0:6b29f9c29a2a 377 downwall.genFlag = 0;
el14moh 0:6b29f9c29a2a 378 } else if ((downwall.random == 1)&&(upwall.cooldown > 60)) {
el14moh 0:6b29f9c29a2a 379 downwall.moveFlag = 1;
el14moh 0:6b29f9c29a2a 380 downwall.genFlag = 0;
el14moh 0:6b29f9c29a2a 381 } else {
el14moh 0:6b29f9c29a2a 382 downwall.moveFlag = 0;
el14moh 0:6b29f9c29a2a 383 }
el14moh 0:6b29f9c29a2a 384 }
el14moh 0:6b29f9c29a2a 385 }
el14moh 0:6b29f9c29a2a 386 }
el14moh 0:6b29f9c29a2a 387
el14moh 0:6b29f9c29a2a 388 // UP WALL
el14moh 0:6b29f9c29a2a 389 if (counter > 1500) {
el14moh 0:6b29f9c29a2a 390 if (upwall.moveFlag == 1) {
el14moh 0:6b29f9c29a2a 391 if (downwall.cooldown > 60) {
el14moh 0:6b29f9c29a2a 392 if (counter % 2 == 1) { // horizontal walls move half the speed of vertical walls
el14moh 0:6b29f9c29a2a 393 upwall.y-=1;
el14moh 0:6b29f9c29a2a 394 }
el14moh 0:6b29f9c29a2a 395 }
el14moh 0:6b29f9c29a2a 396 if (upwall.y<3) {
el14moh 0:6b29f9c29a2a 397 upwall.moveFlag = 0;
el14moh 0:6b29f9c29a2a 398 }
el14moh 0:6b29f9c29a2a 399 } else {
el14moh 0:6b29f9c29a2a 400 if (upwall.genFlag == 0) {
el14moh 0:6b29f9c29a2a 401 upwall.x = rand() % 63+8;
el14moh 0:6b29f9c29a2a 402 upwall.y = 46;
el14moh 0:6b29f9c29a2a 403 upwall.genFlag = 1;
el14moh 0:6b29f9c29a2a 404 } else {
el14moh 0:6b29f9c29a2a 405 if (upwall.cooldown > 80) {
el14moh 0:6b29f9c29a2a 406 upwall.moveFlag = 1;
el14moh 0:6b29f9c29a2a 407 upwall.genFlag = 0;
el14moh 0:6b29f9c29a2a 408 } else if ((upwall.random == 1)&&(downwall.cooldown > 60)) {
el14moh 0:6b29f9c29a2a 409 upwall.moveFlag = 1;
el14moh 0:6b29f9c29a2a 410 upwall.genFlag = 0;
el14moh 0:6b29f9c29a2a 411 } else {
el14moh 0:6b29f9c29a2a 412 upwall.moveFlag = 0;
el14moh 0:6b29f9c29a2a 413 }
el14moh 0:6b29f9c29a2a 414 }
el14moh 0:6b29f9c29a2a 415 }
el14moh 0:6b29f9c29a2a 416 }
el14moh 0:6b29f9c29a2a 417 }
el14moh 0:6b29f9c29a2a 418
el14moh 0:6b29f9c29a2a 419 void checkCollision() // checks for any collisions (i.e. player has hit a wall or side of the screen)
el14moh 0:6b29f9c29a2a 420 {
el14moh 0:6b29f9c29a2a 421 // if floor
el14moh 0:6b29f9c29a2a 422 if ( j >= 47 - (PLAYERRADIUS+3)) {
el14moh 0:6b29f9c29a2a 423 j = 47 - (PLAYERRADIUS+3);
el14moh 0:6b29f9c29a2a 424 }
el14moh 0:6b29f9c29a2a 425
el14moh 0:6b29f9c29a2a 426 // if roof
el14moh 0:6b29f9c29a2a 427 if ( j <= (PLAYERRADIUS+3)) {
el14moh 0:6b29f9c29a2a 428 j = (PLAYERRADIUS+3);
el14moh 0:6b29f9c29a2a 429 }
el14moh 0:6b29f9c29a2a 430
el14moh 0:6b29f9c29a2a 431 // if right wall
el14moh 0:6b29f9c29a2a 432 if ( i >= 83 - (PLAYERRADIUS+3)) {
el14moh 0:6b29f9c29a2a 433 i = 83 - (PLAYERRADIUS+3);
el14moh 0:6b29f9c29a2a 434 }
el14moh 0:6b29f9c29a2a 435
el14moh 0:6b29f9c29a2a 436 // if left wall
el14moh 0:6b29f9c29a2a 437 if ( i <= (PLAYERRADIUS+3)) {
el14moh 0:6b29f9c29a2a 438 i = (PLAYERRADIUS+3);
el14moh 0:6b29f9c29a2a 439 }
el14moh 0:6b29f9c29a2a 440
el14moh 0:6b29f9c29a2a 441 // LEFT WALL
el14moh 0:6b29f9c29a2a 442 if ((((i - PLAYERRADIUS) <= leftwall.x) && (leftwall.x <= (i + PLAYERRADIUS))) && (j > (leftwall.y+3) || j < (leftwall.y-3))) {
el14moh 0:6b29f9c29a2a 443 game_over_flag = 1;
el14moh 0:6b29f9c29a2a 444 }
el14moh 0:6b29f9c29a2a 445
el14moh 0:6b29f9c29a2a 446 // RIGHT WALL
el14moh 0:6b29f9c29a2a 447 if ((((i - PLAYERRADIUS) <= rightwall.x) && (rightwall.x <= (i + PLAYERRADIUS))) && (j > (rightwall.y+3) || j < (rightwall.y-3))) {
el14moh 0:6b29f9c29a2a 448 game_over_flag = 1;
el14moh 0:6b29f9c29a2a 449 }
el14moh 0:6b29f9c29a2a 450
el14moh 0:6b29f9c29a2a 451 // DOWN WALL
el14moh 0:6b29f9c29a2a 452 if ((((j - PLAYERRADIUS) <= downwall.y) && (downwall.y <= (j - PLAYERRADIUS))) && (i > (downwall.x+9) || i < (downwall.x-9))) { // if player x is 4 or more than wall x, it has missed the gap
el14moh 0:6b29f9c29a2a 453 game_over_flag = 1;
el14moh 0:6b29f9c29a2a 454 }
el14moh 0:6b29f9c29a2a 455
el14moh 0:6b29f9c29a2a 456 // UP WALL
el14moh 0:6b29f9c29a2a 457 if (((j + PLAYERRADIUS) == upwall.y || (j - PLAYERRADIUS) == upwall.y) && (i > (upwall.x+9) || i < (upwall.x-9))) { // if player x is 4 or more than wall x, it has missed the gap
el14moh 0:6b29f9c29a2a 458 game_over_flag = 1;
el14moh 0:6b29f9c29a2a 459 }
el14moh 0:6b29f9c29a2a 460 }
el14moh 0:6b29f9c29a2a 461
el14moh 0:6b29f9c29a2a 462 void updateScreen() // refreshes the screen, redraws player and walls
el14moh 0:6b29f9c29a2a 463 {
el14moh 0:6b29f9c29a2a 464 lcd.clear();
el14moh 0:6b29f9c29a2a 465 lcd.drawCircle(i,j,PLAYERRADIUS,1);
el14moh 0:6b29f9c29a2a 466 lcd.refresh(); // update display
el14moh 0:6b29f9c29a2a 467
el14moh 0:6b29f9c29a2a 468 // draw Border
el14moh 0:6b29f9c29a2a 469 lcd.drawLine(2,2,81,2,1);
el14moh 0:6b29f9c29a2a 470 lcd.drawLine(2,2,2,45,1);
el14moh 0:6b29f9c29a2a 471 lcd.drawLine(81,2,81,45,1);
el14moh 0:6b29f9c29a2a 472 lcd.drawLine(2,45,81,45,1);
el14moh 0:6b29f9c29a2a 473
el14moh 0:6b29f9c29a2a 474 lcd.drawLine(0,0,83,0,1);
el14moh 0:6b29f9c29a2a 475 lcd.drawLine(0,0,0,47,1);
el14moh 0:6b29f9c29a2a 476 lcd.drawLine(83,0,83,47,1);
el14moh 0:6b29f9c29a2a 477 lcd.drawLine(0,47,83,47,1);
el14moh 0:6b29f9c29a2a 478
el14moh 0:6b29f9c29a2a 479 // draw walls
el14moh 0:6b29f9c29a2a 480 // LEFT WALL
el14moh 0:6b29f9c29a2a 481 lcd.drawLine(leftwall.x,leftwall.y+5,leftwall.x,44,1);
el14moh 0:6b29f9c29a2a 482 lcd.drawLine(leftwall.x,leftwall.y-5,leftwall.x,3,1);
el14moh 0:6b29f9c29a2a 483 lcd.drawLine(leftwall.x+1,leftwall.y+5,leftwall.x+1,44,1);
el14moh 0:6b29f9c29a2a 484 lcd.drawLine(leftwall.x+1,leftwall.y-5,leftwall.x+1,3,1);
el14moh 0:6b29f9c29a2a 485
el14moh 0:6b29f9c29a2a 486 // RIGHT WALL
el14moh 0:6b29f9c29a2a 487 if (counter > 200) {
el14moh 0:6b29f9c29a2a 488 lcd.drawLine(rightwall.x,rightwall.y+5,rightwall.x,44,1);
el14moh 0:6b29f9c29a2a 489 lcd.drawLine(rightwall.x,rightwall.y-5,rightwall.x,3,1);
el14moh 0:6b29f9c29a2a 490 lcd.drawLine(rightwall.x-1,rightwall.y+5,rightwall.x-1,44,1);
el14moh 0:6b29f9c29a2a 491 lcd.drawLine(rightwall.x-1,rightwall.y-5,rightwall.x-1,3,1);
el14moh 0:6b29f9c29a2a 492 }
el14moh 0:6b29f9c29a2a 493
el14moh 0:6b29f9c29a2a 494 // DOWN WALL
el14moh 0:6b29f9c29a2a 495 if (counter > 600) {
el14moh 0:6b29f9c29a2a 496 lcd.drawLine(downwall.x+11,downwall.y,80,downwall.y,1);
el14moh 0:6b29f9c29a2a 497 lcd.drawLine(downwall.x-11,downwall.y,3,downwall.y,1);
el14moh 0:6b29f9c29a2a 498 lcd.drawLine(downwall.x+11,downwall.y-1,80,downwall.y-1,1);
el14moh 0:6b29f9c29a2a 499 lcd.drawLine(downwall.x-11,downwall.y-1,3,downwall.y-1,1);
el14moh 0:6b29f9c29a2a 500 }
el14moh 0:6b29f9c29a2a 501
el14moh 0:6b29f9c29a2a 502 // UP WALL
el14moh 0:6b29f9c29a2a 503 if (counter > 1500) {
el14moh 0:6b29f9c29a2a 504 lcd.drawLine(upwall.x+11,upwall.y,80,upwall.y,1);
el14moh 0:6b29f9c29a2a 505 lcd.drawLine(upwall.x-11,upwall.y,3,upwall.y,1);
el14moh 0:6b29f9c29a2a 506 lcd.drawLine(upwall.x+11,upwall.y+1,80,upwall.y+1,1);
el14moh 0:6b29f9c29a2a 507 lcd.drawLine(upwall.x-11,upwall.y+1,3,upwall.y+1,1);
el14moh 0:6b29f9c29a2a 508 }
el14moh 0:6b29f9c29a2a 509
el14moh 0:6b29f9c29a2a 510 lcd.refresh();
el14moh 0:6b29f9c29a2a 511 }
el14moh 0:6b29f9c29a2a 512
el14moh 0:6b29f9c29a2a 513 void warning ()
el14moh 0:6b29f9c29a2a 514 {
el14moh 0:6b29f9c29a2a 515 if (counter == 170) {
el14moh 0:6b29f9c29a2a 516 lcd.inverseMode();
el14moh 0:6b29f9c29a2a 517 } else if (counter == 570) {
el14moh 0:6b29f9c29a2a 518 lcd.inverseMode();
el14moh 0:6b29f9c29a2a 519 } else if (counter == 1470) {
el14moh 0:6b29f9c29a2a 520 lcd.inverseMode();
el14moh 0:6b29f9c29a2a 521 } else {
el14moh 0:6b29f9c29a2a 522 lcd.normalMode();
el14moh 0:6b29f9c29a2a 523 }
el14moh 0:6b29f9c29a2a 524 }
el14moh 0:6b29f9c29a2a 525
el14moh 0:6b29f9c29a2a 526 void game_timer_isr() // sets flag for timer interrupt
el14moh 0:6b29f9c29a2a 527 {
el14moh 0:6b29f9c29a2a 528 g_timer_flag = 1;
el14moh 0:6b29f9c29a2a 529 }
el14moh 0:6b29f9c29a2a 530
el14moh 0:6b29f9c29a2a 531 void initDisplay() // initialises the LCD display
el14moh 0:6b29f9c29a2a 532 {
el14moh 0:6b29f9c29a2a 533 lcd.init();
el14moh 0:6b29f9c29a2a 534 lcd.normalMode();
el14moh 0:6b29f9c29a2a 535 lcd.setBrightness(1.0F-backlight); // brightness pot on PCB is soldered in the wrong direction, (1.0F-backlight) inverts the reading
el14moh 0:6b29f9c29a2a 536 }
el14moh 0:6b29f9c29a2a 537
el14moh 0:6b29f9c29a2a 538 void calibrateJoystick() // read default positions of the joystick to calibrate later readings
el14moh 0:6b29f9c29a2a 539 {
el14moh 0:6b29f9c29a2a 540 button.mode(PullDown);
el14moh 0:6b29f9c29a2a 541 // must not move during calibration
el14moh 0:6b29f9c29a2a 542 joystick.x0 = xPot; // initial positions in the range 0.0 to 1.0 (0.5 if centred exactly)
el14moh 0:6b29f9c29a2a 543 joystick.y0 = yPot;
el14moh 0:6b29f9c29a2a 544 }
el14moh 0:6b29f9c29a2a 545 void updateJoystick() // reads direction the joystick has been moved
el14moh 0:6b29f9c29a2a 546 {
el14moh 0:6b29f9c29a2a 547 // read current joystick values relative to calibrated values (in range -0.5 to 0.5, 0.0 is centred)
el14moh 0:6b29f9c29a2a 548 joystick.x = xPot - joystick.x0;
el14moh 0:6b29f9c29a2a 549 joystick.y = yPot - joystick.y0;
el14moh 0:6b29f9c29a2a 550 // read button state
el14moh 0:6b29f9c29a2a 551 joystick.button = button;
el14moh 0:6b29f9c29a2a 552
el14moh 0:6b29f9c29a2a 553 // calculate direction depending on x,y values
el14moh 0:6b29f9c29a2a 554 // tolerance allows a little lee-way in case joystick not exactly in the stated direction
el14moh 0:6b29f9c29a2a 555 if ( fabs(joystick.y) < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
el14moh 0:6b29f9c29a2a 556 joystick.direction = CENTRE;
el14moh 0:6b29f9c29a2a 557 } else if ( joystick.y > DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
el14moh 0:6b29f9c29a2a 558 joystick.direction = UP;
el14moh 0:6b29f9c29a2a 559 } else if ( joystick.y < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) {
el14moh 0:6b29f9c29a2a 560 joystick.direction = DOWN;
el14moh 0:6b29f9c29a2a 561 } else if ( joystick.x > DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) {
el14moh 0:6b29f9c29a2a 562 joystick.direction = LEFT;
el14moh 0:6b29f9c29a2a 563 } else if ( joystick.x < DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) {
el14moh 0:6b29f9c29a2a 564 joystick.direction = RIGHT;
el14moh 0:6b29f9c29a2a 565 } else if ( joystick.y > DIRECTION_TOLERANCE && joystick.x > DIRECTION_TOLERANCE) {
el14moh 0:6b29f9c29a2a 566 joystick.direction = UPLEFT;
el14moh 0:6b29f9c29a2a 567 } else if ( joystick.y > DIRECTION_TOLERANCE && joystick.x < DIRECTION_TOLERANCE) {
el14moh 0:6b29f9c29a2a 568 joystick.direction = UPRIGHT;
el14moh 0:6b29f9c29a2a 569 } else if ( joystick.x > DIRECTION_TOLERANCE && joystick.y < DIRECTION_TOLERANCE) {
el14moh 0:6b29f9c29a2a 570 joystick.direction = DOWNLEFT;
el14moh 0:6b29f9c29a2a 571 } else if ( joystick.x < DIRECTION_TOLERANCE && joystick.y < DIRECTION_TOLERANCE) {
el14moh 0:6b29f9c29a2a 572 joystick.direction = DOWNRIGHT;
el14moh 0:6b29f9c29a2a 573 }
el14moh 0:6b29f9c29a2a 574
el14moh 0:6b29f9c29a2a 575 else {
el14moh 0:6b29f9c29a2a 576 joystick.direction = UNKNOWN;
el14moh 0:6b29f9c29a2a 577 }
el14moh 0:6b29f9c29a2a 578
el14moh 0:6b29f9c29a2a 579
el14moh 0:6b29f9c29a2a 580 printFlag = 1; // set flag for printing
el14moh 0:6b29f9c29a2a 581 }
el14moh 0:6b29f9c29a2a 582
el14moh 0:6b29f9c29a2a 583 void debug() // prints for debug purposes
el14moh 0:6b29f9c29a2a 584 {
el14moh 0:6b29f9c29a2a 585 if (printFlag) { // if flag set, clear flag and print joystick values to serial port
el14moh 0:6b29f9c29a2a 586 printFlag = 0;
el14moh 0:6b29f9c29a2a 587 /*
el14moh 0:6b29f9c29a2a 588 if (joystick.direction == UP)
el14moh 0:6b29f9c29a2a 589 serial.printf(" UP\n");
el14moh 0:6b29f9c29a2a 590 if (joystick.direction == DOWN)
el14moh 0:6b29f9c29a2a 591 serial.printf(" DOWN\n");
el14moh 0:6b29f9c29a2a 592 if (joystick.direction == LEFT)
el14moh 0:6b29f9c29a2a 593 serial.printf(" LEFT\n");
el14moh 0:6b29f9c29a2a 594 if (joystick.direction == RIGHT)
el14moh 0:6b29f9c29a2a 595 serial.printf(" RIGHT\n");
el14moh 0:6b29f9c29a2a 596 if (joystick.direction == UPRIGHT)
el14moh 0:6b29f9c29a2a 597 serial.printf(" UPRIGHT\n"); // Diagonally up + right
el14moh 0:6b29f9c29a2a 598 if (joystick.direction == UPLEFT)
el14moh 0:6b29f9c29a2a 599 serial.printf(" UPLEFT\n"); // Diagonally up + left
el14moh 0:6b29f9c29a2a 600 if (joystick.direction == DOWNRIGHT)
el14moh 0:6b29f9c29a2a 601 serial.printf(" DOWNRIGHT\n"); // Diagonally down + right
el14moh 0:6b29f9c29a2a 602 if (joystick.direction == DOWNLEFT)
el14moh 0:6b29f9c29a2a 603 serial.printf(" DOWNLEFT\n"); // Diagonally down + left
el14moh 0:6b29f9c29a2a 604 if (joystick.direction == CENTRE)
el14moh 0:6b29f9c29a2a 605 serial.printf(" CENTRE\n");
el14moh 0:6b29f9c29a2a 606 if (joystick.direction == UNKNOWN)
el14moh 0:6b29f9c29a2a 607 serial.printf(" Unsupported direction\n");
el14moh 0:6b29f9c29a2a 608 */
el14moh 0:6b29f9c29a2a 609 serial.printf("Left-wall Cooldown = %d \n",leftwall.cooldown);
el14moh 0:6b29f9c29a2a 610 serial.printf("Right-wall Cooldown = %d \n",rightwall.cooldown);
el14moh 0:6b29f9c29a2a 611 serial.printf("counter = %d \n",counter);
el14moh 0:6b29f9c29a2a 612
el14moh 0:6b29f9c29a2a 613 }
el14moh 0:6b29f9c29a2a 614 }
el14moh 0:6b29f9c29a2a 615
el14moh 0:6b29f9c29a2a 616 void init_serial() // sets baud rate for serial
el14moh 0:6b29f9c29a2a 617 {
el14moh 0:6b29f9c29a2a 618 // set to highest baud - ensure terminal software matches
el14moh 0:6b29f9c29a2a 619 serial.baud(115200);
el14moh 0:6b29f9c29a2a 620 }
el14moh 0:6b29f9c29a2a 621