Created
August 26, 2021 18:24
-
-
Save joshua-8/c1536ee2a1ed93e557bcf56d7ab02494 to your computer and use it in GitHub Desktop.
ESC/Servo serial control
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
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