示例#1
0
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 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;
        } 
    }
}
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); 
}