// Global variables int timeDelay = 3000; void setup(){ // declaring the four pins to be outputs pinMode(34, OUTPUT); pinMode(32, OUTPUT); pinMode(30, OUTPUT); pinMode(28, OUTPUT); // setting the inital state of the electromagnets digitalWrite(34, HIGH); digitalWrite(32, LOW); digitalWrite(30, LOW); digitalWrite(28, HIGH); delay(10); // a small time delay to allow the motor to move }// end of setup void loop(){ for(int i=0; i<202; i++){ // looping through this chunk of code for ~ a full rotation digitalWrite(30, LOW); digitalWrite(34, HIGH); delayMicroseconds(timeDelay); digitalWrite(28, LOW); digitalWrite(32, HIGH); delayMicroseconds(timeDelay); digitalWrite(34, LOW); digitalWrite(30, HIGH); delayMicroseconds(timeDelay); digitalWrite(32, LOW); digitalWrite(28, HIGH); delayMicroseconds(timeDelay); }// end of looping // preparing the electromagnets to go the other direction digitalWrite(32, HIGH); digitalWrite(28, LOW); delayMicroseconds(timeDelay*500); for(int j=0; j<204; j++){ // looping through this chunk of code for ~ a full rotation in the other direction digitalWrite(30, LOW); digitalWrite(34, HIGH); delayMicroseconds(timeDelay); digitalWrite(28, HIGH); digitalWrite(32, LOW); delayMicroseconds(timeDelay); digitalWrite(34, LOW); digitalWrite(30, HIGH); delayMicroseconds(timeDelay); digitalWrite(32, HIGH); digitalWrite(28, LOW); delayMicroseconds(timeDelay); }// end of looping // preparing the electromagnets to go the other direction digitalWrite(32, LOW); digitalWrite(28, HIGH); delayMicroseconds(timeDelay*500); }//end of loop