Guest User

Untitled

a guest
Jun 18th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.70 KB | None | 0 0
  1. /*
  2. * Mechanisms and Movement
  3. *
  4. * A device that uses two forms of mechanical movement,
  5. * driven by a DC motor:
  6. * it translates rotary motion (DC motor)
  7. * to a rocking motion (4-bar linkage)
  8. * to intermittent motion (dowel on pivot)
  9. *
  10. *
  11. * Created by Corinna Sherman
  12. * October 10, 2010
  13. */
  14.  
  15. int enableSwitchPin = 8; // enable switch input pin to turn device ON/OFF
  16. int enablePin1 = 9; // H-bridge enable pin 1 (1,2EN)
  17. int motorPin1 = 3; // motor 1 logic pin 1 on H-bridge (1A)
  18. int motorPin2 = 5; // motor 1 logic pin 2 on H-bridge (2A)
  19.  
  20. void setup() {
  21.  
  22. // Initialize serial communication.
  23. Serial.begin(9600);
  24.  
  25. // Set enable switch pin and touch sensor pins as input pins.
  26. pinMode(enableSwitchPin, INPUT);
  27.  
  28. // Set other pins as output pins.
  29. pinMode(enablePin1, OUTPUT);
  30. pinMode(motorPin1, OUTPUT);
  31. pinMode(motorPin2, OUTPUT);
  32.  
  33. // Go forward by default.
  34. goForward();
  35. }
  36.  
  37. void loop() {
  38.  
  39. // If the switch is on, the motor turns in one direction.
  40. if (digitalRead(enableSwitchPin) == HIGH) {
  41. // Set enablePins to HIGH to turn on both motors.
  42. Serial.println("go");
  43. enable();
  44. }
  45. else {
  46. Serial.println("stop");
  47. disable();
  48. }
  49.  
  50. }
  51.  
  52. void enable() {
  53. // Set enablePins to HIGH to turn on both motors.
  54. digitalWrite(enablePin1, HIGH);
  55. }
  56.  
  57. void disable() {
  58. // Set enablePins to LOW to turn off both motors.
  59. digitalWrite(enablePin1, LOW);
  60. }
  61.  
  62. void goForward() {
  63. // Set motor's direction
  64. digitalWrite(motorPin1, LOW); // Set H-bridge 1A pin to low
  65. digitalWrite(motorPin2, HIGH); // Set H-bridge 2A pin to high
  66. }
  67.  
  68. void goBackward() {
  69. // Set motor's direction
  70. digitalWrite(motorPin1, HIGH); // Set H-bridge 1A pin to high
  71. digitalWrite(motorPin2, LOW); // Set H-bridge 2A pin to low
  72. }
Add Comment
Please, Sign In to add comment