1 // Adafruit Motor shield library
2 // copyright Adafruit Industries LLC, 2009
3 // this code is public domain, enjoy!
7 // Connect a stepper motor with 48 steps per revolution (7.5 degree)
8 // to motor port #2 (M3 and M4)
9 AF_Stepper motor(48, 2);
12 Serial.begin(9600); // set up Serial library at 9600 bps
13 Serial.println("Stepper test!");
15 motor.setSpeed(10); // 10 rpm
19 // Serial.println("Single coil steps");
20 // motor.step(100, FORWARD, SINGLE);
21 // motor.step(100, BACKWARD, SINGLE);
23 if (Serial.available()) {
24 int in = Serial.read();
25 Serial.println(in, DEC);
26 if ( in == 102 ) { // f
27 Serial.println("Double coil steps forward");
28 motor.step(48, FORWARD, DOUBLE);
29 } else if ( in == 98 ) { // b
30 Serial.println("Double coil steps backward");
31 motor.step(48, BACKWARD, DOUBLE);
32 } else if ( in >= 49 && in <= 57 ) {
33 int speed = ( in - 48 ) * 10;
34 Serial.print("speed ");
35 Serial.print(speed, DEC);
36 Serial.println(" rpm");
37 motor.setSpeed( speed );
41 // Serial.println("Interleave coil steps");
42 // motor.step(100, FORWARD, INTERLEAVE);
43 // motor.step(100, BACKWARD, INTERLEAVE);
45 // Serial.println("Micrsostep steps");
46 // motor.step(100, FORWARD, MICROSTEP);
47 // motor.step(100, BACKWARD, MICROSTEP);