GPIO D10 High-Low Based on Height

Dependencies:   FXOS8700Q mbed

Committer:
chavan
Date:
Fri Mar 30 02:50:50 2018 +0000
Revision:
1:643da51350f0
Parent:
0:748d42bc36b2
GPIO D10 High-Low Based on Height

Who changed what in which revision?

UserRevisionLine numberNew contents of line
chavan 0:748d42bc36b2 1 #include "mbed.h"
chavan 0:748d42bc36b2 2 #include "FXOS8700Q.h"
chavan 0:748d42bc36b2 3 FXOS8700Q_acc acc( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
chavan 0:748d42bc36b2 4 FXOS8700Q_mag mag( PTE25, PTE24, FXOS8700CQ_SLAVE_ADDR1);
chavan 0:748d42bc36b2 5 //Temrinal enable
chavan 0:748d42bc36b2 6 Serial pc(USBTX, USBRX);
chavan 0:748d42bc36b2 7 MotionSensorDataUnits mag_data;
chavan 0:748d42bc36b2 8 MotionSensorDataUnits acc_data;
chavan 0:748d42bc36b2 9
chavan 0:748d42bc36b2 10
chavan 0:748d42bc36b2 11 InterruptIn switch1(SW2);
chavan 0:748d42bc36b2 12
chavan 0:748d42bc36b2 13 //Setting the motor Pin
chavan 0:748d42bc36b2 14 DigitalOut motorPin(D10);
chavan 0:748d42bc36b2 15
chavan 0:748d42bc36b2 16
chavan 0:748d42bc36b2 17 void switch1ISR(){
chavan 0:748d42bc36b2 18 switch1.fall(NULL);
chavan 0:748d42bc36b2 19 //v=1;
chavan 0:748d42bc36b2 20 switch1.fall(&switch1ISR);
chavan 0:748d42bc36b2 21 }
chavan 0:748d42bc36b2 22
chavan 0:748d42bc36b2 23 int main()
chavan 0:748d42bc36b2 24 {
chavan 0:748d42bc36b2 25 int cnt =0;
chavan 0:748d42bc36b2 26 float faX, faY, faZ;
chavan 0:748d42bc36b2 27 float fmX, fmY, fmZ;
chavan 0:748d42bc36b2 28 acc.enable();
chavan 0:748d42bc36b2 29 printf("\r\n\nFXOS8700Q Who Am I= %X\r\n", acc.whoAmI());
chavan 0:748d42bc36b2 30 while (true)
chavan 0:748d42bc36b2 31 {
chavan 0:748d42bc36b2 32 acc.getAxis(acc_data);
chavan 0:748d42bc36b2 33 mag.getAxis(mag_data);
chavan 0:748d42bc36b2 34 printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f ", acc_data.x, acc_data.y, acc_data.z);
chavan 0:748d42bc36b2 35 printf(" MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", mag_data.x, mag_data.y, mag_data.z);
chavan 0:748d42bc36b2 36 acc.getX(&faX);
chavan 0:748d42bc36b2 37 acc.getY(&faY);
chavan 0:748d42bc36b2 38 acc.getZ(&faZ);
chavan 0:748d42bc36b2 39 mag.getX(&fmX);
chavan 0:748d42bc36b2 40 mag.getY(&fmY);
chavan 0:748d42bc36b2 41 mag.getZ(&fmZ);
chavan 0:748d42bc36b2 42 printf("FXOS8700Q ACC: X=%1.4f Y=%1.4f Z=%1.4f ", faX, faY, 1000*faZ);
chavan 0:748d42bc36b2 43 printf(" MAG: X=%4.1f Y=%4.1f Z=%4.1f\r\n", fmX, fmY, fmZ);
chavan 1:643da51350f0 44
chavan 0:748d42bc36b2 45 wait(10);
chavan 1:643da51350f0 46 if(1000*faZ<1001)
chavan 0:748d42bc36b2 47 { motorPin = 1;
chavan 0:748d42bc36b2 48 cnt = 1;
chavan 0:748d42bc36b2 49 wait(10);
chavan 0:748d42bc36b2 50 }
chavan 0:748d42bc36b2 51 else ( cnt = 0);
chavan 0:748d42bc36b2 52 { motorPin = 0;
chavan 0:748d42bc36b2 53 wait(10);
chavan 0:748d42bc36b2 54 }
chavan 0:748d42bc36b2 55 }
chavan 0:748d42bc36b2 56 }