Fork of bouncing_ball by Stephen Licht

Committer:
rsean10
Date:
Wed Nov 15 20:58:54 2017 +0000
Revision:
6:1e5cd98fc2aa
Parent:
5:dd8df17df666

        

Who changed what in which revision?

UserRevisionLine numberNew 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
rsean10 4:2c97532a9aa7 19 #define GRAVITY 9.81
rsean10 5:dd8df17df666 20 #define BUFFER 1
slicht 0:aff81f4c72f3 21
slicht 0:aff81f4c72f3 22 // Class declaration
slicht 0:aff81f4c72f3 23 class physics_ball
slicht 0:aff81f4c72f3 24 {
slicht 0:aff81f4c72f3 25 public:
slicht 2:ba1844b0eb9f 26 physics_ball();
slicht 0:aff81f4c72f3 27 ~physics_ball();
slicht 0:aff81f4c72f3 28
slicht 0:aff81f4c72f3 29 float speedx;
slicht 0:aff81f4c72f3 30 float speedy;
slicht 0:aff81f4c72f3 31 int posx;
slicht 0:aff81f4c72f3 32 int posy;
slicht 1:0aa572c0f2b1 33 int color;
slicht 1:0aa572c0f2b1 34 int radius;
slicht 1:0aa572c0f2b1 35
slicht 2:ba1844b0eb9f 36 void update(float time_step, MMA8452Q &accelerometer);
slicht 2:ba1844b0eb9f 37 void define_space(int desired_width, int desired_height);
slicht 2:ba1844b0eb9f 38 void set_param(int desired_radius, int desired_color);
slicht 2:ba1844b0eb9f 39 void set_state(int desired_x, int desired_y, float desired_vx, float desired_vy);
slicht 0:aff81f4c72f3 40
slicht 0:aff81f4c72f3 41 private:
slicht 0:aff81f4c72f3 42
slicht 2:ba1844b0eb9f 43 int _width;
slicht 2:ba1844b0eb9f 44 int _height;
slicht 2:ba1844b0eb9f 45 int _upside_down_status;
slicht 2:ba1844b0eb9f 46 float _posx_f;
slicht 2:ba1844b0eb9f 47 float _posy_f;
slicht 2:ba1844b0eb9f 48
slicht 2:ba1844b0eb9f 49 void _reset_upside_down();
slicht 0:aff81f4c72f3 50 };
slicht 0:aff81f4c72f3 51
slicht 1:0aa572c0f2b1 52 #endif //bouncing_ball_H
slicht 0:aff81f4c72f3 53
slicht 0:aff81f4c72f3 54