Programming Milestone 1 Group 7 BMT M9: Making robots move at different velocities/directions by adjusting potmeter.

Dependencies:   FastPWM MODSERIAL mbed

Fork of Programming_Milestone_1 by Marie-Laure Snijders

Revision:
4:a4cd6f9c851d
Parent:
2:6d3f3d1bcef7
Child:
5:92360cb2e0e4
--- a/main.cpp	Tue Sep 25 14:58:08 2018 +0000
+++ b/main.cpp	Wed Sep 26 16:33:53 2018 +0000
@@ -3,7 +3,7 @@
 #include "MODSERIAL.h"
 MODSERIAL pc(USBTX, USBRX);
 
-Ticker motor; // ticker function
+Ticker motor; // Ticker function
 FastPWM pwmpin1(D5); // SPECIFIC PIN (hoeft niet aangesloten te worden) Tells you how fast the motor has to go (later: pwmpin.write will tell you the duty cycle, aka how much voltage the motor gets)
 FastPWM pwmpin2(D6); // SPECIFIC PIN (hoeft niet aangesloten te worden) Tells you how fast the motor has to go (later: pwmpin.write will tell you the duty cycle, aka how much voltage the motor gets)
 DigitalOut directionpin1(D4); // SPECIFIC PIN (hoeft niet aangesloten te worden) Direction value (0-1) that the mbed will give the motor: in which direction the motor must rotate
@@ -19,25 +19,21 @@
 volatile float u2;
 
 void motorfunction()
-{       pot1 = potmeter1.read();          // Reads out value potmeter 1 between 0-1
-        pot1_scale = pot1*2 -1;           // Scales value potmeter from 0-1 to -1 - 1.
-        pot2 = potmeter2.read(); 
-        pot2_scale = pot2*2 -1;           // Scales value potmeter from 0-1 to -1 - 1.        
+{       pot1 = potmeter1.read();          // reads out value potmeter 1 between 0-1
+        pot1_scale = pot1*2 -1;           // scales value potmeter from 0-1 to -1 - 1.
+        pot2 = potmeter2.read();          // reads out value potmeter 2 between 0-1 
+        pot2_scale = pot2*2 -1;           // scales value potmeter from 0-1 to -1 - 1.        
         u1 = pot1_scale;                  // motor control signal
         u2 = pot2_scale;                  // motor control signal
-        directionpin1 = u1 > 0.0f;              //either true or false, determines direction (0 or 1)
-        directionpin2 = u2 > 0.0f;              //either true or false
-        pwmpin1 = fabs(u1);                     //pwm duty cycle can only be positive, floating point absolute value (if value is >0, the there still will be a positive value).
-        pwmpin2 = fabs(u2);                     //pwm duty cycle can only be positive, floating point absolute value (if value is >0, the there still will be a positive value).
+        directionpin1 = u1 > 0.0f;        // either true or false, determines direction (0 or 1)
+        directionpin2 = u2 > 0.0f;        // either true or false
+        pwmpin1 = fabs(u1);               // pwm duty cycle can only be positive, floating point absolute value (if value is >0, the there still will be a positive value).
+        pwmpin2 = fabs(u2);               // pwm duty cycle can only be positive, floating point absolute value (if value is >0, the there still will be a positive value).
 }
 
 int main()
 {
     pwmpin1.period_us(60.0); //60 microseconds PWM period, 16.7 kHz, defines all PWM pins (only needs to be done once)
-    pc.baud(115200);
     motor.attach(motorfunction,0.5);
-    while(true){
-           pc.printf("%f \n, %f \n, %f\n", pot1,pot1_scale, u1);
-           wait(1.0f);
-           } //Lege while loop zodat functie niet afloopt
+    while(true){} //Lege while loop zodat functie niet afloopt
 }
\ No newline at end of file