
ECE 4180 Final Project
main.cpp
- Committer:
- amitchell41
- Date:
- 2018-12-11
- Revision:
- 2:59677142d3dd
- Parent:
- 1:aaa03bac6dd6
- Child:
- 3:660252b9fa29
File content as of revision 2:59677142d3dd:
#include "mbed.h" #include "Servo.h" #include "MMA8452.h" #include "PinDetect.h" Serial pc(USBTX,USBRX); DigitalOut myLed(LED1); PinDetect pb1(p20); DigitalOut Comm(p11); //If master //DigitalIn Comm(p11); //If slave DigitalOut Red4(p5); DigitalOut Red3(p6); DigitalOut Yel2(p7); DigitalOut Grn1(p8); Servo _base(p21); Servo _shoulder(p22); Servo _elbow(p23); Servo _sword(p24); void countdown(){ Comm = 1; Red4 = 1; wait(1); Red4 = 0; Red3 = 1; wait(1); Red3 = 0; Yel2 = 1; wait(1); Red4 = 1; Red3 = 1; Grn1 = 1; wait(1); Red4 = 0; Red3 = 0; Yel2 = 0; Grn1 = 0; Comm = 0; } void swing(){ _sword.write(1.0); wait(.1); _sword.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); countdown(); //If master /* while(Comm = 1) { wait(.1); } */ 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); _elbow.write((x+1)/4); 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