const int direction_pin = 26; const int step_pin = 27; const int left_button = 29; const int right_button = 6; int go_left = LOW; int go_right = false; void setup() { // put your setup code here, to run once: pinMode(direction_pin, OUTPUT); pinMode(step_pin, OUTPUT); pinMode(left_button, INPUT_PULLDOWN); pinMode(right_button, INPUT_PULLDOWN); } void step() { while (go_left == HIGH){ // move left digitalWrite(direction_pin, LOW); digitalWrite(step_pin, HIGH); delayMicroseconds(1000); digitalWrite(step_pin, LOW); delayMicroseconds(1000); go_left = LOW; } while (go_right == HIGH){ // move right digitalWrite(direction_pin, HIGH); digitalWrite(step_pin, HIGH); delayMicroseconds(1000); digitalWrite(step_pin, LOW); delayMicroseconds(1000); go_right = LOW; } } void loop(){ go_left = digitalRead(left_button); go_right = digitalRead(right_button); step(); Serial.print("output:"); Serial.print(go_left); Serial.print("|"); Serial.println(go_right); delayMicroseconds(1000); }