Software that allows basic remote control of the position of a servo (schematic included in the comments)

Dependencies:   MyDS1820 mbed

Fork of Nucleo_sg90_remote_control by YP Roy

Revision:
0:7a91558f8c41
Child:
1:df2cee74ab8b
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Mon Jan 30 05:20:16 2017 +0000
@@ -0,0 +1,31 @@
+#include "mbed.h"
+
+PwmOut mypwm(PA_7);
+InterruptIn monBouton(USER_BUTTON);
+int compteur;
+int cycle[]={700, 1550, 2500, 1550};
+void pressed(void)
+{
+    compteur++;
+    if (compteur >= sizeof(cycle)/sizeof(int))
+    {
+        compteur = 0;
+    }
+    mypwm.pulsewidth_us(cycle[compteur]);    
+}
+
+DigitalOut myled(LED1);
+
+int main() {
+    compteur = 0;    
+    mypwm.period_ms(20);
+    mypwm.pulsewidth_us(500);
+  
+//    printf("pwm set to %.2f %%\n", mypwm.read() * 100);
+    monBouton.fall(&pressed);
+      
+    while(1) {
+        myled = !myled;
+        wait(1);
+    }
+}