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

Files at this revision

API Documentation at this revision

Comitter:
brass_phoenix
Date:
Fri Oct 19 07:30:19 2018 +0000
Parent:
7:e4b475fceb86
Commit message:
* Fixed pointer mistake

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
diff -r e4b475fceb86 -r e69799b5cce1 main.cpp
--- a/main.cpp	Mon Oct 15 10:11:21 2018 +0000
+++ b/main.cpp	Fri Oct 19 07:30:19 2018 +0000
@@ -13,11 +13,11 @@
 
 // Updates a motor connected to the specified pins with the given speed.
 // The speed can be both positive and negative.
-void update_motor(DigitalOut dir, FastPWM pwm, float speed) {
+void update_motor(DigitalOut* dir, FastPWM* pwm, float speed) {
     // either true or false, determines direction (0 or 1)
-    dir = speed > 0;
+    *dir = speed > 0;
     // pwm duty cycle can only be positive, floating point absolute value (if value is >0, the there still will be a positive value).
-    pwm = fabs(speed);
+    *pwm = fabs(speed);
 }
 
 // Normalizes a potmeter value from it's original range of [0, 1] to [-1, 1]
@@ -36,8 +36,8 @@
         float motor2_speed = normalize_pot(pot2);
         
         // Update both motors.
-        update_motor(directionpin1, pwmpin1, motor1_speed);
-        update_motor(directionpin2, pwmpin2, motor2_speed);
+        update_motor(&directionpin1, &pwmpin1, motor1_speed);
+        update_motor(&directionpin2, &pwmpin2, motor2_speed);
 }