Étape 2: programmation
à newtonlabs
Dim readString ;
#include < Servo.h >
Servo myservo ; Créez l’objet servo pour contrôler un servo
Servo myservo2 ; créer le second objet de servo
const int gauche = 10 ; broche du moteur gauche sur arduino
const int droite = 9 ; droit d’axe du moteur sur l’arduino
void setup() {}
Serial.Begin(9600) ;
Serial.println("servo-test-22-Dual-Input") ; Si je peux garder une trace de ce qui est chargé
}
void loop() {}
tandis que (Serial.available()) {}
char c = Serial.read() ; Obtient un octet de mémoire tampon série
readString += c ; rend la chaîne readString
Delay(2) ; ralentir une boucle pour laisser le tampon de remplir avec le caractère suivant
}
Si (readString.length() > 0) {}
Serial.println(ReadString) ; ainsi vous pouvez voir la chaîne capturée
Si (readString == « l ») / / acfivates gauche servo seulement
{
myservo.Attach(Left) ; écrit tant au moteur gauche
myservo2.Attach(Left) ;
}
Si (readString == « r ») / / active servo de droite uniquement
{
myservo.Attach(Right) ; écrit tant au moteur gauche
myservo2.Attach(Right) ;
}
Si (readString == « b ») / / active les deux moteurs
{
myservo.Attach(Left) ; écrivant au moteur gauche
myservo2.Attach(Right) ; écrivant à moteur droite
}
int n = readString.toInt() ; convertir un nombre de readString
auto select valeur appropriée, copié à partir quelqu'un elses code.
Si (n > = 500)
{
Serial.Print ("écriture microsecondes:") ; affichage en série
Serial.println(n) ; nombre
myservo.writeMicroseconds(n) ; écrit aux ports
myservo2.writeMicroseconds(n) ;
}
d’autre
{
Serial.Print (« Angle d’écriture: ") ; affichage en série
Serial.println(n) ; nombre
myservo.Write(n) ; écrit aux ports
myservo2.Write(n) ;
}
readString = "" ; vide pour l’entrée suivante
}
}