Capteur ST

Dependencies:   VL6180x mbed Servo

Fork of VL6180X_Explorer by Ian Kilburn

Revision:
3:27076d13c756
Parent:
2:083c1efc951f
--- a/main.cpp	Thu Sep 10 12:32:36 2015 +0000
+++ b/main.cpp	Fri Sep 11 11:02:40 2015 +0000
@@ -26,6 +26,7 @@
  ******************************************************************************/
 #include "mbed.h"
 #include <VL6180x.h>
+#include "Servo.h"
 
 /*const float GAIN_1    = 1.01;  // Actual ALS Gain of 1.01
 const float GAIN_1_25 = 1.28;  // Actual ALS Gain of 1.28
@@ -39,6 +40,8 @@
 
 #define VL6180X_ADDRESS 0x29
 
+Serial pc(SERIAL_TX, SERIAL_RX);
+
 DigitalInOut sda_D(PB_9);
 DigitalInOut scl_D(PB_8);
 
@@ -76,6 +79,14 @@
 }
 int main() {
 
+ Servo myservo(D7);                // Create the servo object
+ float butee_droite=0.1;
+ float butee_gauche=1;
+ double position=0.1;
+ myservo.calibrate(0.00095, 90.0); // Calibrate the servo
+ 
+ pc.baud(115200);
+
   wait_ms(100); // delay .1s
   sda_D.mode(PullUp);
   scl_D.mode(PullUp);
@@ -91,9 +102,21 @@
   
   while(1) {
   
-      printf("capteur: %d\n\r", sensor_D.getDistance());
-      //printf("capteur gauche: %d\n\r",/*sensor_G.getAmbientLight(GAIN_1),*/ sensor_G.getDistance());
-      wait_ms(1000);  
+        while(position<butee_gauche){
+            myservo.write(position);
+            //printf("capteur: %d %f\n", sensor_D.getDistance(), position);
+            pc.printf("%d\n\r", sensor_D.getDistance());
+            pc.printf("%f\n\r", position);
+            wait_ms(10);  
+            position = position + 0.01;
+
+        }
+        
+        myservo.write(butee_droite);
+        position = 0.1;
+        wait_ms(10);
+        
+      
   }
 }