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.
main.cpp@0:d3a050703801, 2016-04-25 (annotated)
- Committer:
- el15s3p
- Date:
- Mon Apr 25 17:14:30 2016 +0000
- Revision:
- 0:d3a050703801
- Child:
- 1:9d69901e18d0
Menu made, need to do: Game(all), Diff, score, instruc.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| el15s3p | 0:d3a050703801 | 1 | #include "mbed.h" | 
| el15s3p | 0:d3a050703801 | 2 | #include "N5110.h" | 
| el15s3p | 0:d3a050703801 | 3 | |
| el15s3p | 0:d3a050703801 | 4 | #define DIRECTION_TOLERANCE 0.05 | 
| el15s3p | 0:d3a050703801 | 5 | |
| el15s3p | 0:d3a050703801 | 6 | // VCC, SCE, RST, D/C, MOSI, SCLK, LED | 
| el15s3p | 0:d3a050703801 | 7 | N5110 lcd (PTE26 , PTA0 , PTC4 , PTD0 , PTD2 , PTD1 , PTC3); | 
| el15s3p | 0:d3a050703801 | 8 | |
| el15s3p | 0:d3a050703801 | 9 | // connections for joystick | 
| el15s3p | 0:d3a050703801 | 10 | DigitalIn buttonJoy(PTB11); | 
| el15s3p | 0:d3a050703801 | 11 | AnalogIn xPot(PTB2); | 
| el15s3p | 0:d3a050703801 | 12 | AnalogIn yPot(PTB3); | 
| el15s3p | 0:d3a050703801 | 13 | |
| el15s3p | 0:d3a050703801 | 14 | AnalogIn Pot1(PTB10); | 
| el15s3p | 0:d3a050703801 | 15 | |
| el15s3p | 0:d3a050703801 | 16 | BusOut leds(LED1,LED2); | 
| el15s3p | 0:d3a050703801 | 17 | DigitalOut led1(LED1); | 
| el15s3p | 0:d3a050703801 | 18 | DigitalOut led2(LED2); | 
| el15s3p | 0:d3a050703801 | 19 | |
| el15s3p | 0:d3a050703801 | 20 | |
| el15s3p | 0:d3a050703801 | 21 | InterruptIn sw2 (SW2); | 
| el15s3p | 0:d3a050703801 | 22 | DigitalIn buttonA(PTB18); | 
| el15s3p | 0:d3a050703801 | 23 | DigitalIn buttonB(PTB19); | 
| el15s3p | 0:d3a050703801 | 24 | PwmOut buzzer(PTA2); | 
| el15s3p | 0:d3a050703801 | 25 | |
| el15s3p | 0:d3a050703801 | 26 | // timer to regularly read the joystick | 
| el15s3p | 0:d3a050703801 | 27 | Ticker pollJoystick; | 
| el15s3p | 0:d3a050703801 | 28 | |
| el15s3p | 0:d3a050703801 | 29 | enum DirectionName { | 
| el15s3p | 0:d3a050703801 | 30 | UP, | 
| el15s3p | 0:d3a050703801 | 31 | DOWN, | 
| el15s3p | 0:d3a050703801 | 32 | LEFT, | 
| el15s3p | 0:d3a050703801 | 33 | RIGHT, | 
| el15s3p | 0:d3a050703801 | 34 | CENTRE, | 
| el15s3p | 0:d3a050703801 | 35 | UNKNOWN | 
| el15s3p | 0:d3a050703801 | 36 | }; | 
| el15s3p | 0:d3a050703801 | 37 | |
| el15s3p | 0:d3a050703801 | 38 | // struct for Joystick | 
| el15s3p | 0:d3a050703801 | 39 | typedef struct JoyStick Joystick; | 
| el15s3p | 0:d3a050703801 | 40 | struct JoyStick { | 
| el15s3p | 0:d3a050703801 | 41 | float x; // current x value | 
| el15s3p | 0:d3a050703801 | 42 | float x0; // 'centred' x value | 
| el15s3p | 0:d3a050703801 | 43 | float y; // current y value | 
| el15s3p | 0:d3a050703801 | 44 | float y0; // 'centred' y value | 
| el15s3p | 0:d3a050703801 | 45 | int button; // button state (assume pull-down used, so 1 = pressed, 0 = unpressed) | 
| el15s3p | 0:d3a050703801 | 46 | DirectionName direction; // current direction | 
| el15s3p | 0:d3a050703801 | 47 | }; | 
| el15s3p | 0:d3a050703801 | 48 | // create struct variable | 
| el15s3p | 0:d3a050703801 | 49 | Joystick joystick; | 
| el15s3p | 0:d3a050703801 | 50 | |
| el15s3p | 0:d3a050703801 | 51 | int printFlag = 0; | 
| el15s3p | 0:d3a050703801 | 52 | |
| el15s3p | 0:d3a050703801 | 53 | int main() | 
| el15s3p | 0:d3a050703801 | 54 | { | 
| el15s3p | 0:d3a050703801 | 55 | lcd.init(); | 
| el15s3p | 0:d3a050703801 | 56 | lcd.clear(); | 
| el15s3p | 0:d3a050703801 | 57 | lcd.normalMode(); | 
| el15s3p | 0:d3a050703801 | 58 | lcd.printString("Comet Crusher!",0,0); | 
| el15s3p | 0:d3a050703801 | 59 | lcd.printString("Start",10,2); | 
| el15s3p | 0:d3a050703801 | 60 | lcd.printString("Difficulty",10,3); | 
| el15s3p | 0:d3a050703801 | 61 | lcd.printString("Scores",10,4); | 
| el15s3p | 0:d3a050703801 | 62 | lcd.printString("Instructions",10,5); | 
| el15s3p | 0:d3a050703801 | 63 | lcd.printString(">",5,2); | 
| el15s3p | 0:d3a050703801 | 64 | while(1) { | 
| el15s3p | 0:d3a050703801 | 65 | } | 
| el15s3p | 0:d3a050703801 | 66 | } | 
| el15s3p | 0:d3a050703801 | 67 | |
| el15s3p | 0:d3a050703801 | 68 | void Game() | 
| el15s3p | 0:d3a050703801 | 69 | { | 
| el15s3p | 0:d3a050703801 | 70 | } | 
| el15s3p | 0:d3a050703801 | 71 | |
| el15s3p | 0:d3a050703801 | 72 | void DifficultySet() | 
| el15s3p | 0:d3a050703801 | 73 | { | 
| el15s3p | 0:d3a050703801 | 74 | } | 
| el15s3p | 0:d3a050703801 | 75 | |
| el15s3p | 0:d3a050703801 | 76 | void HighScore() | 
| el15s3p | 0:d3a050703801 | 77 | { | 
| el15s3p | 0:d3a050703801 | 78 | } | 
| el15s3p | 0:d3a050703801 | 79 | |
| el15s3p | 0:d3a050703801 | 80 | void Instructions() | 
| el15s3p | 0:d3a050703801 | 81 | { | 
| el15s3p | 0:d3a050703801 | 82 | } |