Leonardo Luiz Ferreira
/
tccfeiteste
tcc fei teste
Fork of FRDM_MMA8451Q by
Revision 8:c71c60a52509, committed 2016-08-20
- Comitter:
- leoferreira
- Date:
- Sat Aug 20 17:22:58 2016 +0000
- Parent:
- 7:70775be9f474
- Commit message:
- tcc fei teste
Changed in this revision
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/main.cpp Tue Feb 19 23:46:45 2013 +0000 +++ b/main.cpp Sat Aug 20 17:22:58 2016 +0000 @@ -1,18 +1,64 @@ #include "mbed.h" #include "MMA8451Q.h" +Serial pc(USBTX,USBRX); #define MMA8451_I2C_ADDRESS (0x1d<<1) + +PwmOut ena(D7); +PwmOut enb(D6); +DigitalOut in1 (D5); +DigitalOut in2 (D4); +DigitalOut in3 (D3); +DigitalOut in4 (D2); + +//Serial pc(USBTX, USBRX); // liga direto -int main(void) { + +Serial blue(PTC4, PTC3); + +float vela=1.0f; //ENGINE SPEED +float velb=1.0f; //ENGINE SPEED + +int main() +{ + pc.baud(9600); MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); PwmOut rled(LED_RED); - PwmOut gled(LED_GREEN); - PwmOut bled(LED_BLUE); - + while (true) { - rled = 1.0 - abs(acc.getAccX()); - gled = 1.0 - abs(acc.getAccY()); - bled = 1.0 - abs(acc.getAccZ()); - wait(0.1); + + + float estado=0; + + rled = 1.0 - abs(acc.getAccX()); + estado = (acc.getAccX()); + pc.printf("%f\n",estado); + + // if(estado==0) { // PARADO + // ena.write(0); + // in1.write(0); + // in2.write(0); + // enb.write(0); + // in3.write(0); + // in4.write(0); + + //} + if(estado<0) { // Vai para FRENTE + ena.write(estado); + in1.write(0); + in2.write(1); + enb.write(estado); + in3.write(0); + in4.write(1); + } + if(estado>-0) { // Vai para tras ena.write(vela); + ena.write(estado); + in1.write(1); + in2.write(0); + enb.write(estado); + in3.write(1); + in4.write(0); + } } + }