Advertisement
Guest User

Untitled

a guest
Feb 21st, 2019
85
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. #include "mbed.h"
  2.  
  3. PwmOut motorPwmL(D14), motorPwmR(D15) ;
  4. DigitalOut enable(D10), bi1(D12), bi2 (D13);
  5. DigitalIn button(USER_BUTTON);
  6.  
  7. int main() {
  8. float x=0.5;
  9. int s=0;
  10. enable.write(1);
  11. bi1.write(1);
  12. bi2.write(1);
  13. motorPwmL.period_ms(10);
  14. motorPwmR.period_ms (10);
  15. motorPwmL.write(0.5f);
  16. motorPwmR.write(0.5f);
  17.  
  18. while(1){
  19. if(button==0){
  20. s++;
  21. wait(0.3);
  22. if(s>7)
  23. s=0;
  24. }
  25. if(s==0){
  26. motorPwmL.write(0.5f);
  27. motorPwmR.write(0.5f);
  28. }
  29. if(s==1){
  30. motorPwmL.write(0.7f);
  31. motorPwmR.write(0.5f);
  32. }
  33. if(s==2){
  34. motorPwmL.write(0.9f);
  35. motorPwmR.write(0.5f);
  36. }
  37. if(s==3){
  38. motorPwmL.write(0.5f);
  39. motorPwmR.write(0.7f);
  40. }
  41. if(s==4){
  42. motorPwmL.write(0.5f);
  43. motorPwmR.write(0.9f);
  44. }
  45. if(s==5){
  46. motorPwmL.write(0.7f);
  47. motorPwmR.write(0.7f);
  48. }
  49. if(s==6){
  50. motorPwmL.write(0.9f);
  51. motorPwmR.write(0.9f);
  52. }
  53. if(s==7){
  54. motorPwmL.write(0.2f);
  55. motorPwmR.write(0.2f);
  56. }
  57. }
  58.  
  59.  
  60. wait(5);
  61. motorPwmL.write(0.7f);
  62. motorPwmR.write(0.7f);
  63.  
  64. wait(5);
  65. motorPwmL.write(0.5f);
  66. motorPwmR.write(0.5f);
  67.  
  68. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement