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
- Committer:
- ml16c5l
- Date:
- 2019-04-09
- Revision:
- 3:5d860d0d589e
- Parent:
- 1:63db7ec60700
- Child:
- 4:2848b366ee3d
File content as of revision 3:5d860d0d589e:
/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering
University of Leeds
Name: Caiwenjing Liu
Username:ml16c5l
Student ID Number: 201165261
Date: 09/04/2019
*/
///////// pre-processor directives ////////
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
//#include "CopterEngine.h"
#ifdef WITH_TESTING
# include "tests.h"
#endif
/////////////// structs /////////////////
struct UserInput {
Direction d;
float mag;
};
/////////////// objects ///////////////
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
//CopterEngine copter;
///////////// prototypes ///////////////
void init();
void update_game(UserInput input);
void render();
void welcome();
///////////// functions ////////////////
int main()
{
int fps = 8; // frames per second
init(); // initialise and then display welcome screen...
welcome(); // waiting for the user to start
render(); // first draw the initial frame
wait(1.0f/fps); // and wait for one frame period
// game loop - read input, update the game state and render the display
while (1) {
copter.read_input(pad);
copter.update(pad);
render();
wait(1.0f/fps);
}
}
// initialies all classes and libraries
void init()
{
// need to initialise LCD and Gamepad
lcd.init();
pad.init();
// initialise the game with correct ball and paddle sizes
copter.init(COPTER_WIDTH,COPTER_HEIGHT,WALL_SIZE,COPTER_SPEED);
}
// this function draws each frame on the LCD
void render()
{
// clear screen, re-draw and refresh
lcd.clear();
copter.draw(lcd);
lcd.refresh();
}
// simple splash screen displayed on start-up
void welcome() {
lcd.printString(" Copter! ",0,1);
lcd.printString(" Press Start ",0,4);
lcd.refresh();
// wait flashing LEDs until start button is pressed
while ( pad.check_event(Gamepad::START_PRESSED) == false) {
pad.leds_on();
wait(0.1);
pad.leds_off();
wait(0.1);
}
}