eLab Team / Mbed 2 deprecated analogRead

Dependencies:   mbed

Revision:
3:9d006b6e1d04
Parent:
2:e0faf9e57796
Child:
4:972778a8aca8
--- a/main.cpp	Mon Mar 27 14:20:32 2017 +0000
+++ b/main.cpp	Sat Mar 27 13:19:00 2021 +0000
@@ -15,18 +15,26 @@
 const int HIGH = 1; // Optional, but makes code more readable.
 const int LOW = 0; // Optional, but makes code more readable.
  
-AnalogIn analog_value(A0);
- 
+AnalogIn analog_value(A0); 
 DigitalOut led(LED1);
+PwmOut servo(D6);
 
 int main() {
     float value; // Value to be read and sent to serial port.
+    int i=0, angle;
+    servo.period_ms(20);
     
     printf("\nAnalogIn example\n");
     
     while(true) {
         value = analog_value.read(); // Read the analog input value (0 to 1)
         printf("Value = %f\n", value); // Send value as text via serial port.
+        printf("Value_int = %d\n", int(value*180)); // Send value as text via serial port.
+        angle = int(value*180);
+        servo.pulsewidth_us(10*angle+500);
+        wait_ms(10);
+
+
         if (value > 0.5f) { // Activate built-in LED. The f is optional.
           led.write(HIGH);
         }
@@ -35,5 +43,16 @@
         }
         printf("LED = %d\n", (int) led.read()); // Send LED state via serial. 
         wait(0.25); // 250 ms
+        
+//        for (i=0; i<=200; i++){
+//            servo.pulsewidth_us(10*i+500);
+//            wait_ms(10);
+//        }
+//        for (i=0; i<=200; i++){
+//            servo.pulsewidth_us(-10*i+2500);
+//            wait_ms(10);
+//        }
+        
+        
     }
 }