Advertisement
Guest User

Untitled

a guest
Jun 22nd, 2017
52
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.85 KB | None | 0 0
  1. const int potPin = A0;
  2. const int buttonPin = 13;
  3. const int forward1 = 5;
  4. const int forward2 = 4;
  5. const int backward1 = 3;
  6. const int backward2 = 2;
  7. int potValue = 0;
  8. int motorValue = 0;
  9. int buttonState = 0;
  10.  
  11. void setup()
  12. {
  13.  
  14. pinMode(buttonPin, INPUT);
  15. pinMode (forward1, OUTPUT);
  16. pinMode (forward2, OUTPUT);
  17. pinMode (backward1, OUTPUT);
  18. pinMode (backward2, OUTPUT);
  19.  
  20. }
  21.  
  22. void loop()
  23. {
  24.  
  25. potValue = analogRead(potPin);
  26. motorValue = map(potValue, 0, 1023, 0, 255);
  27. buttonState = digitalRead(buttonPin);
  28.  
  29. if (buttonState == LOW)
  30. {
  31.  
  32. analogWrite(backward1, motorValue);
  33. digitalWrite (backward2, HIGH);
  34. digitalWrite (forward1, LOW);
  35. digitalWrite (forward2, LOW);
  36.  
  37. }
  38.  
  39. else
  40. {
  41.  
  42. analogWrite(forward1, motorValue);
  43. digitalWrite (forward2, HIGH);
  44. digitalWrite (backward1, LOW);
  45. digitalWrite (backward2, LOW);
  46.  
  47. }
  48.  
  49. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement