Étape 4: Programme de l’Arduino
Voici la programmation pour contrôler les moteurs servo petit comme vous pilotez un avion en temps réel. Ils se déplaceront que vous tournez. Cette programmation contrôle également un indicateur led pour le train d’atterrissage, un conférencier pour un avertissement de décrochage, un bouton poussoir pour aussi passer le train d’atterrissage.C’est à vous de programmer les actionneurs de taille !
#include
#include
Servo pitchservo ;
int rollVal = 0 ;
Servo rollservo ;
int pitchVal = 0 ;
int code dans ;
int flapsINT ;
int rollInt ;
int pitchInt ;
int gForceInt ;
int stallInt = 0 ;
Chaîne de KoldpinStateSTR, KpinStateSTR, Kstringnewstate, Kstringoldstate ;
String gearSimple, Rabat, flapsOld, rouleaux, pitchS, gForceS, stalles ;
void setup()
{
pinMode (sortie 2) ; Gear nez LED
pinMode (5, sortie) ; engins de nez en transition LED
pinMode(12,OUTPUT) ; Avertissement de décrochage
rollservo.Attach(8) ;
pitchservo.Attach(11) ;
Serial.Begin(115200) ;
}
void loop() {}
Serial.println(stallInt) ;
stallInt = 0 ;
pitchVal = carte (pitchInt, -25, 25, 0, 179) ;
Si (rollInt > -90 & rollInt < 90)
{rollVal = carte (rollInt, -10, 0, 10, 179);}
else {rollVal = 90;}
pitchservo.Write(pitchVal) ;
rollservo.Write(rollVal) ;
Si (étals == « 1 »)
{tone(12,140);}
else{noTone(12);}
Si (Serial.available()) {}
Code = GetChar () ;
Si (code == ' <') {LESSTHAN();}
Si (code == '?') {QUESTION();}
}
}
char GetChar ()
{
while(Serial.available() == 0) ;
Return((Char)Serial.Read()) ;
}
void LESSTHAN() {}
Code = GetChar () ;
{Switch(CodeIn)}
case « F » :
gForceS = "" ;
gForceS += GetChar () ;
gForceS += GetChar () ;
gForceS += GetChar () ;
gForceInt = gForceS.toInt() ;
rupture ;
de l’affaire ":
Cale = "" ;
Cale = "" ;
Cale = "" ;
Stalles += GetChar () ;
Serial.Print ("String:" + cale) ;
stallInt = stallS.toInt() ;
Serial.println ("Int:" + stallInt) ;
rupture ;
}
}
void QUESTION() {}
Code = GetChar () ;
{Switch(CodeIn)}
affaire « Y » :
gearSimple = "" ;
gearSimple += GetChar (); / / get premier caractère (train avant)
Si (gearSimple == « 2 ») {digitalWrite (2, HIGH);} else {digitalWrite (2, basse);}
Si (gearSimple == « 1 ») {digitalWrite (5, HIGH);} else {digitalWrite (5, LOW);}
affaire « y » :
pitchS = "" ;
pitchS += GetChar () ;
pitchS += GetChar () ;
pitchS += GetChar () ;
pitchS += GetChar () ;
pitchS += GetChar () ;
pitchS += GetChar () ;
pitchInt = pitchS.toInt() ;
rupture ;
case « x » :
petits pains = "" ;
petits pains += GetChar () ;
petits pains += GetChar () ;
petits pains += GetChar () ;
petits pains += GetChar () ;
petits pains += GetChar () ;
petits pains += GetChar () ;
rollInt = rollS.toInt() ;
rupture ;
}
} / / fin de question vide