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@5:915bcac4e9b9, 2019-04-16 (annotated)
- Committer:
- shahidsajid
- Date:
- Tue Apr 16 10:17:21 2019 +0000
- Revision:
- 5:915bcac4e9b9
- Parent:
- 4:55a0509c4874
- Child:
- 6:3e50f2cf4366
Updated the bat class;
Who changed what in which revision?
| User | Revision | Line number | New 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 | 1:ce0d477de314 | 16 | |
| shahidsajid | 1:ce0d477de314 | 17 | |
| shahidsajid | 1:ce0d477de314 | 18 | N5110 lcd(PTC9,PTC0,PTC7,PTD2,PTD1,PTC11); | 
| shahidsajid | 1:ce0d477de314 | 19 | Gamepad pad; | 
| shahidsajid | 3:bd3465a70a5a | 20 | Ball ball; | 
| shahidsajid | 4:55a0509c4874 | 21 | Bat bat; | 
| shahidsajid | 1:ce0d477de314 | 22 | |
| shahidsajid | 1:ce0d477de314 | 23 | void init(); | 
| shahidsajid | 1:ce0d477de314 | 24 | |
| shahidsajid | 1:ce0d477de314 | 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 | 4:55a0509c4874 | 32 | //welcome(); | 
| shahidsajid | 3:bd3465a70a5a | 33 | draw(); | 
| shahidsajid | 3:bd3465a70a5a | 34 | /* | 
| shahidsajid | 3:bd3465a70a5a | 35 | while (1){ | 
| shahidsajid | 3:bd3465a70a5a | 36 | draw(); | 
| shahidsajid | 3:bd3465a70a5a | 37 | wait(1.0f/fps); | 
| shahidsajid | 3:bd3465a70a5a | 38 | } | 
| shahidsajid | 3:bd3465a70a5a | 39 | */ | 
| shahidsajid | 5:915bcac4e9b9 | 40 | float f; | 
| shahidsajid | 3:bd3465a70a5a | 41 | while(1){ | 
| shahidsajid | 5:915bcac4e9b9 | 42 | f= pad.get_mag(); | 
| shahidsajid | 5:915bcac4e9b9 | 43 | printf("MAG %f \n",f); | 
| shahidsajid | 3:bd3465a70a5a | 44 | ball.start(lcd); | 
| shahidsajid | 3:bd3465a70a5a | 45 | draw(); | 
| shahidsajid | 3:bd3465a70a5a | 46 | wait(1.0f/fps); | 
| shahidsajid | 3:bd3465a70a5a | 47 | } | 
| shahidsajid | 3:bd3465a70a5a | 48 | |
| shahidsajid | 3:bd3465a70a5a | 49 | |
| shahidsajid | 3:bd3465a70a5a | 50 | |
| shahidsajid | 1:ce0d477de314 | 51 | } | 
| shahidsajid | 1:ce0d477de314 | 52 | void init(){ | 
| shahidsajid | 1:ce0d477de314 | 53 | lcd.init(); | 
| shahidsajid | 1:ce0d477de314 | 54 | pad.init(); | 
| shahidsajid | 4:55a0509c4874 | 55 | bat.init(4,5); | 
| shahidsajid | 4:55a0509c4874 | 56 | ball.init(2,3); | 
| shahidsajid | 3:bd3465a70a5a | 57 | //field.init(); | 
| shahidsajid | 1:ce0d477de314 | 58 | lcd.setContrast(0.4); | 
| shahidsajid | 1:ce0d477de314 | 59 | lcd.normalMode(); // normal colour mode | 
| shahidsajid | 1:ce0d477de314 | 60 | lcd.setBrightness(0.5); | 
| shahidsajid | 1:ce0d477de314 | 61 | lcd.clear(); | 
| shahidsajid | 1:ce0d477de314 | 62 | |
| shahidsajid | 1:ce0d477de314 | 63 | } | 
| shahidsajid | 1:ce0d477de314 | 64 | void welcome() { | 
| shahidsajid | 1:ce0d477de314 | 65 | |
| 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 | |
| shahidsajid | 1:ce0d477de314 | 72 | // wait flashing LEDs until start button is pressed | 
| shahidsajid | 1:ce0d477de314 | 73 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { | 
| shahidsajid | 1:ce0d477de314 | 74 | pad.leds_on(); | 
| shahidsajid | 1:ce0d477de314 | 75 | wait(0.1); | 
| shahidsajid | 1:ce0d477de314 | 76 | pad.leds_off(); | 
| shahidsajid | 1:ce0d477de314 | 77 | wait(0.1); | 
| shahidsajid | 1:ce0d477de314 | 78 | } | 
| shahidsajid | 1:ce0d477de314 | 79 | |
| shahidsajid | 2:e9ac69c17a75 | 80 | } | 
| shahidsajid | 3:bd3465a70a5a | 81 | void draw(){ | 
| shahidsajid | 2:e9ac69c17a75 | 82 | lcd.clear(); | 
| shahidsajid | 3:bd3465a70a5a | 83 | lcd.drawCircle((WIDTH/2),HEIGHT/2,23,FILL_TRANSPARENT); | 
| shahidsajid | 3:bd3465a70a5a | 84 | lcd.drawRect(37,11,12,30,FILL_TRANSPARENT); | 
| shahidsajid | 3:bd3465a70a5a | 85 | ball.draw(lcd); | 
| shahidsajid | 3:bd3465a70a5a | 86 | ball.set_field(lcd); | 
| shahidsajid | 4:55a0509c4874 | 87 | bat.draw(lcd); | 
| shahidsajid | 2:e9ac69c17a75 | 88 | lcd.refresh(); | 
| shahidsajid | 3:bd3465a70a5a | 89 | } | 
| shahidsajid | 3:bd3465a70a5a | 90 | void ball_test(){ | 
| shahidsajid | 3:bd3465a70a5a | 91 | Vector2D ball_pos = ball.get_pos(); | 
| shahidsajid | 3:bd3465a70a5a | 92 | Vector2D ball_velocity = ball.get_velocity(); | 
| shahidsajid | 3:bd3465a70a5a | 93 | ball.update(); | 
| shahidsajid | 3:bd3465a70a5a | 94 | |
| shahidsajid | 3:bd3465a70a5a | 95 | ball.set_velocity(ball_velocity); | 
| shahidsajid | 3:bd3465a70a5a | 96 | ball.set_pos(ball_pos); | 
| shahidsajid | 3:bd3465a70a5a | 97 | ball.update(); | 
| shahidsajid | 1:ce0d477de314 | 98 | } |