Advertisement
Guest User

Untitled

a guest
Jun 16th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.39 KB | None | 0 0
  1. const int button = 4; // Limit switch
  2. const int button2 = 2; // Limit Switch
  3. const int button3 = 13; // Start signal
  4. const int motorPin = 8; // L298 IN2
  5. const int motorPin2 = 7; // L298 IN1
  6.  
  7. boolean buttonstatus = 0;
  8. boolean buttonstatus2 = 0;
  9. boolean buttonstatus3 = 0;
  10.  
  11. int drawPosition = 2;
  12.  
  13. void setup() {
  14. pinMode(motorPin, OUTPUT);
  15. pinMode(motorPin2, OUTPUT);
  16. pinMode(button, INPUT);
  17. pinMode(button2, INPUT);
  18. pinMode(button3, INPUT);
  19. // if the power fails close gate
  20. digitalWrite(motorPin, HIGH);
  21. digitalWrite(motorPin2, LOW);
  22. }
  23.  
  24. void drawForward() {
  25. digitalWrite(motorPin, LOW);
  26. digitalWrite(motorPin2, HIGH);
  27. }
  28.  
  29. void drawBackward() {
  30. // turn motor in other direction:
  31. digitalWrite(motorPin, HIGH);
  32. digitalWrite(motorPin2, LOW);
  33. }
  34.  
  35. void stopDrawFromMoving() {
  36. digitalWrite(motorPin, LOW);
  37. digitalWrite(motorPin2, LOW);
  38.  
  39. }
  40.  
  41. void loop() {
  42. buttonstatus = digitalRead(button);
  43. buttonstatus2 = digitalRead(button2);
  44. buttonstatus3 = digitalRead(button3);
  45.  
  46. if (buttonstatus == HIGH) {
  47. drawPosition = 2;
  48. stopDrawFromMoving();
  49. }else if (buttonstatus2 == HIGH) {
  50. drawPosition = 1;
  51. stopDrawFromMoving();
  52. }
  53. if (buttonstatus3 == HIGH) {
  54. if (drawPosition == 2 ) {
  55. delay(100);
  56. drawForward();
  57. delay(100);
  58. drawPosition = 1;
  59. }
  60. }
  61. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement