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
Diff: main.cpp
- Revision:
- 1:09a835e6d063
- Parent:
- 0:7423345f87c5
- Child:
- 2:c6772c5ab69d
--- a/main.cpp Fri Jan 31 12:32:38 2020 +0000 +++ b/main.cpp Tue Jun 02 21:33:00 2020 +0000 @@ -1,17 +1,21 @@ +/* +ELEC2645 Embedded Systems Project +School of Electronic & Electrical Engineering +University of Leeds +2019/20 + +Name: Simon Thackray Atkinson +Username: el18s2a +Student ID Number: 201255483 +Date: 05/03/2020 +*/ + ///////// pre-processor directives //////// #include "mbed.h" #include "Gamepad.h" #include "N5110.h" -#include "PongEngine.h" -#ifdef WITH_TESTING -# include "tests.h" -#endif -#define PADDLE_WIDTH 2 -#define PADDLE_HEIGHT 8 -#define BALL_SIZE 2 -#define BALL_SPEED 3 /////////////// structs ///////////////// struct UserInput { @@ -21,76 +25,51 @@ /////////////// objects /////////////// N5110 lcd; Gamepad pad; -PongEngine pong; + -///////////// prototypes /////////////// -void init(); -void update_game(UserInput input); -void render(); + void welcome(); ///////////// functions //////////////// + int main() { -#ifdef WITH_TESTING - int number_of_failures = run_all_tests(); - - if(number_of_failures > 0) return number_of_failures; -#endif - - int fps = 6; // 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) { - pong.read_input(pad); - pong.update(pad); - render(); - wait(1.0f/fps); - } -} + // first need to initialise display + lcd.init(); -// 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 - pong.init(PADDLE_WIDTH,PADDLE_HEIGHT,BALL_SIZE,BALL_SPEED); - -} - -// this function draws each frame on the LCD -void render() -{ - // clear screen, re-draw and refresh - lcd.clear(); - pong.draw(lcd); - lcd.refresh(); -} - -// simple splash screen displayed on start-up -void welcome() { - - lcd.printString(" Pong! ",0,1); + while(1) { + // Splash Screen Info + lcd.clear(); // we need to clear the screen first + lcd.printString(" Author ",0,1); + lcd.printString("Simon Atkinson",0,2); + lcd.printString(" 201255483 ",0,3); + lcd.printString(" Uni of Leeds ",0,4); + lcd.refresh(); // need to refresh display after setting pixels or writing strings + wait(1.0); // we don't want this screen on long! + + // main menu screen no interaction yet pressing start won't do anything but its a start if you pardon the pun! + lcd.clear(); + lcd.printString(" Welcome to ",0,1); + lcd.printString(" Snake! ",0,2); lcd.printString(" Press Start ",0,4); lcd.refresh(); - - // wait flashing LEDs until start button is pressed - while ( pad.start_pressed() == false) { - lcd.setContrast( pad.read_pot1()); - pad.leds_on(); - wait(0.1); - pad.leds_off(); - wait(0.1); - } - -} \ No newline at end of file + wait(45.0); + lcd.clear(); + + // Easter Egg time! + lcd.printString(" Do you need ",0,1); + lcd.printString(" more time? ",0,2); + lcd.printString(" Grandpa! ",0,3); + lcd.refresh(); + wait(5.0); + + //returns back to normal welcome screen + lcd.clear(); + lcd.printString(" Welcome to ",0,1); + lcd.printString(" Snake! ",0,2); + lcd.printString(" Press Start ",0,4); + lcd.refresh(); + break; //stops the loop + +} +}