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.
Dependencies: Joystick N5110 SDFileSystem beep fsmMenu mbed
Fork of SnakeProjectRev1 by
Diff: main.cpp
- Revision:
- 16:68b9460d4c76
- Parent:
- 15:a5590211888c
- Child:
- 17:4e6f0f7f22fb
--- a/main.cpp Wed May 04 12:33:52 2016 +0000 +++ b/main.cpp Wed May 04 15:16:12 2016 +0000 @@ -26,11 +26,13 @@ Ticker pollJoystick; Ticker gameTicker; -volatile int game_timer_flag = 0; + FILE *fp; // this is our file pointer void timer_isr(); +void rb_isr(); +void lb_isr(); int main() { @@ -44,14 +46,76 @@ lcd.init(); //snakeIntro(); //hardWall(); - wrapAround(); - generateFood(); - gamePlaying = true; - initSnakeTail(); + //wrapAround(); + //generateFood(); + gamePlaying = false; + //initSnakeTail(); button.rise(&buttonISR); gameTicker.attach(&timer_isr,0.1); + RB.mode(PullDown); + LB.mode(PullDown); + RB.rise(&rb_isr); + LB.rise(&lb_isr); + + + while(1) { + + lcd.printString("Classic",0,1); + lcd.printString("Infinite",0,3); + lcd.printString("Hard Map",0,5); + + if (rb_flag == 1) { + rb_flag = 0; + gamePlaying = true; + break; + } + + // check if flag i.e. interrupt has occured + if (printFlag ==1) { + printFlag = 0; // if it has, clear the flag - /* while(gamePlaying == true) { + // swap direction when button has been pressed + // (could just use ! but want this to be explicit to aid understanding) + if (joystick.direction == CENTRE) { + serial.printf(" CENTRE\n"); + menuDirection = menuSTOP; + } + else if (joystick.direction == UP) { + serial.printf(" UP\n"); + menuDirection = menuUP; + buzzer.beep(2000,0.2); + } + else if (joystick.direction == DOWN) { + serial.printf(" DOWN\n"); + menuDirection = menuDOWN; + buzzer.beep(2000,0.2); + } + } + + + menuFSM(); + + + wait(0.2); // small delay + if (state ==0) { + lcd.clear(); + lcd.printString("*",70,1); + gameType = classicMode; + } + else if (state ==1) { + lcd.clear(); + lcd.printString("*",70,3); + gameType = infiniteMode; + } + else if (state ==2) { + lcd.clear(); + lcd.printString("*",70,5); + gameType = hardMode; + } + + } + + while(gamePlaying == true) { lcd.setBrightness(1-pot); // turn pot right for brightness @@ -71,7 +135,7 @@ moveSnake(); } sleep(); // put the MCU to sleep until an interrupt wakes it up - } */ + } } @@ -266,31 +330,6 @@ void specialMap() { - for (int i=0; i<21; i++) { // top/bottom left x line - lcd.setPixel(i,0); - lcd.setPixel(i,47); - lcd.refresh(); - } - for (int i=63; i<84; i++) { // top/bottom right x line - lcd.setPixel(i,0); - lcd.setPixel(i,47); - lcd.refresh(); - } - for (int i=37; i<47; i++) { // top/bottom middle x line - lcd.setPixel(i,0); - lcd.setPixel(i,47); - lcd.refresh(); - } - for (int j=0; j<17; j++) { // left/right top y line - lcd.setPixel(0,j); - lcd.setPixel(83,j); - lcd.refresh(); - } - for (int j=29; j<48; j++) { // left/right bottom y line - lcd.setPixel(0,j); - lcd.setPixel(83,j); - lcd.refresh(); - } for (int i=41; i<43; i++) { // vertical cross line for (int j=14; j<34; j++) { lcd.setPixel(i,j); @@ -410,4 +449,14 @@ void timer_isr() { game_timer_flag = 1; +} + +void rb_isr() +{ +rb_flag = 1; +} + +void lb_isr() +{ +lb_flag = 1; } \ No newline at end of file