TP_presa

Dependencies:   SRF08 Servo mbed

Revision:
1:5830b7d6a985
Parent:
0:99cb324a2329
Child:
2:6d12c2d70f19
diff -r 99cb324a2329 -r 5830b7d6a985 main.cpp
--- a/main.cpp	Wed May 31 18:32:54 2017 +0000
+++ b/main.cpp	Wed May 31 18:33:28 2017 +0000
@@ -1,6 +1,7 @@
 #include "mbed.h"
 
 char Adress = 128;
+char Vit =50;
                     //Address: 130
                     //Command : 0
                     //Data: 64
@@ -23,47 +24,85 @@
     myled3=l3;
     myled4=l4;    
 }
-
-void forward(char Vit) {
+void emiss(char Code,  char Vit_perso){
      sbt.putc(Adress);
-     sbt.putc(0); 
-     sbt.putc(Vit);  
-     sbt.putc((Adress+0+Vit) & 127);
-     
-     sbt.putc(Adress);
-     sbt.putc(4); 
-     sbt.putc(Vit);  
-     sbt.putc((Adress+4+Vit) & 127);
+     sbt.putc(Code); 
+     sbt.putc(Vit_perso);  
+     sbt.putc((Adress+Code+Vit_perso) & 127);
+    }
+
+void forward(char Vit_perso) {
+    emiss(0,Vit_perso);
+    emiss(4,Vit_perso);
 }
 void avancer(void) {
-     Vit=50;
-     sbt.putc(Adress);
-     sbt.putc(0); 
-     sbt.putc(Vit);  
-     sbt.putc((Adress+0+Vit) & 127);
-     
-     sbt.putc(Adress);
-     sbt.putc(4); 
-     sbt.putc(Vit);  
-     sbt.putc((Adress+4+Vit) & 127);
+ 
+     emiss(0,Vit);
+     emiss(4,Vit);
 }
-void reculer(void) {
-     Vit=50;
-     sbt.putc(Adress);
-     sbt.putc(1); 
-     sbt.putc(Vit);  
-     sbt.putc((Adress+0+Vit) & 127);
-     
-     sbt.putc(Adress);
-     sbt.putc(5); 
-     sbt.putc(Vit);  
-     sbt.putc((Adress+4+Vit) & 127);
+void arreter(void) {
+     emiss(0,0);
+     emiss(4,0);
 }
 
+void reculer(void) {
+ 
+     emiss(1,Vit);
+     emiss(5,Vit);
+}
+void tourner_droite(void) {
 
+     emiss(0,Vit);
+     emiss(5,Vit);   
+     wait(0.3);
+     emiss(0,0);
+     emiss(5,0);  
+}
+void tourner_gauche(void) {
+     Vit=50;
+     emiss(1,Vit);
+     emiss(4,Vit);   
+     wait(0.3);
+     emiss(1,0);
+     emiss(4,0);  
+}
+void demi_tour_droite(void) {
+
+     emiss(0,Vit);
+     emiss(5,Vit);   
+     wait(1);
+     emiss(0,0);
+     emiss(5,0);      
+}
+void demi_tour_gauche(void) {
+     emiss(1,Vit);
+     emiss(4,Vit);   
+     wait(1);
+     emiss(1,0);
+     emiss(4,0);  
+}
 int main (){
-    Led (0,1,0,1);
+    while (1){
+    Led (1,0,0,0);
     S2=0;
     wait(1);
-    forward(50);
+    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);
+ 
+    }
 }