#define DISTANCE 1 // Define the discrete length of a step int StepCounter = 0; bool Stepping = false; /* Declare flag pin to send digital output to the RASPBERRY PI */ const int signal_pin = 12; /* Easy Driver pins */ const int driver_dir = 8; const int driver_stp = 9; /* Physical buttons */ const int button_up = 2; const int button_down = 3; void setup() { /* Report state of automata: listening or stepping? */ pinMode(signal_pin, OUTPUT); digitalWrite(signal_pin, LOW); /* Easy Driver To control direction. Set as LOW for UP direction and HIGH for DOWN direction */ pinMode(driver_dir, OUTPUT); /* To step one step */ pinMode(driver_stp, OUTPUT); digitalWrite(driver_dir, LOW); // Starting direction is UP digitalWrite(driver_stp, LOW); // No-step /* Up */ pinMode(button_up, INPUT); // physical button step-up /* Down */ pinMode(button_down, INPUT); // physical button step-down } void loop() { /* Check up direction with */ if ((digitalRead(button_up) == LOW) && (Stepping == false )) { digitalWrite(driver_dir, LOW); Stepping = true; digitalWrite(signal_pin, HIGH); } /* Check down direction with */ if ((digitalRead(button_down) == LOW) && (Stepping == false )) { digitalWrite(driver_dir, HIGH); Stepping = true; digitalWrite(signal_pin, HIGH); } /* If wished, go ahead and step */ if (Stepping == true) { digitalWrite(driver_stp, HIGH); delay(1); digitalWrite(driver_stp, LOW); delay(1); StepCounter += 1; if (StepCounter == DISTANCE) { StepCounter = 0; Stepping = false; digitalWrite(signal_pin, LOW); } } }