Skip to content

Instantly share code, notes, and snippets.

@dnet
Created December 6, 2012 19:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dnet/4227625 to your computer and use it in GitHub Desktop.
Save dnet/4227625 to your computer and use it in GitHub Desktop.
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