Skip to content

Instantly share code, notes, and snippets.

@SisyamoNeko
Created October 1, 2019 09:42
Show Gist options
  • Save SisyamoNeko/69a7e22751fbd9070b538a9468a052fc to your computer and use it in GitHub Desktop.
Save SisyamoNeko/69a7e22751fbd9070b538a9468a052fc to your computer and use it in GitHub Desktop.
arduinoに繋いだ複数のサーボのうち任意のヤツを動かすsketch 雛形
#include <String.h>
#include <Servo.h>
Servo sv1;
Servo sv2;
String PTangle, kari;
unsigned int ang;
void setup() {
Serial.begin(9600);
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
sv1.attach(9);
sv2.attach(10);
sv1.write(85);
sv2.write(90);
}
void loop() {
if (Serial.available() > 0) {
PTangle = Serial.readStringUntil("\n");
kari = PTangle.substring(1);
ang = kari.toInt();
if (ang >= 10 && ang <= 180) {
if (PTangle.startsWith("p")) {
ptang(sv1, ang);
} else if (PTangle.startsWith("t")) {
ptang(sv2, ang);
}
}
}
}
void ptang(Servo x, int y) {
digitalWrite(13, HIGH);
x.write(y);
delay(300);
digitalWrite(13, LOW);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment