// This one has the easiest logic of all #include #define HALFSTEP 8 #define rightButton 8 //the adjust pin // Change the pin defination if you want to #define motorPin1 9 // IN1 on the ULN2003 driver 1 #define motorPin2 10 // IN2 on the ULN2003 driver 1 #define motorPin3 11 // IN3 on the ULN2003 driver 1 #define motorPin4 12 // IN4 on the ULN2003 driver 1 // Initialize construtor with pin sequence IN1-IN3-IN2-IN4 for using the AccelStepper with 28BYJ-48 AccelStepper stepper1(HALFSTEP, motorPin1, motorPin3, motorPin2, motorPin4); void setup() { Serial.begin(4800); //Remember from the Serial communication tutorial stepper1.setMaxSpeed(1000); stepper1.setAcceleration(1000); // max accelartaion seto to 1000 steps/sec^2 stepper1.setSpeed(1000); // speed set to 1000 steps/sec , this is the maximum recommended speed in the AccelStepper docs stepper1.moveTo(4096); // 4096 steps for 1 rotations in 28BYJ-48 – 5V Stepper Motor }//--(end setup )--- void loop() // the autoscroll should be cheked out from the Serial Monitor { //Many lines may seem excess but while doing Objective 2 you will know why they are here //while(Serial.available() == 0); //Loops in this line until the funtion gets any data from the Serial buffer char data = 'g';//Serial.read(); if(data == 'g') // 'g' means GO ......to switch on the Stepper after data is recieved from Atmega 3 to Atmega 2 trigger_go_go_go(); if(data == 's') // 's' will be sent which signifies STOP .......this lets you syncronize the stepper { stepper1.stop(); // First stop the motor plzz adjust(); // lets you syncronize the stepper } } void trigger_go_go_go() // Check out adjust() first, then you can easily understand { //stepper1.moveTo(4096); while(Serial.available()==0) { if(stepper1.distanceToGo() == 0) Serial.println(millis()); // To print the time spent from start up //trig_go_go_go(); go_go_go(); } loop(); } void go_go_go() // just required to move the stepper { stepper1.run(); } // this function is not required for now void adjust() // Executes if and only iff there is no Serial data coming in { stepper1.move(4096); while(Serial.available() == 0) { if(stepper1.distanceToGo() == 0) // when the stepper reaches step 4096 calls adjust() [recursion] adjust(); if(digitalRead(rightButton) == HIGH) //when the right switch is pressed the stepper moves when unpressed stops automatically go_go_go(); } loop(); // this actually means a if statement.....i.e. if(Serial.available!=0) } /////////// thats it for the 1st Atmega /////////////