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.
Dependencies: mbed
main.cpp@5:8814d6de77d0, 2019-04-13 (annotated)
- Committer:
- el17m2h
- Date:
- Sat Apr 13 17:37:52 2019 +0000
- Revision:
- 5:8814d6de77d0
- Parent:
- 4:8ec314f806ae
- Child:
- 15:4efa04a6a376
Created an update function for the doodler to change its position depending on the user moving the joystick left or right.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
el17m2h | 5:8814d6de77d0 | 1 | /* |
el17m2h | 5:8814d6de77d0 | 2 | ELEC2645 Embedded Systems Project |
el17m2h | 5:8814d6de77d0 | 3 | School of Electronic & Electrical Engineering |
el17m2h | 5:8814d6de77d0 | 4 | University of Leeds |
el17m2h | 5:8814d6de77d0 | 5 | Name: Melissa Hartmann |
el17m2h | 5:8814d6de77d0 | 6 | Username: el17m2h |
el17m2h | 5:8814d6de77d0 | 7 | Student ID Number: 201176603 |
el17m2h | 5:8814d6de77d0 | 8 | Date: 11/04/2019 |
el17m2h | 5:8814d6de77d0 | 9 | */ |
el17m2h | 5:8814d6de77d0 | 10 | |
el17m2h | 5:8814d6de77d0 | 11 | |
el17m2h | 1:0001cb3eb053 | 12 | #include "mbed.h" |
el17m2h | 1:0001cb3eb053 | 13 | #include "Gamepad.h" |
el17m2h | 1:0001cb3eb053 | 14 | #include "N5110.h" |
el17m2h | 2:360a6c301a4e | 15 | #include "Engine.h" |
el17m2h | 1:0001cb3eb053 | 16 | |
el17m2h | 5:8814d6de77d0 | 17 | #define FLOORS_WIDTH 13 |
el17m2h | 3:116913e97fd7 | 18 | #define FLOORS_HEIGHT 2 |
el17m2h | 5:8814d6de77d0 | 19 | #define DOODLER_RADIUS 2 |
el17m2h | 5:8814d6de77d0 | 20 | |
el17m2h | 5:8814d6de77d0 | 21 | //structs |
el17m2h | 5:8814d6de77d0 | 22 | struct UserInput { |
el17m2h | 5:8814d6de77d0 | 23 | Direction d; |
el17m2h | 5:8814d6de77d0 | 24 | float mag; |
el17m2h | 5:8814d6de77d0 | 25 | }; |
el17m2h | 5:8814d6de77d0 | 26 | |
el17m2h | 1:0001cb3eb053 | 27 | |
el17m2h | 1:0001cb3eb053 | 28 | // objects |
el17m2h | 1:0001cb3eb053 | 29 | N5110 lcd(PTC5,PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); // START, LCD SCE, LCD RST, LCD DC, LCD MOSI, LCD CLK, LCD Backlight |
el17m2h | 1:0001cb3eb053 | 30 | Gamepad pad; |
el17m2h | 2:360a6c301a4e | 31 | Engine eng; |
el17m2h | 1:0001cb3eb053 | 32 | |
el17m2h | 1:0001cb3eb053 | 33 | // prototypes |
el17m2h | 1:0001cb3eb053 | 34 | void init(); |
el17m2h | 5:8814d6de77d0 | 35 | void update_game(UserInput input); |
el17m2h | 5:8814d6de77d0 | 36 | void render(); |
el17m2h | 1:0001cb3eb053 | 37 | void welcome(); |
el17m2h | 1:0001cb3eb053 | 38 | |
el17m2h | 1:0001cb3eb053 | 39 | // functions |
el17m2h | 1:0001cb3eb053 | 40 | int main(){ |
el17m2h | 5:8814d6de77d0 | 41 | int fps = 8; |
el17m2h | 1:0001cb3eb053 | 42 | init(); // initialise and then display welcome screen... |
el17m2h | 5:8814d6de77d0 | 43 | welcome(); |
el17m2h | 5:8814d6de77d0 | 44 | render(); |
el17m2h | 5:8814d6de77d0 | 45 | wait(1.0f/fps); |
el17m2h | 1:0001cb3eb053 | 46 | while(1){ |
el17m2h | 5:8814d6de77d0 | 47 | eng.read_input(pad); |
el17m2h | 5:8814d6de77d0 | 48 | eng.update(pad); |
el17m2h | 5:8814d6de77d0 | 49 | render(); |
el17m2h | 5:8814d6de77d0 | 50 | wait(1.0f/fps); |
el17m2h | 1:0001cb3eb053 | 51 | } |
el17m2h | 1:0001cb3eb053 | 52 | } |
el17m2h | 1:0001cb3eb053 | 53 | |
el17m2h | 5:8814d6de77d0 | 54 | |
el17m2h | 1:0001cb3eb053 | 55 | // initialies all classes and libraries |
el17m2h | 1:0001cb3eb053 | 56 | void init(){ |
el17m2h | 1:0001cb3eb053 | 57 | // need to initialise LCD and Gamepad |
el17m2h | 1:0001cb3eb053 | 58 | lcd.init(); |
el17m2h | 1:0001cb3eb053 | 59 | pad.init(); |
el17m2h | 4:8ec314f806ae | 60 | eng.init(FLOORS_WIDTH, FLOORS_HEIGHT, DOODLER_RADIUS); |
el17m2h | 1:0001cb3eb053 | 61 | } |
el17m2h | 1:0001cb3eb053 | 62 | |
el17m2h | 5:8814d6de77d0 | 63 | void render(){ |
el17m2h | 5:8814d6de77d0 | 64 | lcd.clear(); |
el17m2h | 5:8814d6de77d0 | 65 | eng.draw(lcd); |
el17m2h | 5:8814d6de77d0 | 66 | lcd.refresh(); |
el17m2h | 5:8814d6de77d0 | 67 | } |
el17m2h | 5:8814d6de77d0 | 68 | |
el17m2h | 1:0001cb3eb053 | 69 | // Starting menu screen display |
el17m2h | 1:0001cb3eb053 | 70 | void welcome() { |
el17m2h | 1:0001cb3eb053 | 71 | lcd.printString(" Doodle Jump! ",0,1); |
el17m2h | 1:0001cb3eb053 | 72 | lcd.printString(" Press Start ",0,4); |
el17m2h | 1:0001cb3eb053 | 73 | lcd.refresh(); |
el17m2h | 5:8814d6de77d0 | 74 | |
el17m2h | 5:8814d6de77d0 | 75 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
el17m2h | 5:8814d6de77d0 | 76 | pad.leds_on(); |
el17m2h | 5:8814d6de77d0 | 77 | wait(0.1); |
el17m2h | 5:8814d6de77d0 | 78 | pad.leds_off(); |
el17m2h | 5:8814d6de77d0 | 79 | wait(0.1); |
el17m2h | 5:8814d6de77d0 | 80 | } |
el17m2h | 5:8814d6de77d0 | 81 | } |