//// Example 8, Master, Tansmitter, one encoder controls one stepper motor //#define outputA 6 //#define outputB 7 //#include // //int8_t counter = 0; //int aState; //int aLastState; //int8_t stepper_1_pos[30]={}; //int i; //void setup() { // Serial.begin(9600); // Wire.begin(); // pinMode (outputA,INPUT); // pinMode (outputB,INPUT); // aLastState = digitalRead(outputA); // i=0; //} //void loop(){ // aState = digitalRead(outputA); // Reads the "current" state of the outputA // // If the previous and the current state of the outputA are different, that means a Pulse has occured // if (aState != aLastState){ // // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise // if (digitalRead(outputB) != aState) { // counter ++; // } // else { // counter --; // } // stepper_1_pos[i]=counter; // Wire.beginTransmission(9);// send through I2C to slave, 9 here is the address of the slave board // Wire.write(stepper_1_pos[i]);//Transfers the value of potentiometer to the slave board // Wire.endTransmission(); // i++; // } // aLastState = aState; // Updates the previous state of the outputA with the current state //} //// Slave, receiver, which controls the motor //#include //#include //#define pushbutton 2 //int buttonState, buttonStateLast; //const int stepsPerRevolution = 2038; // the number of steps in one revolution of your motor (28BYJ-48) //// initialize the stepper library on pins 8 through 11: //Stepper myStepper_1(stepsPerRevolution, 13, 11, 12, 10); // 8, 10, 9, 11 //int8_t stepper_1_pos_rec[100]={};//they need to be 8-bit signed numbers. byte is unsigned, int is 16-bit. //int8_t stepSize[100]={}; //int i, j, m, n, k; // //void setup() { // pinMode(pushbutton,INPUT);//detect the pushbutton triggering to send the data to the motor // myStepper_1.setSpeed(5); // 5 rpm // Wire.begin(9);// matching the address defined in the master. // Wire.onReceive(receiveEvent);// whenever receives anything will trigger the receiveEvent() function // Serial.begin(9600); // i=0; // buttonState=0; // buttonStateLast=0; //} //void receiveEvent(int8_t bytes){ // stepper_1_pos_rec[i]=Wire.read(); // Serial.println(stepper_1_pos_rec[i]); // i++; //} //void loop(){ // buttonState=digitalRead(pushbutton); // if (buttonState != buttonStateLast && buttonState ==HIGH){ // for(m=0;m