ELEC2645 (2018/19) / Mbed 2 deprecated el17szs

Dependencies:   mbed

Committer:
shahidsajid
Date:
Mon Apr 22 17:34:11 2019 +0000
Revision:
10:6c6e09023942
Parent:
9:a81db6a703b7
Child:
11:f481ec642cc5
Created a new folder called Cricket to modularize the code for efficiency

Who changed what in which revision?

UserRevisionLine numberNew contents of line
shahidsajid 0:bed27dc63dea 1 /*
shahidsajid 0:bed27dc63dea 2 ELEC2645 Embedded Systems Project
shahidsajid 0:bed27dc63dea 3 School of Electronic & Electrical Engineering
shahidsajid 0:bed27dc63dea 4 University of Leeds
shahidsajid 1:ce0d477de314 5 Name: Shahid Zubin Sajid
shahidsajid 1:ce0d477de314 6 Username: el17szs
shahidsajid 1:ce0d477de314 7 Student ID Number: 201197609
shahidsajid 1:ce0d477de314 8 Date: 21/03/2019
shahidsajid 1:ce0d477de314 9 */
shahidsajid 1:ce0d477de314 10
shahidsajid 1:ce0d477de314 11 #include "mbed.h"
shahidsajid 1:ce0d477de314 12 #include "Gamepad.h"
shahidsajid 1:ce0d477de314 13 #include "N5110.h"
shahidsajid 3:bd3465a70a5a 14 #include "Ball.h"
shahidsajid 4:55a0509c4874 15 #include "Bat.h"
shahidsajid 10:6c6e09023942 16 #include "Cricket.h"
shahidsajid 1:ce0d477de314 17
shahidsajid 1:ce0d477de314 18
shahidsajid 1:ce0d477de314 19 N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11);
shahidsajid 10:6c6e09023942 20 Gamepad pad;
shahidsajid 10:6c6e09023942 21 Cricket cricket;
shahidsajid 1:ce0d477de314 22
shahidsajid 1:ce0d477de314 23 void init();
shahidsajid 1:ce0d477de314 24
shahidsajid 6:3e50f2cf4366 25 //void welcome();
shahidsajid 3:bd3465a70a5a 26 void draw();
shahidsajid 3:bd3465a70a5a 27 void ball_test();
shahidsajid 1:ce0d477de314 28
shahidsajid 1:ce0d477de314 29 int main(){
shahidsajid 1:ce0d477de314 30 int fps=8;
shahidsajid 1:ce0d477de314 31 init();
shahidsajid 6:3e50f2cf4366 32 // welcome();
shahidsajid 3:bd3465a70a5a 33 draw();
shahidsajid 10:6c6e09023942 34 float f;
shahidsajid 9:a81db6a703b7 35 int status=0;
shahidsajid 3:bd3465a70a5a 36 while(1){
shahidsajid 10:6c6e09023942 37 cricket.game(lcd);
shahidsajid 10:6c6e09023942 38 draw();
shahidsajid 10:6c6e09023942 39 }
shahidsajid 10:6c6e09023942 40 /*
shahidsajid 10:6c6e09023942 41 while(1){
shahidsajid 9:a81db6a703b7 42 ball.reset();
shahidsajid 10:6c6e09023942 43 field.set_field(lcd);
shahidsajid 10:6c6e09023942 44 draw();
shahidsajid 9:a81db6a703b7 45 while (status!=1){
shahidsajid 9:a81db6a703b7 46 f= pad1.get_mag();
shahidsajid 9:a81db6a703b7 47 int lol=bat.get_hitBall();
shahidsajid 10:6c6e09023942 48 ball.start(lcd,lol,pad.get_direction());
shahidsajid 9:a81db6a703b7 49 draw();
shahidsajid 9:a81db6a703b7 50 wait(1.0f/fps);
shahidsajid 10:6c6e09023942 51 }
shahidsajid 3:bd3465a70a5a 52 }
shahidsajid 10:6c6e09023942 53 */
shahidsajid 1:ce0d477de314 54 }
shahidsajid 1:ce0d477de314 55 void init(){
shahidsajid 1:ce0d477de314 56 lcd.init();
shahidsajid 10:6c6e09023942 57 pad.init();
shahidsajid 10:6c6e09023942 58 cricket.init();
shahidsajid 1:ce0d477de314 59 lcd.setContrast(0.4);
shahidsajid 1:ce0d477de314 60 lcd.normalMode(); // normal colour mode
shahidsajid 1:ce0d477de314 61 lcd.setBrightness(0.5);
shahidsajid 1:ce0d477de314 62 lcd.clear();
shahidsajid 1:ce0d477de314 63
shahidsajid 1:ce0d477de314 64 }
shahidsajid 1:ce0d477de314 65 void welcome() {
shahidsajid 2:e9ac69c17a75 66 lcd.printString(" CRICKET GAME ",0,1);
shahidsajid 2:e9ac69c17a75 67 lcd.printString(" SHAHID SAJID",0,2);
shahidsajid 1:ce0d477de314 68 lcd.printString(" el17szs ",0,3);
shahidsajid 1:ce0d477de314 69 lcd.printString(" Press Start ",0,4);
shahidsajid 1:ce0d477de314 70 lcd.refresh();
shahidsajid 1:ce0d477de314 71 // wait flashing LEDs until start button is pressed
shahidsajid 10:6c6e09023942 72 while ( pad.check_event(Gamepad::START_PRESSED) == false) {
shahidsajid 10:6c6e09023942 73 pad.leds_on();
shahidsajid 1:ce0d477de314 74 wait(0.1);
shahidsajid 10:6c6e09023942 75 pad.leds_off();
shahidsajid 1:ce0d477de314 76 wait(0.1);
shahidsajid 1:ce0d477de314 77 }
shahidsajid 1:ce0d477de314 78
shahidsajid 2:e9ac69c17a75 79 }
shahidsajid 3:bd3465a70a5a 80 void draw(){
shahidsajid 2:e9ac69c17a75 81 lcd.clear();
shahidsajid 10:6c6e09023942 82 cricket.draw(lcd);
shahidsajid 2:e9ac69c17a75 83 lcd.refresh();
shahidsajid 3:bd3465a70a5a 84 }
shahidsajid 10:6c6e09023942 85 /*void ball_test(){
shahidsajid 3:bd3465a70a5a 86 Vector2D ball_pos = ball.get_pos();
shahidsajid 3:bd3465a70a5a 87 Vector2D ball_velocity = ball.get_velocity();
shahidsajid 3:bd3465a70a5a 88 ball.update();
shahidsajid 3:bd3465a70a5a 89
shahidsajid 3:bd3465a70a5a 90 ball.set_velocity(ball_velocity);
shahidsajid 3:bd3465a70a5a 91 ball.set_pos(ball_pos);
shahidsajid 3:bd3465a70a5a 92 ball.update();
shahidsajid 10:6c6e09023942 93 }
shahidsajid 10:6c6e09023942 94 */