lcd accelerometer
Revision 0:a0e65c86809d, committed 2017-10-31
- Comitter:
- jakebonney10
- Date:
- Tue Oct 31 14:31:13 2017 +0000
- Commit message:
- tried using set_state finction
Changed in this revision
physics.cpp | Show annotated file Show diff for this revision Revisions of this file |
physics.h | Show annotated file Show diff for this revision Revisions of this file |
diff -r 000000000000 -r a0e65c86809d physics.cpp --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/physics.cpp Tue Oct 31 14:31:13 2017 +0000 @@ -0,0 +1,57 @@ +//physics.cpp + +#include "mbed.h" +#include "physics.h" +#include "MMA8452Q.h" + +MMA8452Q accel(p28, p27, 0x1D); + +physics_ball :: physics_ball() + + { + //constructor + + x=64; + y=64; + vx=4; + vy=4; + radius = 4; + } + void physics_ball :: update(float time_step){ + + // Initialize accelerometer + accel.init(); + + x -= (vx * accel.readY()); + y -= (vy * accel.readX()); + + //Reset balls to original position + if (accel.readZ() < 0 ){ + x = 64; + y = 64; + } + + // Make red ball bounce + if ( x <= radius + 1 ) { + x = vx * radius + 1; + } + else if ( x >= 126 - radius ) { + x = 126 - vx *radius; + } + if ( y <= radius + 1 ) { + y = vy * radius + 1; + } + else if ( y >= 126 - radius ) { + y = 126 - vy * radius; + } + //void physics_ball :: define_space(int width,int height) + + //void physics_ball :: set_param(int radius, int color) + } + //void physics_ball :: set_state(int x, int y, float vx, float vy){ + //x=10; + //y=10; + //vx=6; + //vy=6; + //} + } \ No newline at end of file
diff -r 000000000000 -r a0e65c86809d physics.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/physics.h Tue Oct 31 14:31:13 2017 +0000 @@ -0,0 +1,19 @@ +// Library for accelerometer Assignment4 OCE360 +// Written by Jake Bonney + +//class definitions +class physics_ball +{ + public: + physics_ball(); + float vx; + float vy; + int x; + int y; + int radius; + void update(float time_step); + void define_space(int width, int height); + void set_param(int radius, int color); + void set_state(int x, int y, float vx,float vy); + }; + \ No newline at end of file