//X25_test_avec_moniteur---------------------------------------------------------------------- // https://github.com/clearwater/SwitecX25 // // This is an example of using the SwitchX25 library. // It zero's the motor, sets the position to mid-range // and waits for serial input to indicate new motor positions. // // Open the serial monitor and try entering values // between 0 and 944. // // Note that the maximum speed of the motor will be determined // by how frequently you call update(). If you put a big slow // serial.println() call in the loop below, the motor will move // very slowly! //---------------------------------------------------------------------- #include // standard X25.168 range 315 degrees at 1/3 degree steps #define STEPS (315*3) // For motors connected to digital pins 10,11,12,13 SwitecX25 motor1(STEPS,10,11,12,13); void setup(void) { // run the motor against the stops motor1.zero(); // start moving towards the center of the range motor1.setPosition(STEPS/2); Serial.begin(9600); Serial.print("Enter a step position from 0 through "); Serial.print(STEPS-1); Serial.println("."); } void loop(void) { static int nextPos = 0; // the motor only moves when you call update motor1.update(); if (Serial.available()) { char c = Serial.read(); if (c==10 || c==13) { Serial.println(nextPos); motor1.setPosition(nextPos); nextPos = 0; } else if (c>='0' && c<='9') { nextPos = 10*nextPos + (c-'0'); } } }