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-11
- Revision:
- 11:2cf0d4ce8677
- Parent:
- 10:40c77d69e83c
- Child:
- 12:9982239b7906
File content as of revision 11:2cf0d4ce8677:
/* 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" //Objects Gamepad gamepad; N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); GameEngine engine; AnalogIn randnoise(PTB0); //Methods void startscreen(); int menu(); ////////////////Main Function////////////// int main(){ int fps = 10; init(); startscreen(); int choice_selected = menu(); if(choice_selected == 0){ engine.classic(accelerometer, fps);} if(choice_selected == 1){ engine.brickbreaker(accelerometer, fps);} if(choice_selected == 2){ engine.options_menu(fps);} } //////////////Start up functions/////////////////// void init(){ gamepad.init(); lcd.init(); lcd.setContrast(0.55); engine.init(3); 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; } } } int menu(){ struct Selection{ int output; int next_state[3]; }; Selection fsm[3] = { {0,{2,1,0}}, {2,{0,2,1}}, {4,{1,0,2}} }; int state = 0; //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)){ 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;} lcd.printString(">", 0, fsm[state].output); lcd.printString("Classic", 36, 0); lcd.printString("BrickBreak", 18, 2); lcd.printString("Options", 36, 4); lcd.printString("(Joy R>>)", 30, 5); lcd.refresh(); wait(0.25); } lcd.clear(); lcd.refresh(); return state; }