Skip to content

@dnet /stepper_repl.ino
Created

Embed URL

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Arduino workshop: nagyobb vasak (2012. december 6.)
// 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
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.