ELEC2645 (2015/16) / Mbed 2 deprecated 2645_ProjectCode

Dependencies:   N5110 mbed

Revision:
2:9e791f33c49f
Parent:
1:9d69901e18d0
--- a/main.cpp	Wed Apr 27 22:27:56 2016 +0000
+++ b/main.cpp	Wed Apr 27 22:47:43 2016 +0000
@@ -58,7 +58,7 @@
 
 int main()
 {
-    for (; 2 > menuSelect < 5;) {
+    while (1) {
         calibrateJoystick();  // get centred values of joystick
         pollJoystick.attach(&updateJoystick,1.0/10.0);  // read joystick 10 times per second
         lcd.init();
@@ -71,52 +71,61 @@
         lcd.printString("Scores",10,5);
         lcd.printString(">",5,menuSelect);
         lcd.refresh();
-
-        if (menuSelect == 2) {
-            if (joystick.direction == DOWN) {
-                menuSelect = 3;
-                sleep();
-            } else if (joystick.direction == UP) {
-                menuSelect = 5;
-                sleep();
-            }
-            lcd.refresh();
-            sleep();
-        }
-        if (menuSelect == 3) {
-            if (joystick.direction == DOWN) {
-                menuSelect = 4;
-                sleep();
-            } else if (joystick.direction == UP) {
-                menuSelect = 2;
-                sleep();
-            }
-            lcd.refresh();
-            sleep();
+        sleep();
+        switch (menuSelect) {
+            case 2:
+                if (joystick.direction == DOWN) {
+                    menuSelect = 3;
+                    lcd.refresh();
+                    wait (0.5);
+                    sleep();
+                } else if (joystick.direction == UP) {
+                    menuSelect = 5;
+                    lcd.refresh();
+                    wait (0.5);
+                    sleep();
+                }
+                break;
+            case 3:
+                if (joystick.direction == DOWN) {
+                    menuSelect = 4;
+                    lcd.refresh();
+                    wait (0.5);
+                    sleep();
+                } else if (joystick.direction == UP) {
+                    menuSelect = 2;
+                    lcd.refresh();
+                    wait (0.5);
+                    sleep();
+                }
+                break;
+            case 4:
+                if (joystick.direction == DOWN) {
+                    menuSelect = 5;
+                    lcd.refresh();
+                    wait (0.5);
+                    sleep();
+                } else if (joystick.direction == UP) {
+                    menuSelect = 3;
+                    lcd.refresh();
+                    wait (0.5);
+                    sleep();
+                }
+                break;
+            case 5:
+                if (joystick.direction == DOWN) {
+                    menuSelect = 2;
+                    lcd.refresh();
+                    wait (0.5);
+                    sleep();
+                } else if (joystick.direction == UP) {
+                    menuSelect = 4;
+                    lcd.refresh();
+                    wait (0.5);
+                    sleep();
+                }
+                break;
         }
-        if (menuSelect == 4) {
-            if (joystick.direction == DOWN) {
-                menuSelect = 5; 
-                sleep();
-            } else if (joystick.direction == UP) {
-                menuSelect = 3;
-                sleep();
-            }
-            lcd.refresh();
-            sleep();
-        }
-        if (menuSelect == 5) {
-            if (joystick.direction == DOWN) {
-                menuSelect = 2;
-                sleep();
-            } else if (joystick.direction == UP) {
-                menuSelect = 4;
-                sleep();
-            }
-            lcd.refresh();
-            sleep();
-        }
-        sleep();
     }
 }
 void game()