sketch_debugMotorsDFRobot.ino 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. int speedPin_M1 = 5; //M1 Speed Control
  2. int speedPin_M2 = 6; //M2 Speed Control
  3. int directionPin_M1 = 4; //M1 Direction Control
  4. int directionPin_M2 = 7; //M1 Direction Control
  5. void setup(){
  6. }
  7. void loop(){
  8. carAdvance(100,100);
  9. delay(1000);
  10. carBack(100,100);
  11. delay(1000);
  12. carTurnLeft(250,250);
  13. delay(1000);
  14. carTurnRight(250,250);
  15. delay(1000);
  16. }
  17. void carStop(){ // Motor Stop
  18. digitalWrite(speedPin_M2,0);
  19. digitalWrite(directionPin_M1,LOW);
  20. digitalWrite(speedPin_M1,0);
  21. digitalWrite(directionPin_M2,LOW);
  22. }
  23. void carTurnLeft(int leftSpeed,int rightSpeed){ //Turn Left
  24. analogWrite (speedPin_M2,leftSpeed); //PWM Speed Control
  25. digitalWrite(directionPin_M1,HIGH);
  26. analogWrite (speedPin_M1,rightSpeed);
  27. digitalWrite(directionPin_M2,HIGH);
  28. }
  29. void carTurnRight(int leftSpeed,int rightSpeed){ //Turn Right
  30. analogWrite (speedPin_M2,leftSpeed);
  31. digitalWrite(directionPin_M1,LOW);
  32. analogWrite (speedPin_M1,rightSpeed);
  33. digitalWrite(directionPin_M2,LOW);
  34. }
  35. void carBack(int leftSpeed,int rightSpeed){ //Move backward
  36. analogWrite (speedPin_M2,leftSpeed);
  37. digitalWrite(directionPin_M1,LOW);
  38. analogWrite (speedPin_M1,rightSpeed);
  39. digitalWrite(directionPin_M2,HIGH);
  40. }
  41. void carAdvance(int leftSpeed,int rightSpeed){ //Move forward
  42. analogWrite (speedPin_M2,leftSpeed);
  43. digitalWrite(directionPin_M1,HIGH);
  44. analogWrite (speedPin_M1,rightSpeed);
  45. digitalWrite(directionPin_M2,LOW);
  46. }