Guest User

Untitled

a guest
Apr 19th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.11 KB | None | 0 0
  1. /*
  2. Aidan Rafferty
  3. Object Lab 05
  4. Part 2
  5. */
  6.  
  7. const int switchPin = 2; // switch input
  8. const int motor1Pin = 3; // H-bridge leg 1 (pin 2, 1A)
  9. const int motor2Pin = 4; // H-bridge leg 2 (pin 7, 2A)
  10. const int enablePin = 9; // H-bridge enable pin
  11.  
  12. void setup() {
  13. // set the switch as an input:
  14. pinMode(switchPin, INPUT);
  15.  
  16. // set all the other pins you're using as outputs:
  17. pinMode(motor1Pin, OUTPUT);
  18. pinMode(motor2Pin, OUTPUT);
  19. pinMode(enablePin, OUTPUT);
  20.  
  21. // set enablePin high so that motor can turn on:
  22. digitalWrite(enablePin, HIGH);
  23.  
  24.  
  25. }
  26.  
  27. void loop() {
  28. // if the switch is high, motor will turn on one direction
  29. int switchVal = digitalRead(switchPin);
  30.  
  31. if(switchVal == 1)
  32. {
  33. digitalWrite(motor1Pin, 1);
  34. digitalWrite(motor2Pin, 0);
  35. }
  36. else
  37. {
  38. digitalWrite(motor1Pin, 0);
  39. digitalWrite(motor2Pin, 1);
  40. }
  41.  
  42. // set leg 1 of the H-bridge low
  43. // set leg 2 of the H-bridge high
  44.  
  45. // else (which means the switch is low), motor will turn in the other direction
  46.  
  47. // set leg 1 of the H-bridge high
  48. // set leg 2 of the H-bridge low
  49. }
Add Comment
Please, Sign In to add comment