A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.
Dependencies: ConfigFile N5110 PowerControl beep mbed
Diff: main.cpp
- Revision:
- 2:8fac5562ed1e
- Parent:
- 1:352c50e88ffa
- Child:
- 3:57bab3b1c974
--- a/main.cpp Mon Apr 13 02:34:03 2015 +0000 +++ b/main.cpp Mon Apr 13 14:08:55 2015 +0000 @@ -389,26 +389,37 @@ /////// Menu Selection Loop //////////////////////////////////////////////////////////// int option = 0; - + + // Internal Pull Up resistors set for + // buttons A and B. +// buttonA.mode(PullUP); +// buttonB.mode(PullUp); + while(1) { + + // Joystick selection if (printFlag) { // if flag set, clear flag and print joystick values to serial port printFlag = 0; serial.printf("x = %f y = %f button = %d ",joystick.x,joystick.y,joystick.button); // Option up - if (joystick.direction == LEFT) { + if (joystick.direction == UP) { serial.printf(" UP\n"); + option = option--; + if (option < 0)option = 0; + } + // Option down + if (joystick.direction == DOWN) { + serial.printf(" DOWN\n"); option = option++; if (option > 1)option = 1; } - - // Option down - if (joystick.direction == RIGHT) { - serial.printf(" DOWN\n"); - option = option--; - if (option < 0)option = 0; - } + // Centre / Unknown orientation + if (joystick.direction == CENTRE) + serial.printf(" CENTRE\n"); + if (joystick.direction == UNKNOWN) + serial.printf(" Unsupported direction\n"); // 'Play Game' option if (option == 0) { @@ -418,7 +429,11 @@ if (option == 1) { lcd.printString(" Options ",3,4); } + if ((option == 0)&&(buttonA == 1){ + + backGround + } } @@ -478,6 +493,8 @@ void calibrateJoystick() { button.mode(PullDown); + buttonA.mode(PullDown); + buttonB.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;