Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
main.cpp
- Committer:
- JamesCummins
- Date:
- 2019-04-17
- Revision:
- 19:deddb013a8e8
- Parent:
- 18:08046153e6ad
- Child:
- 20:4a39a1a2be51
File content as of revision 19:deddb013a8e8:
/* ELEC2645 Embedded Systems Project School of Electronic & Electrical Engineering University of Leeds Name: James Nathan Cummins Username: el17jnc Student ID Number: 201096364 Date: 22/03/19 */ #include "Gamepad.h" #include "mbed.h" #include "N5110.h" #include "GameEngine.h" #define RADIUS 3 //Objects Gamepad gamepad; N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); GameEngine engine; AnalogIn randnoise(PTB0); FXOS8700CQ accelerometer(I2C_SDA,I2C_SCL); //Methods void startscreen(); StartOption menu(); void init(); void print_start_menu(int output); ////////////////Main Function///////////////// int main(){ int fps = 15; init(); startscreen(); while(1){ StartOption choice_selected = menu(); if(choice_selected == CLASSIC){ engine.classic_mode(accelerometer, gamepad, lcd, fps);} if(choice_selected == BRICKBREAKER){ engine.brickbreaker_mode(accelerometer, gamepad, lcd, randnoise, fps);} if(choice_selected == OPTIONS){ engine.options_menu(gamepad, lcd);} } } //////////////Start up functions/////////////////// void init(){ gamepad.init(); lcd.init(); lcd.setContrast(0.55); engine.init(RADIUS); accelerometer.init(); wait(1); } void startscreen() { lcd.clear(); char gamename[] = {'L', 'A', 'B', 'Y', 'R', 'I', 'N', 'T', 'H', ' ', ' ', '\0'}; int i = 0; for(int a = 0; a < 35; a++){ lcd.clear(); lcd.drawCircle(24+2*a, 21, 3, FILL_BLACK); for (i = 0; i < a/3; i++) { lcd.printChar(gamename[i], 15+i*6, 2); lcd.refresh(); } wait_ms(50); } lcd.printString("Press start", 9, 4); lcd.printString("to play >", 15, 5); lcd.refresh(); bool advance = false; while (!advance){ if (gamepad.check_event(gamepad.START_PRESSED)){ lcd.clear(); lcd.refresh(); advance = true; } else { advance = false; } } } StartOption menu(){ StartSelection fsm[3] = { {0,{OPTIONS,BRICKBREAKER,CLASSIC}}, {2,{CLASSIC,OPTIONS,BRICKBREAKER}}, {4,{BRICKBREAKER,CLASSIC,OPTIONS}} }; StartOption state = CLASSIC; //start with the arrow on the top option int next = 2; //next_state = 2 so that by default it doesn't change arrow position while(!(gamepad.get_direction() == E)){ //select choice by pushing joystick to the right state = fsm[state].next_state[next]; lcd.clear(); if(gamepad.get_direction() == N){ next = 0;} else if(gamepad.get_direction() == S){ next = 1;} else {next = 2;} print_start_menu(fsm[state].output); lcd.refresh(); wait(0.25); } lcd.clear(); lcd.refresh(); return state; } void print_start_menu(int output){ lcd.printString(">", 0, output); lcd.printString("Classic", 36, 0); lcd.printString("BrickBreak", 18, 2); lcd.printString("Options", 36, 4); lcd.printString("(Joy R>>)", 30, 5); }