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.
bouncing_ball.h@2:ba1844b0eb9f, 2017-11-07 (annotated)
- Committer:
- slicht
- Date:
- Tue Nov 07 12:07:13 2017 +0000
- Revision:
- 2:ba1844b0eb9f
- Parent:
- 1:0aa572c0f2b1
Working copy. Cycles colors on upside down. Unknown why non-deterministic color cycling.
Who changed what in which revision?
| User | Revision | Line number | New contents of line | 
|---|---|---|---|
| slicht | 1:0aa572c0f2b1 | 1 | // Bouncing ball is a library adding physics based ball bouncing to the Sparkfun Experiment 3/4 rolling ball demo. | 
| slicht | 1:0aa572c0f2b1 | 2 | // Example Code | 
| slicht | 1:0aa572c0f2b1 | 3 | // 10/19/2017 Stephen Licht | 
| slicht | 0:aff81f4c72f3 | 4 | |
| slicht | 0:aff81f4c72f3 | 5 | #include "mbed.h" | 
| slicht | 0:aff81f4c72f3 | 6 | |
| slicht | 0:aff81f4c72f3 | 7 | #ifndef bouncing_ball_H | 
| slicht | 1:0aa572c0f2b1 | 8 | #define bouncing_ball_H //in case any other library wishes to check for presence of this library (see example below) | 
| slicht | 1:0aa572c0f2b1 | 9 | #include "MMA8452Q.h" //includes our new accelerometer library definitions | 
| slicht | 0:aff81f4c72f3 | 10 | |
| slicht | 2:ba1844b0eb9f | 11 | #define DEFAULT_WIDTH 128 | 
| slicht | 2:ba1844b0eb9f | 12 | #define DEFAULT_HEIGHT 128 | 
| slicht | 1:0aa572c0f2b1 | 13 | #define DEFAULT_SPEEDX 0 | 
| slicht | 1:0aa572c0f2b1 | 14 | #define DEFAULT_SPEEDY 0 | 
| slicht | 1:0aa572c0f2b1 | 15 | #define DEFAULT_POSX 64 | 
| slicht | 1:0aa572c0f2b1 | 16 | #define DEFAULT_POSY 64 | 
| slicht | 1:0aa572c0f2b1 | 17 | #define DEFAULT_COLOR 0 | 
| slicht | 1:0aa572c0f2b1 | 18 | #define DEFAULT_RADIUS 10 | 
| slicht | 2:ba1844b0eb9f | 19 | #define GRAVITY 9.8 | 
| slicht | 0:aff81f4c72f3 | 20 | |
| slicht | 0:aff81f4c72f3 | 21 | // Class declaration | 
| slicht | 0:aff81f4c72f3 | 22 | class physics_ball | 
| slicht | 0:aff81f4c72f3 | 23 | { | 
| slicht | 0:aff81f4c72f3 | 24 | public: | 
| slicht | 2:ba1844b0eb9f | 25 | physics_ball(); | 
| slicht | 0:aff81f4c72f3 | 26 | ~physics_ball(); | 
| slicht | 0:aff81f4c72f3 | 27 | |
| slicht | 0:aff81f4c72f3 | 28 | float speedx; | 
| slicht | 0:aff81f4c72f3 | 29 | float speedy; | 
| slicht | 0:aff81f4c72f3 | 30 | int posx; | 
| slicht | 0:aff81f4c72f3 | 31 | int posy; | 
| slicht | 1:0aa572c0f2b1 | 32 | int color; | 
| slicht | 1:0aa572c0f2b1 | 33 | int radius; | 
| slicht | 1:0aa572c0f2b1 | 34 | |
| slicht | 2:ba1844b0eb9f | 35 | void update(float time_step, MMA8452Q &accelerometer); | 
| slicht | 2:ba1844b0eb9f | 36 | void define_space(int desired_width, int desired_height); | 
| slicht | 2:ba1844b0eb9f | 37 | void set_param(int desired_radius, int desired_color); | 
| slicht | 2:ba1844b0eb9f | 38 | void set_state(int desired_x, int desired_y, float desired_vx, float desired_vy); | 
| slicht | 0:aff81f4c72f3 | 39 | |
| slicht | 0:aff81f4c72f3 | 40 | private: | 
| slicht | 0:aff81f4c72f3 | 41 | |
| slicht | 2:ba1844b0eb9f | 42 | int _width; | 
| slicht | 2:ba1844b0eb9f | 43 | int _height; | 
| slicht | 2:ba1844b0eb9f | 44 | int _upside_down_status; | 
| slicht | 2:ba1844b0eb9f | 45 | float _posx_f; | 
| slicht | 2:ba1844b0eb9f | 46 | float _posy_f; | 
| slicht | 2:ba1844b0eb9f | 47 | |
| slicht | 2:ba1844b0eb9f | 48 | void _reset_upside_down(); | 
| slicht | 0:aff81f4c72f3 | 49 | }; | 
| slicht | 0:aff81f4c72f3 | 50 | |
| slicht | 1:0aa572c0f2b1 | 51 | #endif //bouncing_ball_H | 
| slicht | 0:aff81f4c72f3 | 52 | |
| slicht | 0:aff81f4c72f3 | 53 |