Leonardo Luiz Ferreira
/
tccfeiteste
tcc fei teste
Fork of FRDM_MMA8451Q by
main.cpp@8:c71c60a52509, 2016-08-20 (annotated)
- Committer:
- leoferreira
- Date:
- Sat Aug 20 17:22:58 2016 +0000
- Revision:
- 8:c71c60a52509
- Parent:
- 5:bf5becf7469c
tcc fei teste
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
chris | 2:41db78380a6e | 1 | #include "mbed.h" |
chris | 2:41db78380a6e | 2 | #include "MMA8451Q.h" |
leoferreira | 8:c71c60a52509 | 3 | Serial pc(USBTX,USBRX); |
chris | 2:41db78380a6e | 4 | |
chris | 2:41db78380a6e | 5 | #define MMA8451_I2C_ADDRESS (0x1d<<1) |
leoferreira | 8:c71c60a52509 | 6 | |
leoferreira | 8:c71c60a52509 | 7 | PwmOut ena(D7); |
leoferreira | 8:c71c60a52509 | 8 | PwmOut enb(D6); |
leoferreira | 8:c71c60a52509 | 9 | DigitalOut in1 (D5); |
leoferreira | 8:c71c60a52509 | 10 | DigitalOut in2 (D4); |
leoferreira | 8:c71c60a52509 | 11 | DigitalOut in3 (D3); |
leoferreira | 8:c71c60a52509 | 12 | DigitalOut in4 (D2); |
leoferreira | 8:c71c60a52509 | 13 | |
leoferreira | 8:c71c60a52509 | 14 | //Serial pc(USBTX, USBRX); // liga direto |
chris | 2:41db78380a6e | 15 | |
leoferreira | 8:c71c60a52509 | 16 | |
leoferreira | 8:c71c60a52509 | 17 | Serial blue(PTC4, PTC3); |
leoferreira | 8:c71c60a52509 | 18 | |
leoferreira | 8:c71c60a52509 | 19 | float vela=1.0f; //ENGINE SPEED |
leoferreira | 8:c71c60a52509 | 20 | float velb=1.0f; //ENGINE SPEED |
leoferreira | 8:c71c60a52509 | 21 | |
leoferreira | 8:c71c60a52509 | 22 | int main() |
leoferreira | 8:c71c60a52509 | 23 | { |
leoferreira | 8:c71c60a52509 | 24 | pc.baud(9600); |
emilmont | 5:bf5becf7469c | 25 | MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); |
emilmont | 5:bf5becf7469c | 26 | PwmOut rled(LED_RED); |
leoferreira | 8:c71c60a52509 | 27 | |
emilmont | 5:bf5becf7469c | 28 | while (true) { |
leoferreira | 8:c71c60a52509 | 29 | |
leoferreira | 8:c71c60a52509 | 30 | |
leoferreira | 8:c71c60a52509 | 31 | float estado=0; |
leoferreira | 8:c71c60a52509 | 32 | |
leoferreira | 8:c71c60a52509 | 33 | rled = 1.0 - abs(acc.getAccX()); |
leoferreira | 8:c71c60a52509 | 34 | estado = (acc.getAccX()); |
leoferreira | 8:c71c60a52509 | 35 | pc.printf("%f\n",estado); |
leoferreira | 8:c71c60a52509 | 36 | |
leoferreira | 8:c71c60a52509 | 37 | // if(estado==0) { // PARADO |
leoferreira | 8:c71c60a52509 | 38 | // ena.write(0); |
leoferreira | 8:c71c60a52509 | 39 | // in1.write(0); |
leoferreira | 8:c71c60a52509 | 40 | // in2.write(0); |
leoferreira | 8:c71c60a52509 | 41 | // enb.write(0); |
leoferreira | 8:c71c60a52509 | 42 | // in3.write(0); |
leoferreira | 8:c71c60a52509 | 43 | // in4.write(0); |
leoferreira | 8:c71c60a52509 | 44 | |
leoferreira | 8:c71c60a52509 | 45 | //} |
leoferreira | 8:c71c60a52509 | 46 | if(estado<0) { // Vai para FRENTE |
leoferreira | 8:c71c60a52509 | 47 | ena.write(estado); |
leoferreira | 8:c71c60a52509 | 48 | in1.write(0); |
leoferreira | 8:c71c60a52509 | 49 | in2.write(1); |
leoferreira | 8:c71c60a52509 | 50 | enb.write(estado); |
leoferreira | 8:c71c60a52509 | 51 | in3.write(0); |
leoferreira | 8:c71c60a52509 | 52 | in4.write(1); |
leoferreira | 8:c71c60a52509 | 53 | } |
leoferreira | 8:c71c60a52509 | 54 | if(estado>-0) { // Vai para tras ena.write(vela); |
leoferreira | 8:c71c60a52509 | 55 | ena.write(estado); |
leoferreira | 8:c71c60a52509 | 56 | in1.write(1); |
leoferreira | 8:c71c60a52509 | 57 | in2.write(0); |
leoferreira | 8:c71c60a52509 | 58 | enb.write(estado); |
leoferreira | 8:c71c60a52509 | 59 | in3.write(1); |
leoferreira | 8:c71c60a52509 | 60 | in4.write(0); |
leoferreira | 8:c71c60a52509 | 61 | } |
chris | 2:41db78380a6e | 62 | } |
leoferreira | 8:c71c60a52509 | 63 | |
chris | 2:41db78380a6e | 64 | } |