#define EN 8 /* Enable pin for all stepper outputs */ #define R_DIR 5 /* Direction-Pin for right motor */ #define R_STEP 2 /* Step-Pin for right motor */ #define L_DIR 6 /* Direction-Pin for left motor*/ #define L_STEP 3 /* Step-Pin for left motor */ int command; /* Rotational direction of stepper motors*/ boolean Direction_clockwise = LOW ; boolean Direction_counterclockwise = HIGH ; /* Low = Clockwise, High = Counterclockwise */ /* to lift the booth, right motor turns counterclockwise, left motor turns clockwise */ /* with following connections on driver: 1A blue, 1B red, 2A green, 2B black */ // // step // void step() { digitalWrite(R_STEP, HIGH); digitalWrite(L_STEP, HIGH); delay (10); digitalWrite(R_STEP, LOW); digitalWrite (L_STEP, LOW); delay (10); } // // waiting for commands to control the booth // void booth_control(int command) { switch (command){ case 1: // lift structure.*/ digitalWrite(EN, LOW); //Low to enable digitalWrite(R_DIR, Direction_counterclockwise); digitalWrite(L_DIR, Direction_clockwise); break; case 2: // lower structure. digitalWrite(EN, LOW); //Low to enable digitalWrite(R_DIR, Direction_clockwise); digitalWrite(L_DIR, Direction_counterclockwise); break; case 0: // stop the motors digitalWrite(EN, HIGH); //HIGH to disable digitalWrite(R_STEP, LOW); digitalWrite (L_STEP, LOW); break; } } void setup() { Serial.begin(115200); Serial.println("\nmotors control"); /* Configure the stepper drive pins as outputs */ pinMode(EN, OUTPUT); pinMode(R_DIR, OUTPUT); pinMode(R_STEP, OUTPUT); pinMode(L_DIR, OUTPUT); pinMode(L_STEP, OUTPUT); // pinMode(switchPin, INPUT); digitalWrite(EN, HIGH); //HIGH to disable } void loop() { if(Serial.available()) { String booth_ctrl=Serial.readStringUntil('\n'); command=booth_ctrl.toInt(); booth_control(command); Serial.print(F("command: ")); Serial.println(command,DEC); } step(); }