![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
A retro gaming programme, designed for use on a portable embedded system. Incorporates power saving techniques.
Dependencies: ConfigFile N5110 PowerControl beep mbed
main.cpp@42:2eba0c075a89, 2015-04-23 (annotated)
- Committer:
- el13drt
- Date:
- Thu Apr 23 18:52:58 2015 +0000
- Revision:
- 42:2eba0c075a89
- Parent:
- 40:56ab6d368e9b
- Child:
- 46:613eabb6ea86
post led
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el13drt | 0:a8bc3aac5f69 | 1 | /** |
el13drt | 0:a8bc3aac5f69 | 2 | @file main.cpp |
el13drt | 0:a8bc3aac5f69 | 3 | @brief Program implementation |
el13drt | 0:a8bc3aac5f69 | 4 | */ |
el13drt | 0:a8bc3aac5f69 | 5 | |
el13drt | 0:a8bc3aac5f69 | 6 | #include "mbed.h" |
el13drt | 0:a8bc3aac5f69 | 7 | #include "N5110.h" |
el13drt | 10:947d35365ab8 | 8 | #include "beep.h" |
el13drt | 12:eedda6554615 | 9 | #include "tower.h" |
el13drt | 14:c2c969e1c6e8 | 10 | #include "PowerControl/PowerControl.h" |
el13drt | 0:a8bc3aac5f69 | 11 | |
el13drt | 0:a8bc3aac5f69 | 12 | #include <ctime> |
el13drt | 0:a8bc3aac5f69 | 13 | #include <cstdlib> |
el13drt | 0:a8bc3aac5f69 | 14 | |
el13drt | 0:a8bc3aac5f69 | 15 | int main() |
el13drt | 0:a8bc3aac5f69 | 16 | { |
el13drt | 42:2eba0c075a89 | 17 | ledY = 1;//power LED on |
el13drt | 14:c2c969e1c6e8 | 18 | randomise();//randomises falling hazards (initial values only) |
el13drt | 7:217810c90306 | 19 | calibrateJoystick();//get centred values of joystick |
el13drt | 7:217810c90306 | 20 | pollJoystick.attach(&updateJoystick,1.0/10.0);//read joystick 10 times per second |
el13drt | 6:fa2928bcec17 | 21 | |
el13drt | 0:a8bc3aac5f69 | 22 | lcd.init();//initialise screen |
el13drt | 35:9f55326c1b0a | 23 | drawWelcome();//welcome screen |
el13drt | 0:a8bc3aac5f69 | 24 | lcd.clear();//clear pixels |
el13drt | 17:242ccf6a8442 | 25 | buttonA.mode(PullDown);//pull down buttonA |
el13drt | 17:242ccf6a8442 | 26 | buttonB.mode(PullDown);//pull down buttonB |
el13drt | 0:a8bc3aac5f69 | 27 | |
el13drt | 12:eedda6554615 | 28 | int exitFlag = 0;//exit flag |
el13drt | 5:a0e4a67266d6 | 29 | int mainOption = 0;//counter for main menu |
el13drt | 40:56ab6d368e9b | 30 | int exitOption = 1;//counter for exit menu |
el13drt | 14:c2c969e1c6e8 | 31 | |
el13drt | 40:56ab6d368e9b | 32 | timerA.attach(&timerExpiredA, 0.1);//checks state of buttonA |
el13drt | 40:56ab6d368e9b | 33 | timerB.attach(&timerExpiredB, 0.1);//checks state of buttonB |
el13drt | 14:c2c969e1c6e8 | 34 | |
el13drt | 1:352c50e88ffa | 35 | while(1) { |
el13drt | 11:6b8416a8ddb3 | 36 | drawMainMenu();//draws main menu |
el13drt | 11:6b8416a8ddb3 | 37 | mainMenu(mainOption);//presents main menu options |
el13drt | 4:c6305031f80d | 38 | |
el13drt | 11:6b8416a8ddb3 | 39 | // if 'Play Game' selected |
el13drt | 15:ff3eb0091453 | 40 | if ((mainOption == 0)&&(buttonFlagA)) { |
el13drt | 15:ff3eb0091453 | 41 | buttonFlagA = 0; |
el13drt | 19:e0fd493816ae | 42 | buttonFlagB = 0; |
el13drt | 12:eedda6554615 | 43 | game(exitFlag, exitOption);//actual game |
el13drt | 12:eedda6554615 | 44 | } |
el13drt | 12:eedda6554615 | 45 | // if 'Scores' selected |
el13drt | 15:ff3eb0091453 | 46 | if((mainOption == 1)&&(buttonFlagA)) { |
el13drt | 15:ff3eb0091453 | 47 | buttonFlagA = 0; |
el13drt | 19:e0fd493816ae | 48 | buttonFlagB = 0; |
el13drt | 12:eedda6554615 | 49 | scores(); |
el13drt | 5:a0e4a67266d6 | 50 | } |
el13drt | 12:eedda6554615 | 51 | // if 'option' selected |
el13drt | 15:ff3eb0091453 | 52 | if((mainOption == 2)&&(buttonFlagA)) { |
el13drt | 15:ff3eb0091453 | 53 | buttonFlagA = 0; |
el13drt | 19:e0fd493816ae | 54 | buttonFlagB = 0; |
el13drt | 14:c2c969e1c6e8 | 55 | optionsMenu(); |
el13drt | 1:352c50e88ffa | 56 | } |
el13drt | 15:ff3eb0091453 | 57 | sleep(); |
el13drt | 0:a8bc3aac5f69 | 58 | } |
el13drt | 3:57bab3b1c974 | 59 | } |