Created
December 6, 2012 19:39
-
-
Save dnet/4227625 to your computer and use it in GitHub Desktop.
Arduino workshop: nagyobb vasak (2012. december 6.)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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