A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.

Dependencies:   ConfigFile N5110 PowerControl beep mbed

Files at this revision

API Documentation at this revision

Comitter:
el13drt
Date:
Sat Apr 18 00:42:44 2015 +0000
Parent:
16:93ae2f311fd8
Child:
18:c38e1966d870
Commit message:
pre flags

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
tower.h Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Fri Apr 17 21:26:52 2015 +0000
+++ b/main.cpp	Sat Apr 18 00:42:44 2015 +0000
@@ -22,16 +22,15 @@
     lcd.init();//initialise screen
     welcome();//welcome screen
     lcd.clear();//clear pixels
+    buttonA.mode(PullDown);//pull down buttonA
+    buttonB.mode(PullDown);//pull down buttonB
 
     int exitFlag = 0;//exit flag
     int mainOption = 0;//counter for main menu
     int exitOption = 0;//counter for exit menu
     
-    buttonA.mode(PullDown);
-    buttonB.mode(PullDown);
-    
-    timer.attach(&timerExpiredA, 0.2);//checks state of buttonA
-    timer2.attach(&timerExpiredB, 0.2);//checks state of buttonB
+    timerA.attach(&timerExpiredA, 0.2);//checks state of buttonA
+    timerB.attach(&timerExpiredB, 0.2);//checks state of buttonB
     
     while(1) {
         drawMainMenu();//draws main menu
--- a/tower.h	Fri Apr 17 21:26:52 2015 +0000
+++ b/tower.h	Sat Apr 18 00:42:44 2015 +0000
@@ -6,8 +6,8 @@
 N5110 lcd(p7,p8,p9,p10,p11,p13,p22);
 
 // timers to check state of buttons
-Ticker timer;//buttonA
-Ticker timer2;//buttonB
+Ticker timerA;//buttonA
+Ticker timerB;//buttonB
 
 // create buzzer objecct
 Beep buzzer(p21);
@@ -30,6 +30,9 @@
 
 // Globabl Variables /////////////////////////
 
+// sound FX toggle
+int FX = 0;
+
 // timer flags to check state of buttons
 int buttonFlagA = 0;
 int buttonFlagB = 0;
@@ -441,10 +444,24 @@
     lcd.refresh();
 }
 
+// beep/light when buttons are closed
+void actionButtons()
+{
+    if((FX == 0)&&(buttonA||buttonB)) {
+        ledY = 1;
+        buzzer.beep(1500,0.3);
+    }
+    if (buttonA || buttonB) {
+        ledY = 1;
+    } 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 +571,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 +674,7 @@
 // present difficulty options
 void difficultyMenu(int& subOption)
 {
-    //actionButtons();
+    actionButtons();
 
     // joystick selection
     if (printFlag) {//if flag set, clear flag,print joystick values
@@ -729,7 +746,7 @@
 // present sound FX options
 void soundFXMenu(int& fxOption)
 {
-    //actionButtons();
+    actionButtons();
 
     // joystick selection
     if (printFlag) {//if flag set, clear flag,print joystick values
@@ -752,26 +769,30 @@
             serial.printf(" CENTRE\n");
         if (joystick.direction == UNKNOWN)
             serial.printf(" Unsupported direction\n");
+    }
 
-        // 'ON' option 1
-        if (fxOption == 0) {
-            lcd.drawCircle(72,27,2,1);
-            refreshCursor1();
-            refreshCursor3();
+    // 'ON' option 1
+    if (fxOption == 0) {
+        lcd.drawCircle(72,27,2,1);//draw cursor 'ON'
+        refreshCursor1();
+        refreshCursor3();
 
-            if(buttonA == 1) { //select normal
-                //  fall = 2;
-            }
+        if(buttonFlagA) {
+            buttonFlagA =0;
+            FX = 0;
+            serial.printf("FX = %d",FX);
         }
-        // 'OFF' option 2
-        if (fxOption == 1) {
-            lcd.drawCircle(72,35,2,1);
-            refreshCursor1();
-            refreshCursor2();
+    }
+    // 'OFF' option 2
+    if (fxOption == 1) {
+        lcd.drawCircle(72,35,2,1);//draw cursor 'OFF'
+        refreshCursor1();
+        refreshCursor2();
 
-            if(buttonA == 1) { //select difficult
-                //fall = 3;
-            }
+        if(buttonFlagA) {
+            buttonFlagA =0;
+            FX = 1;
+            serial.printf("FX = %d",FX);
         }
     }
 }
@@ -791,7 +812,7 @@
 // actual game
 void game(int& exitFlag, int& exitOption)
 {
-    //actionButtons();
+    actionButtons();
     lcd.clear();//clears screen
     backGround();//draw background
 
@@ -803,7 +824,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
@@ -875,12 +896,12 @@
                 resetGame();
                 break;
             }
-            //wait(0.05);
             startrek();//clears unset pixels, keeps set pixels
-            
+
 
 /// Exit Menu (Back button pressed)///
             if(buttonB == 1) {
+                actionButtons();
                 drawExitMenu();//draws the exit menu
 
                 while(1) {
@@ -888,7 +909,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
@@ -914,7 +935,7 @@
 // high scores screen
 void scores()
 {
-    //actionButtons();
+    actionButtons();
     lcd.clear();//clear screen
     backGround();//set background
     lcd.printString("High Scores",10,0);//title
@@ -936,7 +957,7 @@
         lcd.printString(highScore3,5,4);//display
 
     while(1) {
-      //  actionButtons();//select
+        actionButtons();//select
 
         // back to menu
         if(buttonB == 1) {
@@ -952,22 +973,22 @@
     int option = 0;
     int subOption = 0;
     int fxOption = 0;
-    //actionButtons();
+    actionButtons();
     drawOptionsMenu();//draws options menu
     // counters for navigation
-    
+
     while(1) {
-        //actionButtons();
+        actionButtons();
         optionsMenu(option);//presents options
 
 ////////////////////// difficulty menu ////////////////////////////////////
         if ((option == 0)&&(buttonFlagA)) {
             buttonFlagA = 0;//reset flag
-            //actionButtons();
+            actionButtons();
             drawDifficultyMenu();//draws difficulty menu
 
             while(1) {
-              //  actionButtons();
+                actionButtons();
                 difficultyMenu(subOption);//presents difficulty options
 
                 if(buttonFlagB) {
@@ -975,18 +996,19 @@
                     lcd.clear();//clear screen
                     break;//return back
                 }
+                sleep();//put while to sleep
             }
-        drawOptionsMenu();
+            drawOptionsMenu();
         }
 ///////////////////// sound FX menu //////////////////////////////////////
         if((option ==1)&&(buttonFlagA)) {
             buttonFlagA = 0;//reset flag
-            //actionButtons();
+            actionButtons();
             drawSoundFXMenu();//draw menu
 
             while(1) {
-               // actionButtons();
-                soundFXMenu(fxOption);
+                actionButtons();
+                soundFXMenu(fxOption);//presents options
 
                 // back to options menu
                 if(buttonFlagB) {
@@ -994,6 +1016,7 @@
                     lcd.clear();//clear screen
                     break;//return back
                 }
+                sleep();//put while to sleep
             }
             drawOptionsMenu();
         }
@@ -1003,6 +1026,7 @@
             lcd.clear();//clear
             break;//return back
         }
+    sleep();//put while to sleep
     }
 }