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.
Ball/Ball.h@37:de1f584bce71, 2019-05-06 (annotated)
- Committer:
- JamesCummins
- Date:
- Mon May 06 21:44:49 2019 +0000
- Revision:
- 37:de1f584bce71
- Parent:
- 29:42651f87522b
- Child:
- 38:a85bc227b907
Documentation written out with the exception of example code
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| JamesCummins | 9:ce0a12fb205b | 1 | #ifndef BALL_H |
| JamesCummins | 9:ce0a12fb205b | 2 | #define BALL_H |
| JamesCummins | 9:ce0a12fb205b | 3 | |
| JamesCummins | 9:ce0a12fb205b | 4 | #include "mbed.h" |
| JamesCummins | 9:ce0a12fb205b | 5 | #include "N5110.h" |
| JamesCummins | 9:ce0a12fb205b | 6 | #include "Gamepad.h" |
| JamesCummins | 9:ce0a12fb205b | 7 | #include "FXOS8700CQ.h" |
| JamesCummins | 9:ce0a12fb205b | 8 | |
| JamesCummins | 9:ce0a12fb205b | 9 | |
| JamesCummins | 9:ce0a12fb205b | 10 | class Ball { |
| JamesCummins | 9:ce0a12fb205b | 11 | |
| JamesCummins | 9:ce0a12fb205b | 12 | public: |
| JamesCummins | 37:de1f584bce71 | 13 | /** |
| JamesCummins | 37:de1f584bce71 | 14 | * @brief Create a Ball object |
| JamesCummins | 37:de1f584bce71 | 15 | */ |
| JamesCummins | 9:ce0a12fb205b | 16 | Ball(); |
| JamesCummins | 37:de1f584bce71 | 17 | /** |
| JamesCummins | 37:de1f584bce71 | 18 | * @brief Delete a ball member to free up memory |
| JamesCummins | 37:de1f584bce71 | 19 | */ |
| JamesCummins | 9:ce0a12fb205b | 20 | ~Ball(); |
| JamesCummins | 37:de1f584bce71 | 21 | |
| JamesCummins | 37:de1f584bce71 | 22 | /** Initialise ball object |
| JamesCummins | 37:de1f584bce71 | 23 | * |
| JamesCummins | 37:de1f584bce71 | 24 | * Sets the initial position of the ball to the centre of the LCD display. |
| JamesCummins | 37:de1f584bce71 | 25 | * Sets the initial velocity of the ball to 0 and the sensitivity of the |
| JamesCummins | 37:de1f584bce71 | 26 | * ball to 5/10. |
| JamesCummins | 37:de1f584bce71 | 27 | * @param radius - integer for radius of the ball |
| JamesCummins | 37:de1f584bce71 | 28 | */ |
| JamesCummins | 9:ce0a12fb205b | 29 | void init(int radius); |
| JamesCummins | 37:de1f584bce71 | 30 | /** |
| JamesCummins | 37:de1f584bce71 | 31 | * @brief read the input from the accelerometer and convert it to an instantaneous velocity |
| JamesCummins | 37:de1f584bce71 | 32 | * for the ball. |
| JamesCummins | 37:de1f584bce71 | 33 | * @param accelerometer - FXOS8700CQ object to retrieve acceleromter readings |
| JamesCummins | 37:de1f584bce71 | 34 | */ |
| JamesCummins | 17:5104ecef5bd0 | 35 | void read_input(FXOS8700CQ &accelerometer); |
| JamesCummins | 37:de1f584bce71 | 36 | /** |
| JamesCummins | 37:de1f584bce71 | 37 | * @brief update the coordinates of the ball within the range of the screen |
| JamesCummins | 37:de1f584bce71 | 38 | */ |
| JamesCummins | 17:5104ecef5bd0 | 39 | void update(); |
| JamesCummins | 37:de1f584bce71 | 40 | /** |
| JamesCummins | 37:de1f584bce71 | 41 | * @brief render the ball onto the LCD screen |
| JamesCummins | 37:de1f584bce71 | 42 | * @param lcd - N5110 object to interface with the LCD |
| JamesCummins | 37:de1f584bce71 | 43 | */ |
| JamesCummins | 9:ce0a12fb205b | 44 | void draw(N5110 &lcd); |
| JamesCummins | 37:de1f584bce71 | 45 | /** |
| JamesCummins | 37:de1f584bce71 | 46 | * @brief get the instantaneous velocity of the ball |
| JamesCummins | 37:de1f584bce71 | 47 | * @returns x and y velocities of the ball in a 2D vector |
| JamesCummins | 37:de1f584bce71 | 48 | */ |
| JamesCummins | 9:ce0a12fb205b | 49 | Vector2D get_velocity(); |
| JamesCummins | 37:de1f584bce71 | 50 | /** |
| JamesCummins | 37:de1f584bce71 | 51 | * @brief get the instantaneous position of the ball |
| JamesCummins | 37:de1f584bce71 | 52 | * @returns x and y positions in a 2D vector. 0 < x < 83 and 0 < y < 47. |
| JamesCummins | 37:de1f584bce71 | 53 | */ |
| JamesCummins | 9:ce0a12fb205b | 54 | Vector2D get_position(); |
| JamesCummins | 37:de1f584bce71 | 55 | /** |
| JamesCummins | 37:de1f584bce71 | 56 | * @brief get the radius of the ball |
| JamesCummins | 37:de1f584bce71 | 57 | * @returns radius of the ball as an integer |
| JamesCummins | 37:de1f584bce71 | 58 | */ |
| JamesCummins | 10:40c77d69e83c | 59 | int get_radius(); |
| JamesCummins | 37:de1f584bce71 | 60 | /** |
| JamesCummins | 37:de1f584bce71 | 61 | * @brief get the speed multiplying factor of the ball. Essentially the sensitivity |
| JamesCummins | 37:de1f584bce71 | 62 | * to the accelerometer input |
| JamesCummins | 37:de1f584bce71 | 63 | * @returns ball speed multiplier as an integer in the range 1-10 |
| JamesCummins | 37:de1f584bce71 | 64 | */ |
| JamesCummins | 29:42651f87522b | 65 | int get_ball_speed(); |
| JamesCummins | 37:de1f584bce71 | 66 | /** |
| JamesCummins | 37:de1f584bce71 | 67 | * @brief Set the sensitivity of the ball's motion to the accelerometer input |
| JamesCummins | 37:de1f584bce71 | 68 | * @param ball_speed - integer in the range 1-10 |
| JamesCummins | 37:de1f584bce71 | 69 | */ |
| JamesCummins | 37:de1f584bce71 | 70 | void set_ball_speed(int ball_speed); |
| JamesCummins | 37:de1f584bce71 | 71 | /** |
| JamesCummins | 37:de1f584bce71 | 72 | * @brief set the instantaneous velocities in the x and y directions |
| JamesCummins | 37:de1f584bce71 | 73 | * @param vel - a 2D vector (using the gamepad class) of the desired x and y velocities |
| JamesCummins | 37:de1f584bce71 | 74 | */ |
| JamesCummins | 37:de1f584bce71 | 75 | void set_velocity(Vector2D vel); |
| JamesCummins | 37:de1f584bce71 | 76 | /** |
| JamesCummins | 37:de1f584bce71 | 77 | * @brief set the instantaneous x and y positions of the ball |
| JamesCummins | 37:de1f584bce71 | 78 | * @param pos - a 2D vector (using the gamepad class) of the desired x and y coordinates |
| JamesCummins | 37:de1f584bce71 | 79 | */ |
| JamesCummins | 9:ce0a12fb205b | 80 | void set_position(Vector2D pos); |
| JamesCummins | 37:de1f584bce71 | 81 | /** |
| JamesCummins | 37:de1f584bce71 | 82 | * @brief set the radius of the ball |
| JamesCummins | 37:de1f584bce71 | 83 | * @param radius - integer value |
| JamesCummins | 37:de1f584bce71 | 84 | */ |
| JamesCummins | 10:40c77d69e83c | 85 | void set_radius(int radius); |
| JamesCummins | 9:ce0a12fb205b | 86 | |
| JamesCummins | 9:ce0a12fb205b | 87 | private: |
| JamesCummins | 11:2cf0d4ce8677 | 88 | int _radius; |
| JamesCummins | 11:2cf0d4ce8677 | 89 | int _x; |
| JamesCummins | 11:2cf0d4ce8677 | 90 | int _y; |
| JamesCummins | 9:ce0a12fb205b | 91 | Vector2D _velocity; |
| JamesCummins | 23:61fa82f76808 | 92 | int _ball_speed; |
| JamesCummins | 9:ce0a12fb205b | 93 | }; |
| JamesCummins | 9:ce0a12fb205b | 94 | #endif |