Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Diff: main.cpp
- Revision:
- 2:9e791f33c49f
- Parent:
- 1:9d69901e18d0
diff -r 9d69901e18d0 -r 9e791f33c49f main.cpp
--- 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()