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.
main.cpp
00001 /* 00002 Version 7 – Mike edit 00003 */ 00004 00005 #include "mbed.h" 00006 00007 //Motor PWM (speed) 00008 PwmOut PWMA(PA_8); 00009 PwmOut PWMB(PB_4); 00010 00011 //Motor Direction 00012 DigitalOut DIRA(PA_9); 00013 DigitalOut DIRB(PB_10); 00014 00015 //On board switch 00016 DigitalIn SW1(USER_BUTTON); 00017 00018 //Use the serial object so we can use higher speeds 00019 Serial terminal(USBTX, USBRX); 00020 00021 //Timer used for measuring speeds 00022 Timer timer; 00023 00024 //Enumerated types 00025 enum DIRECTION {FORWARD=0, REVERSE}; 00026 enum PULSE {NOPULSE=0, PULSE}; 00027 enum SWITCHSTATE {PRESSED=0, RELEASED}; 00028 00029 //Debug GPIO 00030 DigitalOut probe(D10); 00031 00032 //Duty cycles 00033 float dutyA = 1.0f; //100% 00034 float dutyB = 1.0f; //100% 00035 00036 int main() 00037 { 00038 //Configure the terminal to high speed 00039 terminal.baud(115200); 00040 00041 //Set initial motor direction 00042 DIRA = FORWARD; 00043 DIRB = FORWARD; 00044 00045 //Set motor period to 100Hz 00046 PWMA.period_ms(10); 00047 PWMB.period_ms(10); 00048 00049 //Set initial motor speed to stop 00050 PWMA.write(0.0f); //0% duty cycle 00051 PWMB.write(0.0f); //0% duty cycle 00052 00053 //Wait for USER button (blue pull-down switch) to start 00054 terminal.puts("Press USER button to start"); 00055 while (SW1 == RELEASED); 00056 00057 //Set initial motor speed to stop { 00058 for(float ramp = 0.0f; ramp <= 1.0f ; ramp += 0.2) 00059 { 00060 PWMA.write(ramp); //Set duty cycle y 00061 PWMB.write(ramp); //Set duty cycle y 00062 wait(1); 00063 } 00064 00065 PWMA.write(dutyA); //Set duty cycle y 00066 PWMB.write(dutyB); //Set duty cycle y 00067 wait(1.1); 00068 PWMB.write(0.2f); //turn 31deg 00069 wait(1.3); 00070 PWMA.write(dutyA); //Set duty cycle hyp 00071 PWMB.write(dutyB); //Set duty cycle hyp 00072 wait(4.4); 00073 PWMB.write(0.2f); //turn 59deg 00074 wait(1.1); 00075 PWMA.write(dutyA); //Set duty cycle x 00076 PWMB.write(dutyB); //Set duty cycle x 00077 wait(2.4); 00078 PWMB.write(0.2f); //turn 90deg 00079 wait(0.7); 00080 00081 PWMA.write(0.0f); 00082 PWMB.write(0.0f); 00083 }
Generated on Wed Sep 7 2022 19:19:18 by
1.7.2