Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
Revision 0:72fcbd17b9f9, committed 2019-10-15
- 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