#include #include // STEPPER_MSG Directions Received From Wire: // Values 1-30: Go to Position // Value -1: Turn Left // Value 0: Stay Put //Stepper Motor 1 int STEPPER_MSG; int PREV_MSG; int MSG; int POSITION; const int stepsPerRevolution = 200; Stepper myStepper(stepsPerRevolution, 8, 9, 10, 11); void setup(){ Wire.begin(9); // Start I2C Bus as Slave on Address 9 Wire.onReceive(receiveEvent); Serial.begin(9600); myStepper.setSpeed(60); } void receiveEvent(int bytes) { STEPPER_MSG = Wire.read(); // read one character from the I2C } int steps = 0; void loop(){ Serial.println(STEPPER_MSG); int GEAR_RATIO = 20; int STEPS_TOTAL = STEPPER_MSG * GEAR_RATIO; Serial.println("STEPS_TOTAL: " + (String) STEPS_TOTAL); while (STEPPER_MSG > 0 & steps <= STEPS_TOTAL) { Serial.println("Steps done: " + steps); steps++; myStepper.step(1); delay(20); // Once you Get to position, stay } //if (STEPPER_MSG 0 | steps == STEPS_TOTAL) { // steps = 0; //} while (STEPPER_MSG == 0 & steps >= 0) { myStepper.step(-1); steps--; delay(20); } }