Austin Mitchell
/
RoboBara
ECE 4180 Final Project
main.cpp
- Committer:
- amitchell41
- Date:
- 2018-12-10
- Revision:
- 1:aaa03bac6dd6
- Parent:
- 0:eff94d72c9f4
- Child:
- 2:59677142d3dd
File content as of revision 1:aaa03bac6dd6:
#include "mbed.h" #include "Servo.h" #include "MMA8452.h" #include "PinDetect.h" Serial pc(USBTX,USBRX); DigitalOut myLed(LED1); PinDetect pb1(p20); Servo _base(p21); Servo _shoulder(p22); Servo _elbow(p23); Servo _gripper(p24); void swing(){ _gripper.write(1.0); wait(.1); _gripper.write(0.0); } int main() { pb1.mode(PullUp); int timer = 0; double x = 0, y = 0, z = 0; MMA8452 acc(p28, p27, 40000); //instantiate an acc object //set parameters -- use these and don't change acc.setBitDepth(MMA8452::BIT_DEPTH_12); acc.setDynamicRange(MMA8452::DYNAMIC_RANGE_4G); acc.setDataRate(MMA8452::RATE_100); while(1) { acc.readXYZGravity(&x,&y,&z); //notice this is passed by reference use pointers _base.write((y+1)/2); _shoulder.write((x+1)/2); if(!pb1){ myLed=1; swing(); myLed=0; } // You can uncomment this line to see the values coming off the MMA8452 //printf("\n(%.2f,%.2f,%.2f)", x,y,z); timer++; } //infinite while loop } //end main