scooter / Mbed 2 deprecated Scooter-uC-Programm

Dependencies:   mbed

Revision:
3:86498e58d1d9
Parent:
0:70f3437369e5
--- a/main.cpp	Tue May 19 14:04:53 2015 +0000
+++ b/main.cpp	Tue May 19 14:16:22 2015 +0000
@@ -1,1 +1,41 @@
-#include "mbed.h"
\ No newline at end of file
+#include "mbed.h"
+#define PERIODEN_DAUER 10
+
+PwmOut mypwm(PWM_OUT); 
+AnalogIn analog_value0(A0); //For Hall-Sensor
+
+DigitalOut myled(LED1);
+
+// Prototypen
+float hall_umrechnung();
+
+int main() {
+  
+    while(1) {
+        mypwm.period_ms(PERIODEN_DAUER);
+        mypwm.pulsewidth_ms(PERIODEN_DAUER*hall_umrechnung());
+        myled = !myled;
+        wait(1);
+    }
+}
+
+float hall_umrechnung()
+{
+    float meas0;
+    meas0 = analog_value0.read() - 0,2503;
+    if(meas0 < 0)
+    {
+        meas0 = 0;
+    }
+    
+    meas0 = meas0*2;
+    
+    if(meas0 > 1)
+    {
+        meas0 = 1;
+    }
+    
+    return meas0;
+
+    
+}
\ No newline at end of file