Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "mbed.h"
- PwmOut motorPwmL(D14), motorPwmR(D15) ;
- DigitalOut enable(D10), bi1(D12), bi2 (D13);
- DigitalIn button(USER_BUTTON);
- int main() {
- float x=0.5;
- int s=0;
- enable.write(1);
- bi1.write(1);
- bi2.write(1);
- motorPwmL.period_ms(10);
- motorPwmR.period_ms (10);
- motorPwmL.write(0.5f);
- motorPwmR.write(0.5f);
- while(1){
- if(button==0){
- s++;
- wait(0.3);
- if(s>7)
- s=0;
- }
- if(s==0){
- motorPwmL.write(0.5f);
- motorPwmR.write(0.5f);
- }
- if(s==1){
- motorPwmL.write(0.7f);
- motorPwmR.write(0.5f);
- }
- if(s==2){
- motorPwmL.write(0.9f);
- motorPwmR.write(0.5f);
- }
- if(s==3){
- motorPwmL.write(0.5f);
- motorPwmR.write(0.7f);
- }
- if(s==4){
- motorPwmL.write(0.5f);
- motorPwmR.write(0.9f);
- }
- if(s==5){
- motorPwmL.write(0.7f);
- motorPwmR.write(0.7f);
- }
- if(s==6){
- motorPwmL.write(0.9f);
- motorPwmR.write(0.9f);
- }
- if(s==7){
- motorPwmL.write(0.2f);
- motorPwmR.write(0.2f);
- }
- }
- wait(5);
- motorPwmL.write(0.7f);
- motorPwmR.write(0.7f);
- wait(5);
- motorPwmL.write(0.5f);
- motorPwmR.write(0.5f);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement