Prog Thib Ju

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
JulienB1
Date:
Thu Apr 11 12:05:57 2019 +0000
Commit message:
J

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 5535594ef331 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Apr 11 12:05:57 2019 +0000
@@ -0,0 +1,67 @@
+#include "mbed.h"
+ 
+
+PwmOut moteur1(D10); 
+PwmOut moteur2(D9);
+DigitalOut Trig(D12);
+InterruptIn reception(D8);
+
+DigitalOut myled(LED1);
+
+DigitalOut LED(LED1);
+Serial pc(USBTX, USBRX);
+Timer t;
+double  distance ;
+double rc;
+
+void front_montant()
+{
+    t.start();
+}
+
+void front_descendant()
+{
+    t.stop();
+    double distance = 330*t.read()/2*1.06;
+   // pc.printf("Distance = %f \r\n",330*t.read()/2*1.06);
+    pc.printf("Distance = %lf \r\n", distance);
+    t.reset();
+    myled =1;
+    if (distance<=0.10){ rc = 0;}
+    if (distance<=0.20 && distance>0.10){ rc = 0.5;}
+    if (distance >=0.20) { rc = 1; }
+    //if (distance<=0.40 && distance>0.20){ rc = 0.6;}
+    //if (distance<=0.50 && distance>0.40){ rc = 0.8;}
+    //pc.printf("rapport cyclique = \r \n"); 
+    //pc.scanf("%lf" ,&rc);
+    pc.printf("Nouvelle valeur du rapport cyclique = %lf \r \n", rc);
+    moteur2.write(rc);
+} 
+
+int main() 
+{
+    t.reset();
+    reception.rise(&front_montant);
+    reception.fall(&front_descendant);
+    moteur1.period_ms(10);
+    moteur2.period_ms(10);
+    moteur1.write(0);
+    moteur2.write(0);
+    pc.baud(9600);
+    
+    while(1)
+    {
+        Trig = 1;
+        wait(0.001);
+        Trig =0 ; 
+        wait(0.001);
+    /*    Trig = 0;
+        Trig = 1;    
+    
+    //pc.printf("rapport cyclique = \r \n"); 
+    //pc.scanf("%lf" ,&rc);
+        pc.printf("Nouvelle valeur du rapport cyclique = %lf \r \n", rc);
+        moteur_cc_pwm.write(rc);
+    */    
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 5535594ef331 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Apr 11 12:05:57 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file