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@1:37802772843e, 2019-03-25 (annotated)
- Committer:
- joshdavy
- Date:
- Mon Mar 25 10:48:23 2019 +0000
- Revision:
- 1:37802772843e
- Parent:
- 0:4916a63a6cbf
- Child:
- 2:b62e8be35a5d
Basic Classes defined. Simple sprite drawing.;
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| joshdavy | 0:4916a63a6cbf | 1 | /* |
| joshdavy | 0:4916a63a6cbf | 2 | ELEC2645 Embedded Systems Project |
| joshdavy | 0:4916a63a6cbf | 3 | School of Electronic & Electrical Engineering |
| joshdavy | 0:4916a63a6cbf | 4 | University of Leeds |
| joshdavy | 0:4916a63a6cbf | 5 | Name: Joshua Davy |
| joshdavy | 0:4916a63a6cbf | 6 | Username: el17jd |
| joshdavy | 0:4916a63a6cbf | 7 | Student ID Number: 201148379 |
| joshdavy | 0:4916a63a6cbf | 8 | Date: 12/03/2019 |
| joshdavy | 1:37802772843e | 9 | */ |
| joshdavy | 1:37802772843e | 10 | const int fps = 15; |
| joshdavy | 1:37802772843e | 11 | |
| joshdavy | 1:37802772843e | 12 | |
| joshdavy | 1:37802772843e | 13 | ///////// pre-processor directives //////// |
| joshdavy | 1:37802772843e | 14 | #include "mbed.h" |
| joshdavy | 1:37802772843e | 15 | #include "Gamepad.h" |
| joshdavy | 1:37802772843e | 16 | #include "N5110.h" |
| joshdavy | 1:37802772843e | 17 | #include "Sprite.h" |
| joshdavy | 1:37802772843e | 18 | #include "Game.h" |
| joshdavy | 1:37802772843e | 19 | |
| joshdavy | 1:37802772843e | 20 | |
| joshdavy | 1:37802772843e | 21 | /////////////// objects /////////////// |
| joshdavy | 1:37802772843e | 22 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); |
| joshdavy | 1:37802772843e | 23 | Gamepad pad; |
| joshdavy | 1:37802772843e | 24 | Game game; |
| joshdavy | 1:37802772843e | 25 | |
| joshdavy | 1:37802772843e | 26 | |
| joshdavy | 1:37802772843e | 27 | ///////////// prototypes /////////////// |
| joshdavy | 1:37802772843e | 28 | void init(); |
| joshdavy | 1:37802772843e | 29 | void welcome(); |
| joshdavy | 1:37802772843e | 30 | |
| joshdavy | 1:37802772843e | 31 | // initialies all classes and libraries |
| joshdavy | 1:37802772843e | 32 | void init() |
| joshdavy | 1:37802772843e | 33 | { |
| joshdavy | 1:37802772843e | 34 | // need to initialise LCD and Gamepad |
| joshdavy | 1:37802772843e | 35 | lcd.init(); |
| joshdavy | 1:37802772843e | 36 | pad.init(); |
| joshdavy | 1:37802772843e | 37 | |
| joshdavy | 1:37802772843e | 38 | |
| joshdavy | 1:37802772843e | 39 | |
| joshdavy | 1:37802772843e | 40 | } |
| joshdavy | 1:37802772843e | 41 | // simple splash screen displayed on start-up |
| joshdavy | 1:37802772843e | 42 | void welcome() { |
| joshdavy | 1:37802772843e | 43 | |
| joshdavy | 1:37802772843e | 44 | lcd.printString(" WOoo ",0,1); |
| joshdavy | 1:37802772843e | 45 | lcd.printString(" Press Start ",0,4); |
| joshdavy | 1:37802772843e | 46 | lcd.refresh(); |
| joshdavy | 1:37802772843e | 47 | |
| joshdavy | 1:37802772843e | 48 | // wait flashing LEDs until start button is pressed |
| joshdavy | 1:37802772843e | 49 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
| joshdavy | 1:37802772843e | 50 | pad.leds_on(); |
| joshdavy | 1:37802772843e | 51 | wait(0.1); |
| joshdavy | 1:37802772843e | 52 | pad.leds_off(); |
| joshdavy | 1:37802772843e | 53 | wait(0.1); |
| joshdavy | 1:37802772843e | 54 | } |
| joshdavy | 1:37802772843e | 55 | |
| joshdavy | 1:37802772843e | 56 | } |
| joshdavy | 1:37802772843e | 57 | |
| joshdavy | 1:37802772843e | 58 | int main() |
| joshdavy | 1:37802772843e | 59 | { |
| joshdavy | 1:37802772843e | 60 | init(); // initialise and then display welcome screen... |
| joshdavy | 1:37802772843e | 61 | welcome(); // waiting for the user to start |
| joshdavy | 1:37802772843e | 62 | |
| joshdavy | 1:37802772843e | 63 | // first draw the initial frame |
| joshdavy | 1:37802772843e | 64 | wait(1.0f/fps); // and wait for one frame period |
| joshdavy | 1:37802772843e | 65 | |
| joshdavy | 1:37802772843e | 66 | |
| joshdavy | 1:37802772843e | 67 | // game loop - read input, update the game state and render the display |
| joshdavy | 1:37802772843e | 68 | while (1) { |
| joshdavy | 1:37802772843e | 69 | game.read_input(pad); |
| joshdavy | 1:37802772843e | 70 | game.update(pad); |
| joshdavy | 1:37802772843e | 71 | game.draw(lcd); |
| joshdavy | 1:37802772843e | 72 | |
| joshdavy | 1:37802772843e | 73 | wait(1.0f/fps); |
| joshdavy | 1:37802772843e | 74 | } |
| joshdavy | 1:37802772843e | 75 | } |