Arduino_Z_no_GUI_noRanges.ino 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. #define DISTANCE 1 // Define the discrete length of a step
  2. int StepCounter = 0;
  3. bool Stepping = false;
  4. /* Declare flag pin to send digital output to the RASPBERRY PI */
  5. const int signal_pin = 12;
  6. /* Easy Driver pins */
  7. const int driver_dir = 8;
  8. const int driver_stp = 9;
  9. /* Physical buttons */
  10. const int button_up = 2;
  11. const int button_down = 3;
  12. void setup()
  13. {
  14. /* Report state of automata: listening or stepping? */
  15. pinMode(signal_pin, OUTPUT);
  16. digitalWrite(signal_pin, LOW);
  17. /* Easy Driver
  18. To control direction. Set as LOW for UP direction and HIGH for DOWN direction */
  19. pinMode(driver_dir, OUTPUT);
  20. /* To step one step */
  21. pinMode(driver_stp, OUTPUT);
  22. digitalWrite(driver_dir, LOW); // Starting direction is UP
  23. digitalWrite(driver_stp, LOW); // No-step
  24. /* Up */
  25. pinMode(button_up, INPUT); // physical button step-up
  26. /* Down */
  27. pinMode(button_down, INPUT); // physical button step-down
  28. }
  29. void loop()
  30. {
  31. /* Check up direction with */
  32. if ((digitalRead(button_up) == LOW) && (Stepping == false ))
  33. {
  34. digitalWrite(driver_dir, LOW);
  35. Stepping = true;
  36. digitalWrite(signal_pin, HIGH);
  37. }
  38. /* Check down direction with */
  39. if ((digitalRead(button_down) == LOW) && (Stepping == false ))
  40. {
  41. digitalWrite(driver_dir, HIGH);
  42. Stepping = true;
  43. digitalWrite(signal_pin, HIGH);
  44. }
  45. /* If wished, go ahead and step */
  46. if (Stepping == true)
  47. {
  48. digitalWrite(driver_stp, HIGH);
  49. delay(1);
  50. digitalWrite(driver_stp, LOW);
  51. delay(1);
  52. StepCounter += 1;
  53. if (StepCounter == DISTANCE)
  54. {
  55. StepCounter = 0;
  56. Stepping = false;
  57. digitalWrite(signal_pin, LOW);
  58. }
  59. }
  60. }