Motor test for Stage 1 Engineering at the University of York

Files at this revision

API Documentation at this revision

Comitter:
ajp109
Date:
Mon Sep 20 16:10:22 2021 +0000
Parent:
1:3d2e96d4ef3a
Commit message:
Initial commit of motor test

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
--- a/main.cpp	Mon Oct 19 15:21:13 2020 +0000
+++ b/main.cpp	Mon Sep 20 16:10:22 2021 +0000
@@ -2,23 +2,18 @@
 
 int main()
 {
-    float const pi = 3.14159265359;
-    
-    // Initialise the digital pins D2, D3 and D4 as PWM outputs
-    PwmOut red(D2);
-    PwmOut green(D3);
-    PwmOut blue(D4);
+    // Initialise the digital pin D4 as a PWM output
+    PwmOut motor(D4);
 
     // Loop forever...
     while (true) {
-        // Loop the 'angle' variable from 0 to 359
-        for (int angle = 0; angle < 360; angle++) {
-            // Set the intensities of the LEDs
-            red = 0.5+0.5*sin(angle*pi/180);
-            green = 0.5+0.5*sin((angle+120)*pi/180);
-            blue = 0.5+0.5*sin((angle+240)*pi/180);
-            // The angle will change by one degree every 20ms
-            thread_sleep_for(20);
-        }
+        motor = 0.5; // 50%
+        thread_sleep_for(500);
+        motor = 0.0; // stop
+        thread_sleep_for(500);
+        motor = 1.0; // 100%
+        thread_sleep_for(500);
+        motor = 0.0; // stop
+        thread_sleep_for(500);
     }
 }