public
Created

Arduino workshop: nagyobb vasak (2012. december 6.)

  • Download Gist
stepper_repl.ino
Arduino
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
// http://hsbp.org/arduino
 
#include <Stepper.h>
 
Stepper myStepper(100, 8, 10, 9, 11);
 
// The setup() method runs once, when the sketch starts
void setup() {
// initialize the digital pin as an output:
Serial.begin(9600);
}
// the loop() method runs over and over again,
// as long as the Arduino has power
void loop()
{
int speed = 0, step_num = 0;
Serial.print("Speed: ");
while (true) {
while (!Serial.available());
byte b = Serial.read();
Serial.write(b);
if (b <= '9' && b >= '0') {
speed = speed * 10 + b - '0';
} else if (b == '\r') {
Serial.print("Number of steps: ");
break;
}
}
boolean negative = false;
while (true) {
while (!Serial.available());
byte b = Serial.read();
Serial.write(b);
if (b <= '9' && b >= '0') {
step_num = step_num * 10 + b - '0';
} else if (b == '-') {
negative = true;
} else if (b == '\r') {
break;
}
}
myStepper.setSpeed(speed);
myStepper.step(negative ? -step_num : step_num); // -step_num if negative else step_num
}

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.