A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.
Dependencies: ConfigFile N5110 PowerControl beep mbed
Diff: tower.h
- Revision:
- 15:ff3eb0091453
- Parent:
- 14:c2c969e1c6e8
- Child:
- 16:93ae2f311fd8
--- a/tower.h Fri Apr 17 16:12:40 2015 +0000 +++ b/tower.h Fri Apr 17 20:23:31 2015 +0000 @@ -5,6 +5,10 @@ // VCC,SCE,RST,D/C,MOSI,SCLK,LED - set pins for LCD N5110 lcd(p7,p8,p9,p10,p11,p13,p22); +// timers to check state of buttons +Ticker timer;//buttonA +Ticker timer2;//buttonB + // create buzzer objecct Beep buzzer(p21); @@ -21,12 +25,15 @@ // connections for joystick InterruptIn joyButton(p17);//Interrupt for ISR - AnalogIn xPot(p15); AnalogIn yPot(p16); // Globabl Variables ///////////////////////// +// timer flags to check state of buttons +int buttonFlagA = 0; +int buttonFlagB = 0; + // flag for joystick reading int printFlag = 0; @@ -99,6 +106,21 @@ // create struct variable Joystick joystick; +void timerExpiredA() +{ + if(buttonA == 1) { + buttonFlagA = 1; + serial.printf("flagA set\n"); + } +} + +void timerExpiredB() +{ + if(buttonB == 1) { + buttonFlagB = 1; + serial.printf("flagB set\n"); + } +} // set seed/randomise initial co-Ordinates void randomise() @@ -419,32 +441,10 @@ lcd.refresh(); } -// BEEP/LED when button is closed -void actionButtons() -{ - buttonA.mode(PullDown); - buttonB.mode(PullDown); - - if (buttonA != 0) { - ledY = 1; - buzzer.beep(1000,0.2);//frequeny/duration - serial.printf("buttonA\n");//print for debugging - } else { - ledY = 0; - } - if (buttonB != 0) { - ledY = 1; - buzzer.beep(400,0.2);//frequency/duration - serial.printf("buttonB\n");//print for debugging - } else { - ledY = 0; - } -} - // presents main menu options void mainMenu(int& mainOption) { - actionButtons();//set audible/light for button + //actionButtons();//set audible/light for button // joystick selection if (printFlag) {//if flag set, clear flag and print joystick values to serial port @@ -554,7 +554,7 @@ // presents exit menu options void exitMenu(int& exitOption) { - actionButtons(); + //actionButtons(); if (printFlag) {//if flag set, clear flag and print joystick values to serial port printFlag = 0; @@ -657,7 +657,7 @@ // present difficulty options void difficultyMenu(int& subOption) { - actionButtons(); + //actionButtons(); // joystick selection if (printFlag) {//if flag set, clear flag,print joystick values @@ -729,7 +729,7 @@ // present sound FX options void soundFXMenu(int& fxOption) { - actionButtons(); + //actionButtons(); // joystick selection if (printFlag) {//if flag set, clear flag,print joystick values @@ -792,7 +792,7 @@ // actual game void game(int& exitFlag, int& exitOption) { - actionButtons(); + //actionButtons(); lcd.clear();//clears screen backGround();//draw background @@ -804,7 +804,7 @@ if (length <= 14) //ensure length is smaller than screen lcd.printString(buffer,3,0);//display - actionButtons(); + //actionButtons(); pixelNinja();//set character hazards();//initiates hazards hazardFall();//increments hazards towards floor @@ -887,7 +887,7 @@ // 'exit' option YES if((buttonA == 1)&&(exitOption == 0)) { //returns to menu - actionButtons(); + // actionButtons(); lcd.clear();//clears screen resetGame();//resets scores/objects exitFlag = 1;//sets exit flag @@ -913,7 +913,7 @@ // high scores screen void scores() { - actionButtons(); + //actionButtons(); lcd.clear();//clear screen backGround();//set background lcd.printString("High Scores",10,0);//title @@ -935,7 +935,7 @@ lcd.printString(highScore3,5,4);//display while(1) { - actionButtons();//select + // actionButtons();//select // back to menu if(buttonB == 1) { @@ -948,52 +948,59 @@ // options menu void optionsMenu() { - actionButtons(); - drawOptionsMenu();//draws options menu - // counters for navigation int option = 0; int subOption = 0; int fxOption = 0; + //actionButtons(); + drawOptionsMenu();//draws options menu + // counters for navigation while(1) { - actionButtons(); + //actionButtons(); optionsMenu(option);//presents options ////////////////////// difficulty menu //////////////////////////////////// - if ((option == 0)&&(buttonA == 1)) { - actionButtons(); + if ((option == 0)&&(buttonFlagA)) { + buttonFlagA = 0;//reset flag + //actionButtons(); drawDifficultyMenu();//draws difficulty menu while(1) { - actionButtons(); + // actionButtons(); difficultyMenu(subOption);//presents difficulty options - if(buttonB != 0) { - lcd.clear(); - break; + if(buttonFlagB) { + buttonFlagB = 0;//reset flag + lcd.clear();//clear screen + break;//return back } } + drawOptionsMenu(); } ///////////////////// sound FX menu ////////////////////////////////////// - if((option ==1)&&(buttonA !=0)) { - actionButtons(); + if((option ==1)&&(buttonFlagA)) { + buttonFlagA = 0;//reset flag + //actionButtons(); drawSoundFXMenu();//draw menu while(1) { - actionButtons(); + // actionButtons(); soundFXMenu(fxOption); // back to options menu - if(buttonB !=0) { - lcd.clear(); - break; + if(buttonFlagB) { + buttonFlagB = 0;//reset flag + lcd.clear();//clear screen + break;//return back } } + drawOptionsMenu(); } // back to mainmenu - if(buttonB !=0) { - lcd.clear(); - break; + if(buttonFlagB) { + buttonFlagB = 0;//reset flag + lcd.clear();//clear + break;//return back } } }