![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
TP_presa
Dependencies: SRF08 Servo mbed
Diff: main.cpp
- Revision:
- 2:6d12c2d70f19
- Parent:
- 1:5830b7d6a985
- Child:
- 3:0b19b5b7c3a4
diff -r 5830b7d6a985 -r 6d12c2d70f19 main.cpp --- a/main.cpp Wed May 31 18:33:28 2017 +0000 +++ b/main.cpp Wed May 31 18:33:54 2017 +0000 @@ -1,7 +1,7 @@ #include "mbed.h" char Adress = 128; -char Vit =50; +//char Vit =50; //Address: 130 //Command : 0 //Data: 64 @@ -24,85 +24,105 @@ myled3=l3; myled4=l4; } -void emiss(char Code, char Vit_perso){ +void emiss(char Code, char Vit){ sbt.putc(Adress); sbt.putc(Code); - sbt.putc(Vit_perso); - sbt.putc((Adress+Code+Vit_perso) & 127); + sbt.putc(Vit); + sbt.putc((Adress+Code+Vit) & 127); } -void forward(char Vit_perso) { - emiss(0,Vit_perso); - emiss(4,Vit_perso); +void forward(char Vit) { + emiss(0,Vit); + emiss(4,Vit); } -void avancer(void) { - - emiss(0,Vit); - emiss(4,Vit); +void avancer(char Vit) { + int i=0; + for(i; i<Vit ; i=i+(Vit/5));{ + emiss(0,i); + emiss(4,i); + wait(0.1); + } } -void arreter(void) { +void arreter(char Vit){ + int i=Vit; + for(i ; i>0;i=i-(Vit/5)){ + emiss(0,i); + emiss(4,i); + wait(0.1);} emiss(0,0); emiss(4,0); } - -void reculer(void) { - - emiss(1,Vit); - emiss(5,Vit); +void arret_urgence(void) { + emiss(0,0); + emiss(4,0); } -void tourner_droite(void) { - +void reculer(char Vit) { + for(int i =0; i<Vit;i=i+5){ + emiss(1,i); + emiss(5,i); + wait(0.1);} +} +void tourner_droite(char Vit) { emiss(0,Vit); emiss(5,Vit); - wait(0.3); + wait(0.125); emiss(0,0); emiss(5,0); } -void tourner_gauche(void) { - Vit=50; +void tourner_gauche(char Vit) { emiss(1,Vit); emiss(4,Vit); - wait(0.3); + wait(0.125); emiss(1,0); emiss(4,0); } -void demi_tour_droite(void) { - +void demi_tour_droite(char Vit) { emiss(0,Vit); emiss(5,Vit); - wait(1); + wait(0.75); emiss(0,0); emiss(5,0); } -void demi_tour_gauche(void) { +void demi_tour_gauche(char Vit) { emiss(1,Vit); emiss(4,Vit); - wait(1); + wait(0.75); emiss(1,0); emiss(4,0); } +void myVG (char Vit , char Ang){ + emiss(1,Vit); + emiss(4,Vit); + wait((Ang*0.44)/Vit); + emiss(1,0); + emiss(4,0); + } int main (){ while (1){ - Led (1,0,0,0); - S2=0; - wait(1); - avancer(); - Led (1,1,0,0); - wait(1); - reculer(); - Led (1,1,1,0); - wait(1); - tourner_gauche(); - Led (1,1,1,1); - wait(1); - tourner_droite(); - Led (0,1,1,1); - wait(1); - demi_tour_gauche(); - Led (0,0,1,1); - wait(1); - demi_tour_droite(); - Led (0,0,0,1); + Led (1,0,0,0); + S2=0; + wait(1); + avancer(70); + Led (1,1,0,0); + wait(1); + arreter(70); + wait(0.5); + reculer(70); + Led (1,1,1,0); + wait(1); + arret_urgence(); + wait(0.5); + tourner_gauche(120); + Led (1,1,1,1); + wait(1); + tourner_droite(120); + Led (0,1,1,1); + wait(1); + demi_tour_gauche(120); + Led (0,0,1,1); + wait(1); + demi_tour_droite(120); + Led (0,0,0,1); } }