From: Dobrica Pavlinusic Date: Sun, 2 Nov 2014 16:40:58 +0000 (+0100) Subject: drive stepper motor via serial port X-Git-Url: http://git.rot13.org/?p=Arduino;a=commitdiff_plain;h=dd1b7d2112771a635d457e84d3015199821df4cd drive stepper motor via serial port --- diff --git a/StepperSerialTest/StepperSerialTest.ino b/StepperSerialTest/StepperSerialTest.ino new file mode 100644 index 0000000..cbe8e68 --- /dev/null +++ b/StepperSerialTest/StepperSerialTest.ino @@ -0,0 +1,42 @@ +// Adafruit Motor shield library +// copyright Adafruit Industries LLC, 2009 +// this code is public domain, enjoy! + +#include + +// Connect a stepper motor with 48 steps per revolution (7.5 degree) +// to motor port #2 (M3 and M4) +AF_Stepper motor(48, 2); + +void setup() { + Serial.begin(9600); // set up Serial library at 9600 bps + Serial.println("Stepper test!"); + + motor.setSpeed(10); // 10 rpm +} + +void loop() { +// Serial.println("Single coil steps"); +// motor.step(100, FORWARD, SINGLE); +// motor.step(100, BACKWARD, SINGLE); + + if (Serial.available()) { + int in = Serial.read(); + Serial.println(in, DEC); + if ( in == 102 ) { // f + Serial.println("Double coil steps forward"); + motor.step(48, FORWARD, DOUBLE); + } else if ( in == 98 ) { // b + Serial.println("Double coil steps backward"); + motor.step(48, BACKWARD, DOUBLE); + } + } + +// Serial.println("Interleave coil steps"); +// motor.step(100, FORWARD, INTERLEAVE); +// motor.step(100, BACKWARD, INTERLEAVE); + +// Serial.println("Micrsostep steps"); +// motor.step(100, FORWARD, MICROSTEP); +// motor.step(100, BACKWARD, MICROSTEP); +}