Last active
January 5, 2017 13:58
-
-
Save jnsdbr/f400b8e85a7df77558f618f65683caae to your computer and use it in GitHub Desktop.
Test sketch for the Hitec HS-785HB
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
// zoomkat 12-25-13 serial servo test | |
// type servo position 0 to 180 in serial monitor | |
// or for writeMicroseconds, use a value like 1500 | |
// Send an a to attach servo or d to detach servo | |
// for IDE 1.0.5 and later | |
// Powering a servo from the arduino usually *DOES NOT WORK*. | |
#include <Servo.h> | |
String readString; //String captured from serial port | |
Servo myservo; // create servo object to control a servo | |
int n; //value to write to servo | |
void setup() { | |
Serial.begin(9600); | |
myservo.writeMicroseconds(1500); //set initial servo position if desired | |
myservo.attach(11, 1050, 1950); //the pin for the servo control, and range if desired | |
Serial.println("servo all-in-one test code 12-25-13"); // so I can keep track of what is loaded | |
Serial.println(); | |
myservo.write(0); | |
} | |
void loop() { | |
while (Serial.available()) { | |
char c = Serial.read(); //gets one byte from serial buffer | |
readString += c; //makes the string readString | |
delay(2); //slow looping to allow buffer to fill with next character | |
} | |
if (readString.length() >0) { | |
Serial.println(readString); //so you can see the captured string | |
n = readString.toInt(); //convert readString into a number | |
if (n < 61) | |
{ | |
Serial.print("writing Angle: "); | |
Serial.println(n); | |
myservo.write(n); | |
} | |
bailout: //reenter code loop | |
Serial.print("Last servo command position: "); | |
Serial.println(myservo.read()); | |
Serial.println(); | |
readString=""; //empty for next input | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment