ELEC2645 (2018/19) / Mbed 2 deprecated el17m2h_public

Dependencies:   mbed

Committer:
el17m2h
Date:
Thu Apr 11 14:44:14 2019 +0000
Revision:
4:8ec314f806ae
Parent:
3:116913e97fd7
Child:
5:8814d6de77d0
Added a doodler that will be controlled by the user using the joystick.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
el17m2h 1:0001cb3eb053 1 #include "mbed.h"
el17m2h 1:0001cb3eb053 2 #include "Gamepad.h"
el17m2h 1:0001cb3eb053 3 #include "N5110.h"
el17m2h 2:360a6c301a4e 4 #include "Engine.h"
el17m2h 1:0001cb3eb053 5
el17m2h 4:8ec314f806ae 6 #define FLOORS_WIDTH 12
el17m2h 3:116913e97fd7 7 #define FLOORS_HEIGHT 2
el17m2h 4:8ec314f806ae 8 #define DOODLER_RADIUS 3
el17m2h 1:0001cb3eb053 9
el17m2h 1:0001cb3eb053 10 // objects
el17m2h 1:0001cb3eb053 11 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 12 Gamepad pad;
el17m2h 2:360a6c301a4e 13 Engine eng;
el17m2h 1:0001cb3eb053 14
el17m2h 1:0001cb3eb053 15 // prototypes
el17m2h 1:0001cb3eb053 16 void init();
el17m2h 1:0001cb3eb053 17 void draw();
el17m2h 1:0001cb3eb053 18 void welcome();
el17m2h 1:0001cb3eb053 19
el17m2h 1:0001cb3eb053 20 // functions
el17m2h 1:0001cb3eb053 21 int main(){
el17m2h 1:0001cb3eb053 22 init(); // initialise and then display welcome screen...
el17m2h 1:0001cb3eb053 23 while(1){
el17m2h 1:0001cb3eb053 24 welcome();
el17m2h 1:0001cb3eb053 25 if ( pad.check_event(Gamepad::START_PRESSED) == true) {
el17m2h 1:0001cb3eb053 26 break; }
el17m2h 1:0001cb3eb053 27 }
el17m2h 1:0001cb3eb053 28 draw();
el17m2h 1:0001cb3eb053 29 }
el17m2h 1:0001cb3eb053 30
el17m2h 1:0001cb3eb053 31 // initialies all classes and libraries
el17m2h 1:0001cb3eb053 32 void init(){
el17m2h 1:0001cb3eb053 33 // need to initialise LCD and Gamepad
el17m2h 1:0001cb3eb053 34 lcd.init();
el17m2h 1:0001cb3eb053 35 pad.init();
el17m2h 4:8ec314f806ae 36 eng.init(FLOORS_WIDTH, FLOORS_HEIGHT, DOODLER_RADIUS);
el17m2h 1:0001cb3eb053 37 }
el17m2h 1:0001cb3eb053 38
el17m2h 1:0001cb3eb053 39 // Starting menu screen display
el17m2h 1:0001cb3eb053 40 void welcome() {
el17m2h 1:0001cb3eb053 41 lcd.printString(" Doodle Jump! ",0,1);
el17m2h 1:0001cb3eb053 42 lcd.printString(" Press Start ",0,4);
el17m2h 1:0001cb3eb053 43 lcd.refresh();
el17m2h 1:0001cb3eb053 44 }
el17m2h 1:0001cb3eb053 45
el17m2h 1:0001cb3eb053 46 void draw(){
el17m2h 1:0001cb3eb053 47 lcd.clear();
el17m2h 2:360a6c301a4e 48 eng.draw(lcd);
el17m2h 1:0001cb3eb053 49 lcd.refresh();
el17m2h 1:0001cb3eb053 50 }