Last active
August 29, 2015 14:06
-
-
Save lucabelluccini/634ac94bc11a8ef8f9f5 to your computer and use it in GitHub Desktop.
Parallax Continuous Servo example (http://www.parallax.com/product/900-00025)
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
#include <Servo.h> | |
// Parallax Continuous Servo example (http://www.parallax.com/product/900-00025) | |
// Read values from serial and set the speed of the servo | |
// Range 0 to 180; 90 is no movement | |
// Remember to set the proper baud rate and carriage return settings | |
Servo theServo; | |
int gSpeed = 90; | |
void setup() | |
{ | |
Serial.begin(9600); | |
theServo.attach(9); // attaches the servo on pin 9 to the servo object | |
} | |
void loop() | |
{ | |
while (Serial.available() > 0) { | |
gSpeed = Serial.parseInt(); | |
if (Serial.read() == '\n') { | |
gSpeed = constrain(gSpeed, 0, 180); | |
Serial.print(gSpeed, HEX); | |
theServo.write(gSpeed); | |
} | |
} | |
delay(20); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment