Motorprogrammaatje - the basics, enkel motor laten draaien.

Dependencies:   MODSERIAL mbed

Revision:
0:0cb350eb704a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Fri Sep 28 09:42:48 2018 +0000
@@ -0,0 +1,33 @@
+#include "mbed.h"
+#include "MODSERIAL.h"
+
+AnalogIn pot1(A1);
+AnalogIn pot2(A2);
+DigitalIn encoder(D7);
+PwmOut pwmpin(D5);
+DigitalOut directionpin(D4);
+DigitalOut directionpin2(D6);
+MODSERIAL pc(USBTX, USBRX);
+
+int main()
+{
+        pc.baud(9600);
+    
+    pwmpin.period_us(60); //60 microsecondsPWM period, 16.7 kHz
+   //float ain1;
+   //float ain2;
+    
+    while(true){
+       // ain1 = pot1.read();
+        // ain2 = pot2.read();
+        
+        float u = -0.9f; //determineusefulvalue, -0.3f is justanexample
+        directionpin= u > 0.0f; //eithertrueor false
+        pwmpin= fabs(u); //pwmduty cycle canonlybepositive, floatingpoint absolute value
+        
+        wait(0.5f);
+        
+        printf("Motorsnelheid %i \n \r", encoder); 
+        
+    }
+}
\ No newline at end of file