Johnathan Chin / Mbed 2 deprecated robot_tilt_move

Dependencies:   4DGL-uLCD-SE PinDetect mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "MMA8452.h"
00003 #include "Robot.h"
00004 
00005 Serial pc(USBTX,USBRX);
00006 
00007 int main() {
00008     Robot robot;
00009     double x = 0.0, y = 0.0, z = 0.0, factor = 50.0;
00010     int offsetx = 63;
00011     int offsety = 63;
00012     MMA8452 acc(p9, p10, 40000);
00013     acc.setBitDepth(MMA8452::BIT_DEPTH_12);
00014     acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G);
00015     acc.setDataRate(MMA8452::RATE_100);
00016     while(1) {
00017         robot.erase();
00018         if (!acc.isXYZReady()) {
00019             wait(.01);
00020         } else {
00021             acc.readXYZGravity(&x, &y, &z);
00022             robot.setXPosition(-1 * x * factor + offsetx);
00023             robot.setYPosition(-1 * y * factor + offsety);
00024             robot.draw();
00025         }        
00026     }
00027 }