Skip to content

Instantly share code, notes, and snippets.

@daisycamber
Created April 2, 2020 22:20
Show Gist options
  • Save daisycamber/fb02482230e019c71c41dcd564df4012 to your computer and use it in GitHub Desktop.
Save daisycamber/fb02482230e019c71c41dcd564df4012 to your computer and use it in GitHub Desktop.
Arduino servo test
#include <Servo.h>
Servo s1;
Servo s2;
Servo s3;
void setup() {
// put your setup code here, to run once:
s1.attach(9);
s2.attach(10);
s3.attach(11);
s1.write(255/4*2);
s2.write(255/4*2);
s3.write(255/4*2);
Serial.open(11260);
}
byte servo = 0;
void loop() {
// put your main code here, to run repeatedly:
if(Serial.available()){
String c2 = Serial.readString();
while(!Serial.available()){
delay(10);
}
String c = Serial.readString();
servo = c2.toInt();
if(servo == 0){
s1.write(c.toInt());
} else if(servo == 1){
s2.write(c.toInt());
} else if(servo == 2){
s3.write(c.toInt());
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment