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

Dependencies:   ConfigFile N5110 PowerControl beep mbed

Revision:
14:c2c969e1c6e8
Parent:
13:a1b3a373c5a4
Child:
15:ff3eb0091453
--- a/tower.h	Fri Apr 17 01:20:47 2015 +0000
+++ b/tower.h	Fri Apr 17 16:12:40 2015 +0000
@@ -20,12 +20,16 @@
 DigitalOut ledY(p24);// YELLOW LED
 
 // connections for joystick
-DigitalIn button(p17);
+InterruptIn joyButton(p17);//Interrupt for ISR
+
 AnalogIn xPot(p15);
 AnalogIn yPot(p16);
 
 // Globabl Variables /////////////////////////
 
+// flag for joystick reading
+int printFlag = 0;
+
 // boundary conditions
 int cells [84][48];
 
@@ -96,12 +100,9 @@
 // create struct variable
 Joystick joystick;
 
-int printFlag = 0;
-
 // set seed/randomise initial co-Ordinates
 void randomise()
 {
-
     srand (time(NULL));//initial seed for randomisation
 
     // initial random x co-ordinates
@@ -446,7 +447,7 @@
     actionButtons();//set audible/light for button
 
     // joystick selection
-    if (printFlag) {  //if flag set, clear flag and print joystick values to serial port
+    if (printFlag) {//if flag set, clear flag and print joystick values to serial port
         printFlag = 0;
 
         // option up
@@ -554,7 +555,7 @@
 void exitMenu(int& exitOption)
 {
     actionButtons();
-    if (printFlag) {  //if flag set, clear flag and print joystick values to serial port
+    if (printFlag) {//if flag set, clear flag and print joystick values to serial port
         printFlag = 0;
 
         // check joystick direction
@@ -945,11 +946,15 @@
 }
 
 // options menu
-void optionsMenu(int& option, int& subOption, int& fxOption)
+void optionsMenu()
 {
     actionButtons();
     drawOptionsMenu();//draws options menu
-
+    // counters for navigation
+    int option = 0;
+    int subOption = 0;
+    int fxOption = 0;
+    
     while(1) {
         actionButtons();
         optionsMenu(option);//presents options
@@ -996,7 +1001,7 @@
 // read default positions of the joystick to calibrate later readings
 void calibrateJoystick()
 {
-    button.mode(PullDown);
+    joyButton.mode(PullDown);
     // must not move during calibration
     joystick.x0 = xPot; //initial positions in the range 0.0 to 1.0 (0.5 if centred exactly)
     joystick.y0 = yPot;
@@ -1008,7 +1013,7 @@
     joystick.x = xPot - joystick.x0;
     joystick.y = yPot - joystick.y0;
     // read button state
-    joystick.button = button;
+    joystick.button = joyButton;
 
     // calculate direction depending on x,y values
     // tolerance allows a little lee-way in case joystick not exactly in the stated direction