My ELEC2645 project. Nikollao Sulollari. 200804685

Dependencies:   N5110 SoftPWM mbed

Fork of Treasure_Hunt by ELEC2645 (2015/16)

Revision:
11:53caf3d944a9
Parent:
10:1d229362c134
Child:
12:f591f1965abd
Child:
13:359d3aa66352
--- a/main.h	Wed Apr 27 17:09:13 2016 +0000
+++ b/main.h	Thu Apr 28 16:29:06 2016 +0000
@@ -11,6 +11,7 @@
 #define MAIN_H
 #include "mbed.h"
 #include "N5110.h"
+#include "SoftPWM.h"
 
 #define DIRECTION_TOLERANCE 0.05
 /**
@@ -76,7 +77,7 @@
 @nameSpace buzzer
 @brief create PWM signal to set buzzer duty cycle and period
 */
-PwmOut buzzer(PTB9);
+SoftPWM buzzer(PTB9);
 
 /**
 @nameSpace ticker
@@ -130,6 +131,8 @@
 /// create struct variable
 Joystick joystick;
 
+int main();
+
 /**
 Displays an error message
 */
@@ -186,6 +189,11 @@
 /**
 Set-up flag to 1
 */
+void button1_isr();
+
+/**
+Set-up flag to 1
+*/
 void timeout_isr();
 
 
@@ -295,6 +303,8 @@
 
 int state1 = 1; /*!< controls the direction of the objtacle */
 
+int menuY = 5;
+
 
 void enemies()
 
@@ -330,10 +340,10 @@
     ///cotrol hero
     
     if (xPot > 0.60) { 
-        heroX++;
+        heroX--;
     }
      else if (xPot < 0.40){
-        heroX--;
+        heroX++;
     } else {
         heroX = heroX; 
     }
@@ -396,66 +406,6 @@
         sleep();
         lcd.clear();
     }
-    game_ticker.attach(game_timer_isr,0.2);
-
-    while (1) {
-
-        if (g_game_timer_flag) {
-
-            g_game_timer_flag = 0;
-            updateJoystick();
-            lcd.clear();
-            menu(); ///get Joystick's value to select option in menu
-            //option = menu();
-
-            if (option == 0) { /// select Start Game
-
-                lcd.printString("Start Game <",0,0);
-                lcd.printString("Settings",0,2);
-                lcd.printString("Exit",0,4);
-            } else if (option == 1) { /// select Settings
-
-                lcd.printString("Start Game",0,0);
-                lcd.printString("Settings <",0,2);
-                lcd.printString("Exit",0,4);
-            } else { /// select Exit
-
-                lcd.printString("Start Game",0,0);
-                lcd.printString("Settings",0,2);
-                lcd.printString("Exit <",0,4);
-            }
-        }
-        if (g_button_flag) {
-
-            g_button_flag = 0;
-
-            if (option == 0) {
-
-                game_ticker.detach();
-                break;
-            } else if (option == 1) {
-                
-                lcd.clear();
-                g_button_flag = 0;
-                while(1) {
-                    //settings_menu();
-                    pc.printf("Modify Settings!");
-                    lcd.printString("Lcd Inverse <",0,0);
-                    if (g_button_flag) {
-
-                        lcd.inverseMode();
-                        break;
-                    }
-                    sleep();
-                }
-            } else {
-
-                lcd.turnOff();
-                deepsleep();
-            }
-        }
-        sleep();
-    }
 }
 void guidance()
 {
@@ -480,14 +430,14 @@
         lcd.printString("Play again <",0,0);
         lcd.refresh();
         sleep();
+        if  (g_button1_flag) {
 
-        if  (g_button_flag) {
-
-            g_button_flag = 0;
+            g_button1_flag = 0;
             level = 0;
            // play++;
             lcd.clear();
-            //main();
+            main();
+            r_led = 0;
         }
     }
 }
@@ -640,15 +590,93 @@
 
 int menu()
 {
+    while(1) {
 
-    if (joystick.y <= 0.33) { /// if Joystick moves up
-        option = 0; /// the pointer moves upper in the menu display
-    } else if (joystick.y <= 0.66) { /// if joystick moves down
-        option = 1; /// else pointer moves down
-    } else {
-        option = 2;
+        updateJoystick();
+        lcd.clear();
+
+        lcd.printString("Start Game",0,0);
+        lcd.printString("Settings",0,2);
+        lcd.printString("Exit",0,4);
+        //lcd.drawCircle(70,4,2,1);
+
+        switch (joystick.direction) {
+            case UP:
+                option--;
+                break;
+            case DOWN:
+                option++;
+                break;
+        }
+        if (option < 0) {
+            option = 2;
+        }
+        if (option > 2) {
+            option = 0;
+        }
+
+        if (option == 0) {
+            lcd.drawCircle(70,4,2,1);
+        } else if (option == 1) {
+            lcd.drawCircle(55,20,2,1);
+        } else if (option == 2) {
+            lcd.drawCircle(35,35,2,1);
+        }
+
+        if(g_button_flag) {
+
+            g_button_flag = 0;
+
+            if (option == 0) {
+                break;
+            } else if (option == 1) {
+                
+                option = 0;
+
+                while(1) {
+
+                    updateJoystick();
+                    lcd.clear();
+                    lcd.printString("Game speed",0,0);
+                    lcd.printString("Lcd Mode",0,2);
+                    lcd.printString("Sound",0,4);
+                    switch (joystick.direction) {
+                        case UP:
+                            option--;
+                            break;
+                        case DOWN:
+                            option++;
+                            break;
+                        case CENTRE:
+                            option = option;
+                            break;
+                    }
+                    if (option < 0) {
+                        option = 2;
+                    }
+                    if (option > 2) {
+                        option = 0;
+                    }
+
+                    if (option == 0) {
+                        lcd.drawCircle(70,4,2,1);
+                    } else if (option == 1) {
+                        lcd.drawCircle(55,20,2,1);
+                    } else if (option == 2) {
+                        lcd.drawCircle(35,35,2,1);
+                    }
+                    lcd.refresh();
+                    sleep();
+                }
+            } else if (option == 2) {
+                lcd.clear();
+                lcd.turnOff();
+                deepsleep();
+            }
+        }
+        lcd.refresh();
+        sleep();
     }
-    return option;
 }
 
 int intersection(int i, int j)
@@ -680,8 +708,8 @@
 
     for (int i=40+heroX; i<50+heroX; i++) {
         for (int j=35+heroY; j<48+heroY; j++) {
-            
-            int count = intersection(i,j); 
+
+            int count = intersection(i,j);
             //lcd.setPixel(i,j);
         }
     }