lcd accelerometer

physics.cpp

Committer:
jakebonney10
Date:
2017-10-31
Revision:
0:a0e65c86809d

File content as of revision 0:a0e65c86809d:

//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;
            //}      
   }