Skip to content

Instantly share code, notes, and snippets.

@joshua-8
Created August 26, 2021 18:24
Show Gist options
  • Save joshua-8/c1536ee2a1ed93e557bcf56d7ab02494 to your computer and use it in GitHub Desktop.
Save joshua-8/c1536ee2a1ed93e557bcf56d7ab02494 to your computer and use it in GitHub Desktop.
ESC/Servo serial control
String inString = "";
#include <Servo.h>
Servo myservo1;
void setup() {
myservo1.attach(9);
Serial.begin(2000000);
Serial.println("ESCs Speed Control. attach pin 9 to the ESC.");
}
void loop() {
while (Serial.available() > 0) {
int inChar = Serial.read();
if (isDigit(inChar)) {
inString += (char)inChar;
}
if (inChar == '\n') {
if (inString.toInt() >= 400 && inString.toInt() <= 2600) {
Serial.println(inString.toInt());
myservo1.write((inString.toInt()));
}
inString = "";
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment