A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.
Dependencies: ConfigFile N5110 PowerControl beep mbed
Diff: main.cpp
- Revision:
- 66:d5174aa5839d
- Parent:
- 65:c5dad703f752
- Child:
- 67:3574ddf58be3
--- a/main.cpp Fri May 08 05:13:38 2015 +0000 +++ b/main.cpp Fri May 08 06:15:23 2015 +0000 @@ -115,6 +115,7 @@ { if(buttonA == 1) { buttonFlagA = 1; + lcd.setBrightness(1.0); serial.printf("flagA set\n"); } } @@ -124,6 +125,7 @@ { if(buttonB == 1) { buttonFlagB = 1; + lcd.setBrightness(1.0); serial.printf("flagB set\n"); } } @@ -804,6 +806,7 @@ refreshCursor2(); refreshCursor3(); if(buttonFlagA) { //select easy + //rightness(1.0); buttonFlagA = 0; fall = 1; } @@ -815,6 +818,7 @@ refreshCursor3(); if(buttonFlagA) { //select normal + //rightness(1.0); buttonFlagA = 0; fall = 2; } @@ -826,6 +830,7 @@ refreshCursor2(); if(buttonFlagA) { //select difficult + //rightness(1.0); buttonFlagA = 0; fall = 3; } @@ -882,6 +887,7 @@ refreshCursor3(); if(buttonFlagA) { + //rightness(1.0); buttonFlagA =0; FX = 0; serial.printf("FX = %d\n",FX); @@ -894,6 +900,7 @@ refreshCursor2(); if(buttonFlagA) { + //rightness(1.0); buttonFlagA =0; FX = 1; serial.printf("FX = %d\n",FX); @@ -919,6 +926,7 @@ void newScore() { if(score >= highScore3) {//entry condition + //rightness(1.0); buttonFlagA = 0;//reset flags buttonFlagB = 0; lcd.clear();//clears screen @@ -1000,6 +1008,7 @@ lcd.printChar(z,52,2); } if(buttonFlagA) { + //rightness(1.0); actionButtons(); buttonFlagA = 0; buttonFlagB = 0; @@ -1114,6 +1123,7 @@ //Exit Menu (Back button pressed)/// if(buttonFlagB) { + //rightness(1.0); buttonFlagB = 0;//reset flags buttonFlagA = 0; actionButtons(); @@ -1124,6 +1134,7 @@ //'exit' option YES if((buttonFlagA)&&(exitOption == 0)) { //returns to menu + //rightness(1.0); exitOption = 1;//reset intial option value buttonFlagA = 0;//reset flags buttonFlagB = 0; @@ -1135,6 +1146,7 @@ } //'exit' option NO - returns to game if((buttonFlagA)&&(exitOption == 1)) { + //rightness(1.0); buttonFlagA = 0;//resets flags buttonFlagB = 0; break; @@ -1173,6 +1185,7 @@ //back to menu if(buttonFlagB) { + //rightness(1.0); buttonFlagA = 0;//reset flags buttonFlagB = 0; lcd.clear(); @@ -1200,6 +1213,7 @@ //////////////////////difficulty menu //////////////////////////////////// if ((option == 0)&&(buttonFlagA)) { + //rightness(1.0); buttonFlagA = 0;//reset flag actionButtons(); drawDifficultyMenu();//draws difficulty menu @@ -1209,6 +1223,7 @@ difficultyMenu(subOption);//presents difficulty options if(buttonFlagB) { + //rightness(1.0); buttonFlagB = 0;//reset flags buttonFlagA = 0; lcd.clear();//clear screen @@ -1221,6 +1236,7 @@ //================sound FX menu========================== if((option ==1)&&(buttonFlagA)) { + //rightness(1.0); buttonFlagA = 0;//reset flags buttonFlagB = 0; actionButtons(); @@ -1232,6 +1248,7 @@ //back to options menu if(buttonFlagB) { + //rightness(1.0); buttonFlagB = 0;//reset flags buttonFlagA = 0; lcd.clear();//clear screen @@ -1243,6 +1260,7 @@ } //back to mainmenu if(buttonFlagB) { + //rightness(1.0); buttonFlagB = 0;//reset flags buttonFlagA = 0; lcd.clear();//clear @@ -1276,12 +1294,16 @@ joystick.direction = CENTRE; } else if ( joystick.y > DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { joystick.direction = DOWN; + lcd.setBrightness(1.0); } else if ( joystick.y < DIRECTION_TOLERANCE && fabs(joystick.x) < DIRECTION_TOLERANCE) { joystick.direction = UP; + lcd.setBrightness(1.0); } else if ( joystick.x > DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) { joystick.direction = RIGHT; + lcd.setBrightness(1.0); } else if ( joystick.x < DIRECTION_TOLERANCE && fabs(joystick.y) < DIRECTION_TOLERANCE) { joystick.direction = LEFT; + lcd.setBrightness(1.0); } else { joystick.direction = UNKNOWN; } @@ -1290,10 +1312,11 @@ printFlag = 1; } -void screenOff(){ - +///Turns screen backlighting off for standby. +void screenOff() +{ lcd.setBrightness(0.0); - } +} int main() { @@ -1319,14 +1342,15 @@ timerA.attach(&timerExpiredA, 0.1);//checks state of buttonA timerB.attach(&timerExpiredB, 0.1);//checks state of buttonB - if((!buttonFlagA)||(!buttonFlagB)||(!printFlag)){ - standby.attach(&screenOff,);} + if((!buttonFlagA)||(!buttonFlagB)||(!joystick.direction)){ + standby.attach(&screenOff,3);} while(1) { drawMainMenu();//draws main menu mainMenu(mainOption);//presents main menu options actionButtons();//sound light when buttons pressed - + + // if 'Play Game' selected if ((mainOption == 0)&&(buttonFlagA)) { buttonFlagA = 0; @@ -1340,7 +1364,7 @@ scores(); } // if 'option' selected - if((mainOption == 2)&&(buttonFlagA)) { + if((mainOption == 2)&&(buttonFlagA)) { buttonFlagA = 0; buttonFlagB = 0; optionsMenu();