Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: 4DGL-uLCD-SE PinDetect mbed
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 }
Generated on Fri Jul 15 2022 14:00:51 by
1.7.2