Lab2Part3

Dependencies:   4DGL-uLCD-SE LSM9DS1_Library_cal mbed

main.cpp

Committer:
bdragon52
Date:
2017-09-13
Revision:
0:98e654b8abce

File content as of revision 0:98e654b8abce:

#include "mbed.h"
#include "uLCD_4DGL.h"
#include "LSM9DS1.h"

 
uLCD_4DGL uLCD(p28,p27,p30); // serial tx, serial rx, reset pin;
Serial pc(USBTX, USBRX);
LSM9DS1 imu(p9, p10, 0xD6, 0x3C); 

int main()
{
    
    
    //void readAccel();
 
/**
*Read the accelerometer output registers.
*This function will read all six accelerometer output registers.
*The readings are stored in the class' ax, ay, and az variables. Read
*those _after_ calling readAccel().
**/

    imu.begin();
    if (!imu.begin()) {
       
    }
    imu.calibrate();


    
    int x=64,y=64;
    uLCD.background_color(BLACK);
    
    uLCD.filled_circle(64, 64, 45, BLUE);
    uLCD.filled_circle(64, 64, 43, BLACK);
    uLCD.filled_circle(64, 64, 12, BLUE);
    uLCD.filled_circle(64, 64, 10, BLACK);
    
     uLCD.filled_circle(x, y, 8, YELLOW);
        //bounce off edge walls and slow down a bit?
   while(1){
        float oldx=x;
        float oldy=y;
        imu.readAccel();
        float accX=imu.ax;
        float accY=imu.ay;
        
        //0 15800
        //64 128
        
        //247
        if(accX>0){
           x=oldx+2;
            }
        if(accX<0){
           x=oldx-2;
            }
            
         if(accY>0){
            y=oldy+2;
            }
        if(accY<0){
            y=oldy-2;
            }


          

       if(x>(x/109)){
            x=64+(accX/(200));
            }

        if(x<(x/109)){
            x=64-(accX/200);
            }
         
       if(y>(y/109)){
            y=64+(accY/200);
            }

        if(y<(y/109)){
            y=64-(accY/200);
            }
               













 //x=64+15800/(4*x);
 // x=64-15800/(4*x);       
        if(x<32){
            x=32;
            }

        if(x>96){
            x=96;
            }
            
         if(y<32){
            y=32;
            }

        if(y>96){
            y=96;
            }
               
            
            
            
       int posx=x;
       int posy=y;
       uLCD.filled_circle(oldx, oldy, 8, BLACK);
       uLCD.filled_circle(64, 64, 12, BLUE);
       uLCD.filled_circle(64, 64, 10, BLACK);
       uLCD.filled_circle(posx, posy, 8, YELLOW);
       
       
       pc.printf("X: %f\n", accX);
       pc.printf("Y: %f\n", accY);
       
       wait(.05);
       



        }  
        
       
        
        
    }
//......more code demos can be found in main.cpp