Étape 19 : programme
Voici un programme qui s’exécute tous les servos et un petit haut-parleur :////////////////////////// ARDUINO /////////////////////
teste tous les servos et le son
#include < Servo.h >
Servo armRight ; Créez l’objet servo pour contrôler un servo
int pos = 0 ; variable pour stocker la position du servo
Servo armLeft ;
Tête de servo ;
Servo wheelRight ;
Servo wheelLeft ;
int soundPin = 3 ;
int hauteur ;
void setup()
{
armRight.attach(11) ;
Head.Attach(10) ;
armLeft.attach(9) ;
wheelRight.attach(6) ;
wheelLeft.attach(5) ;
}
void loop()
{
pour (pos = 0; pos < 180; pos += 1) / / va de 0 degrés à 180 degrés
{/ / par incréments de 1 degré
armLeft.write(pos) ;
armRight.write(pos) ; dire de servo pour aller à positionner dans la variable « pos »
Head.Write(POS) ;
wheelRight.write(pos) ;
wheelLeft.write(pos) ;
hauteur = carte (pos, 0, 180, 31,4978) ; carte de position à ton
ton (soundPin, pitch, 200) ; broche, note, temps ?
Delay(15) ; attend 15 ms pour le servo atteindre la position
}
pour (pos = 180; pos > = 1; pos-= 1) / / va de 180 degrés à 0 degrés
{
armLeft.write(pos) ;
armRight.write(pos) ; dire de servo pour aller à positionner dans la variable « pos »
Head.Write(POS) ;
wheelRight.write(pos) ;
wheelLeft.write(pos) ;
hauteur = carte (pos, 0, 180, 31,1000) ;
ton (soundPin, pitch, 200) ; broche, note, temps ?
Delay(15) ;
} / / attend 15ms pour le servo atteindre la position
}