A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.
Dependencies: ConfigFile N5110 PowerControl beep mbed
Revision 1:352c50e88ffa, committed 2015-04-13
- Comitter:
- el13drt
- Date:
- Mon Apr 13 02:34:03 2015 +0000
- Parent:
- 0:a8bc3aac5f69
- Child:
- 2:8fac5562ed1e
- Commit message:
- post menu
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Mon Apr 13 01:34:15 2015 +0000 +++ b/main.cpp Mon Apr 13 02:34:03 2015 +0000 @@ -58,6 +58,7 @@ // timer to regularly read the joystick Ticker pollJoystick; + // Serial for debug Serial serial(USBTX,USBRX); @@ -359,7 +360,7 @@ int main() { //////// set initial values - configurate joystick ///////////////////////////////// - + // initialize random seed: srand (time(NULL)); @@ -376,42 +377,51 @@ calibrateJoystick(); // get centred values of joystick pollJoystick.attach(&updateJoystick,1.0/10.0); // read joystick 10 times per second - /////// initiate game ////////////////////////////////////////////////////////////// - + /////// initiate main menu ////////////////////////////////////////////////////////////// + lcd.init();//initialise screen welcome();//welcome screen lcd.clear();//clear pixels mainMenu();//menu screen - wait (3.0); - lcd.clear(); + // backGround();//display background + + /////// Menu Selection Loop //////////////////////////////////////////////////////////// + + int option = 0; + + while(1) { + + if (printFlag) { // if flag set, clear flag and print joystick values to serial port + printFlag = 0; + serial.printf("x = %f y = %f button = %d ",joystick.x,joystick.y,joystick.button); - backGround();//display background - - /////// Menu Selection //////////////////////////////////////////////////////////// - - int option = 0; - - // Option up - if (joystick.direction == UP) { - serial.printf(" UP\n"); - option = option++; + // Option up + if (joystick.direction == LEFT) { + serial.printf(" UP\n"); + option = option++; + if (option > 1)option = 1; + } + + // Option down + if (joystick.direction == RIGHT) { + serial.printf(" DOWN\n"); + option = option--; + if (option < 0)option = 0; + } + + // 'Play Game' option + if (option == 0) { + lcd.printString("Play Game",3,4); + } + // 'Options' option + if (option == 1) { + lcd.printString(" Options ",3,4); + } + + } } - - // Option down - if (joystick.direction == DOWN) { - serial.printf(" DOWN\n"); - option = option--; - } - - if (option == 0){ - //present options - lcd.printString("Play Game",3,4); - } - if (option == 1){ - lcd.printString("options",3,4); - } - + // while(1) { // // pixelNinja();