void Dome::step(long val) { int move = abs(val); int moved = 0; bool hithalf = false; int accel = move / 2; while(move--) { if(Serial.available() > 0) break; motor.setSpeed(constrain(moved, MINSPEED, MAXSPEED)); motor.step(1, (val > 0)?BACKWARD:FORWARD, DOUBLE); (val > 0)?position++:position--; if(!hithalf) { moved++; if(moved >= accel) hithalf = true; } else { moved--; } } }
void release() { #if MOTOR_SHIELD_VERSION == 1 m1.release(); m2.release(); #else m1->release(); m2->release(); #endif }
void setup() { Serial.begin(9600); // set up Serial library at 9600 bps Serial.println("Stepper test!"); motor.setSpeed(10); // 10 rpm motor.release(); delay(1000); motor.step(100, BACKWARD, INTERLEAVE); }
void loop() { if (Serial.available() > 0) { int inByte = Serial.read(); switch (inByte) { case 'a': motor.step(1, BACKWARD, INTERLEAVE); Serial.println("Moved 1"); break; case 'b': motor.step(2, BACKWARD, INTERLEAVE); Serial.println("Moved 2"); break; } } }
/** * Supports movement with both styles of Motor Shield * @input newx the destination x position * @input newy the destination y position **/ void onestep(int motor,int direction) { if(motor==1) { #ifdef VERBOSE Serial.print('X'); #endif #if MOTOR_SHIELD_VERSION == 1 m1.onestep(direction); #else m1->onestep(direction>0?FORWARD:BACKWARD,SINGLE); #endif } else { #ifdef VERBOSE Serial.print('Y'); #endif #if MOTOR_SHIELD_VERSION == 1 m2.onestep(direction); #else m2->onestep(direction>0?FORWARD:BACKWARD,SINGLE); #endif } }
// // Constructor // Dome::Dome(void) { motor.setSpeed(100); // Set a default RPM of 10 //position = 0; }
void stepper_backwardstep1() { myStepper1.onestep(BACKWARD, MICROSTEP); }
// you can change these to DOUBLE or INTERLEAVE or MICROSTEP! void stepper_forwardstep1() { myStepper1.onestep(FORWARD, MICROSTEP); }
void stepper_reset_lp() { myStepper1->onestep(BACKWARD, DOUBLE); delayMicroseconds(300); }
void backwardstep() { stepper_motor.onestep(BACKWARD, DOUBLE); }
void forwardstep() { stepper_motor.onestep(FORWARD, DOUBLE); }
void backwardstep() { lat_motor.onestep( BACKWARD, INTERLEAVE ); }
void forwardstep() { lat_motor.onestep( FORWARD, INTERLEAVE ); }