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.
Diff: main.cpp
- Revision:
- 7:6eb9cade57ab
- Parent:
- 6:952ac12c7f00
- Child:
- 8:4e306b16a941
--- a/main.cpp Sun Apr 07 10:36:53 2019 +0000 +++ b/main.cpp Mon Apr 08 12:40:42 2019 +0000 @@ -14,17 +14,18 @@ Gamepad gamepad; N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); -bool startmenu(); +void startscreen(); +int menu(); int main(){ gamepad.init(); lcd.init(); wait(1); - bool cont = startmenu(); - + startscreen(); + int choice_selected = menu(); } -bool startmenu() { +void startscreen() { lcd.clear(); char gamename[] = {'L', 'A', 'B', 'Y', 'R', 'I', 'N', 'T', 'H', ' ', ' ', '\0'}; int i = 0; @@ -35,7 +36,7 @@ lcd.printChar(gamename[i], 15+i*6, 2); lcd.refresh(); } - wait(0.05); + wait_ms(50); } lcd.printString("Press start", 9, 4); lcd.printString("to play >", 15, 5); @@ -49,5 +50,37 @@ } else { advance = false; } } - return advance; } + +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.check_event(gamepad.A_PRESSED)){ + 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("(Click A)", 30, 5); + lcd.refresh(); + wait(0.25); + } + lcd.clear(); + lcd.refresh(); + return state; +} \ No newline at end of file