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@4:55a0509c4874, 2019-04-16 (annotated)
- Committer:
- shahidsajid
- Date:
- Tue Apr 16 09:48:37 2019 +0000
- Revision:
- 4:55a0509c4874
- Parent:
- 3:bd3465a70a5a
- Child:
- 5:915bcac4e9b9
Initialised 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 | 3:bd3465a70a5a | 40 | while(1){ |
shahidsajid | 3:bd3465a70a5a | 41 | ball.start(lcd); |
shahidsajid | 3:bd3465a70a5a | 42 | draw(); |
shahidsajid | 3:bd3465a70a5a | 43 | wait(1.0f/fps); |
shahidsajid | 3:bd3465a70a5a | 44 | } |
shahidsajid | 3:bd3465a70a5a | 45 | |
shahidsajid | 3:bd3465a70a5a | 46 | |
shahidsajid | 3:bd3465a70a5a | 47 | |
shahidsajid | 1:ce0d477de314 | 48 | } |
shahidsajid | 1:ce0d477de314 | 49 | void init(){ |
shahidsajid | 1:ce0d477de314 | 50 | lcd.init(); |
shahidsajid | 1:ce0d477de314 | 51 | pad.init(); |
shahidsajid | 4:55a0509c4874 | 52 | bat.init(4,5); |
shahidsajid | 4:55a0509c4874 | 53 | ball.init(2,3); |
shahidsajid | 3:bd3465a70a5a | 54 | //field.init(); |
shahidsajid | 1:ce0d477de314 | 55 | |
shahidsajid | 1:ce0d477de314 | 56 | lcd.setContrast(0.4); |
shahidsajid | 1:ce0d477de314 | 57 | lcd.normalMode(); // normal colour mode |
shahidsajid | 1:ce0d477de314 | 58 | lcd.setBrightness(0.5); |
shahidsajid | 1:ce0d477de314 | 59 | lcd.clear(); |
shahidsajid | 1:ce0d477de314 | 60 | |
shahidsajid | 1:ce0d477de314 | 61 | } |
shahidsajid | 1:ce0d477de314 | 62 | void welcome() { |
shahidsajid | 1:ce0d477de314 | 63 | |
shahidsajid | 2:e9ac69c17a75 | 64 | lcd.printString(" CRICKET GAME ",0,1); |
shahidsajid | 2:e9ac69c17a75 | 65 | lcd.printString(" SHAHID SAJID",0,2); |
shahidsajid | 1:ce0d477de314 | 66 | lcd.printString(" el17szs ",0,3); |
shahidsajid | 1:ce0d477de314 | 67 | lcd.printString(" Press Start ",0,4); |
shahidsajid | 1:ce0d477de314 | 68 | lcd.refresh(); |
shahidsajid | 1:ce0d477de314 | 69 | |
shahidsajid | 1:ce0d477de314 | 70 | // wait flashing LEDs until start button is pressed |
shahidsajid | 1:ce0d477de314 | 71 | while ( pad.check_event(Gamepad::START_PRESSED) == false) { |
shahidsajid | 1:ce0d477de314 | 72 | pad.leds_on(); |
shahidsajid | 1:ce0d477de314 | 73 | wait(0.1); |
shahidsajid | 1:ce0d477de314 | 74 | pad.leds_off(); |
shahidsajid | 1:ce0d477de314 | 75 | wait(0.1); |
shahidsajid | 1:ce0d477de314 | 76 | } |
shahidsajid | 1:ce0d477de314 | 77 | |
shahidsajid | 2:e9ac69c17a75 | 78 | } |
shahidsajid | 3:bd3465a70a5a | 79 | void draw(){ |
shahidsajid | 2:e9ac69c17a75 | 80 | lcd.clear(); |
shahidsajid | 3:bd3465a70a5a | 81 | lcd.drawCircle((WIDTH/2),HEIGHT/2,23,FILL_TRANSPARENT); |
shahidsajid | 3:bd3465a70a5a | 82 | lcd.drawRect(37,11,12,30,FILL_TRANSPARENT); |
shahidsajid | 3:bd3465a70a5a | 83 | ball.draw(lcd); |
shahidsajid | 3:bd3465a70a5a | 84 | ball.set_field(lcd); |
shahidsajid | 4:55a0509c4874 | 85 | bat.draw(lcd); |
shahidsajid | 2:e9ac69c17a75 | 86 | lcd.refresh(); |
shahidsajid | 3:bd3465a70a5a | 87 | } |
shahidsajid | 3:bd3465a70a5a | 88 | void ball_test(){ |
shahidsajid | 3:bd3465a70a5a | 89 | Vector2D ball_pos = ball.get_pos(); |
shahidsajid | 3:bd3465a70a5a | 90 | Vector2D ball_velocity = ball.get_velocity(); |
shahidsajid | 3:bd3465a70a5a | 91 | ball.update(); |
shahidsajid | 3:bd3465a70a5a | 92 | |
shahidsajid | 3:bd3465a70a5a | 93 | ball.set_velocity(ball_velocity); |
shahidsajid | 3:bd3465a70a5a | 94 | ball.set_pos(ball_pos); |
shahidsajid | 3:bd3465a70a5a | 95 | ball.update(); |
shahidsajid | 1:ce0d477de314 | 96 | } |