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
Fork of ll14zs by
main.cpp
- Committer:
- ll14zs
- Date:
- 2018-04-26
- Revision:
- 1:4f9586b828c9
- Parent:
- 0:2211174dee1c
- Child:
- 2:5d3aac7fd3df
File content as of revision 1:4f9586b828c9:
/*
ELEC2645 Embedded Systems Project
School of Electronic & Electrical Engineering University of Leeds
Name: ZESHAAN SAEED
Username: LL14ZS
Student ID Number: 200967328
Date: 01/04/2018
*/
///////// pre-processor directives ////////
#include "mbed.h"
#include "Gamepad.h"
#include "N5110.h"
#include "PongEngine.h"
#define PADDLE_WIDTH 2
#define PADDLE_HEIGHT 8
#define BALL_SIZE 2
#define BALL_SPEED 3
/////////////// structs /////////////////
struct UserInput {
Direction d;
float mag;
};
/////////////// objects ///////////////
N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
Gamepad pad;
PongEngine pong;
///////////// prototypes ///////////////
void init();
void update_game(UserInput input);
void render();
void welcome();
///////////// functions ////////////////
int main()
{
int fps = 8; // frames per second
init();
welcome();
render(); // draw initial frame
wait(1.0f/fps);
// game loop - read input, update the game state and render the display
while (1) {
pong.read_input(pad);
pong.update(pad);
render();
wait(1.0f/fps);
}
}
void init()
{
// need to initialise LCD and Gamepad
lcd.init();
pad.init();
// initialise the game
pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED);
}
void render()
{
// clear screen, re-draw and refresh
lcd.clear();
pong.draw(lcd);
lcd.refresh();
}
void welcome() {
lcd.printString(" Pong! ",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);
}
}
