christophe vermaelen
/
_test_suivi_mur
...
Diff: main.cpp
- Revision:
- 7:24a3fa0f912a
- Parent:
- 6:5f7df5c74a77
diff -r 5f7df5c74a77 -r 24a3fa0f912a main.cpp --- a/main.cpp Wed May 31 08:48:23 2017 +0000 +++ b/main.cpp Wed Jun 07 16:14:27 2017 +0000 @@ -1,60 +1,29 @@ #include "mbed.h" #include "fct.h" -BusOut ledsetat(p12,p13); - +DigitalOut cs(p13); +DigitalIn bp(p14); int main() { - int etat=0; - init(); + char A=0x80; + char B=0x00; + monI2C.write(ADR_PCF,&A,1); + vitG.period(PERIOD); + vitD.period(PERIOD); + vitG.pulsewidth(PERIOD); + vitD.pulsewidth(PERIOD); + cs = 1; //initialisation de CS à ‘1’ + spi.format(16,0); + spi.frequency(1000000); + bp.mode(PullUp); while(1) { - // printf("etat=%d US1=%.0f US2=%.0f US3=%.0f erreur=%.0f AN1=%.0f AN2=%.0f cmdD=%.0f cmdG=%.0f\n\r",etat,US1,US2,US3,(US2-US1),AN1,AN2,cmdD,cmdG); - //wait(0.05); - ledsetat.write(etat); - switch(etat) { - case 0 : - if((AN2>10 && AN2<20) || US3<13) { - etat=1; - stopMotor(); - } - if(US2>100 && US1<40) { - etat=2; - stopMotor(); - } - break; - case 1 : - if(US2>100 && US1<40) { - etat=2; - stopMotor(); - } - if(AN2>30) { - etat=0; - t2.start(); - t2.reset(); - stopMotor(); - } - - break; - case 2 : - if((AN2>10 && AN2<20) || US3<13) { - etat=1; - stopMotor(); - } - if(t2.read()>2.5) { - etat=0; - } - break; - } - switch(etat) { - case 0 : - suivi_mur(); - break; - case 1 : - rotation_horaire(); - break; - case 2 : - contournement(); - break; - } - + leds.write(bp.read()+1); + //cs=0; + monI2C.write(ADR_PCF,&B,1); + unsigned int valeur = spi.write(0x00); + valeur = (valeur>>1)&0x0FFF; + printf("valeur lue = %d\n\r", valeur); + //cs=1; + monI2C.write(ADR_PCF,&A,1); + wait(0.05); } }