UoD_ME21001_Group_1_12 / Mbed 2 deprecated ME21001_Lab05_Exercise_05

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
jfair
Date:
Tue Oct 15 15:59:57 2019 +0000
Commit message:
works

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 72fcbd17b9f9 main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Oct 15 15:59:57 2019 +0000
@@ -0,0 +1,38 @@
+#include "mbed.h"
+DigitalOut Ain1(p17);
+DigitalOut Ain2(p18);
+DigitalOut Standby(p22);
+PwmOut motor_control(p21); // PWM output pin
+
+void set_motor_speed(float speed) {
+motor_control.write(speed); // set the PWM signal to be 'speed' percent (0.0 – 1.0)
+wait(1.000); // wait for 1s to allow the PWM signal to persist
+}
+int main() {
+ float j=0.0;
+ float i=0.0;
+  motor_control.period(0.020); // 1s PWM period
+  Ain1 = 0;
+  Ain2 = 1;
+ while(1) { // repeat indefinitely
+ wait(1);
+for(j=0;j<1;j++){
+for(i=0.0;i<=1.0;i+=0.25){ // set the PWM signal to increment from 0-100% by 25%
+ Standby = 1;
+  motor_control.write(i); // call the set_motor_speed function with the current 'i' value
+  wait(0.2);             //waits 0.2 second
+  motor_control.write(0.0);
+  wait(1); 
+  }
+for(i=1.0;i>=0.0;i-=0.25){ // set the PWM signal to decrement from 100-0% by 25%
+ Standby = 1;
+  motor_control.write(i); // call the set_motor_speed function with the current 'i' value
+  wait(0.2);             //waits 1 second
+  motor_control.write(0.0);
+  wait(1); 
+  }
+  Ain1=!Ain1;
+  Ain2=!Ain2;
+  }
+  }
+}
\ No newline at end of file
diff -r 000000000000 -r 72fcbd17b9f9 mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Oct 15 15:59:57 2019 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file