Étape 4: Le Code
Ouvrez l’environnement Arduino. Ensuite, copiez et collez-le dans une nouvelle esquisse.
Puis télécharger le code de la carte Arduino.
#include < Servo.h >
Servo myservo ; Créez l’objet servo pour contrôler un servo
int ResetTimer = 0 ; ensembles de retardent pour réinitialiser la position
int GoalPosition = 3 ; stocke la postion de but (1-5) où la personne est debout
int GoalPositionDegrees ; stocke la position de l’objectif en degrés (30-150)
int CurrentPositionDegrees = 90 ; stocke la position actuelle en degrés (30-150)
PinFiveAverage = PinFiveAverage + (PinFiveCurrent-PinFiveAverage) / AveragingSpeed ;
calcule le ratio de la valeur actuelle de broche à broche valeur moyenne
RatioPinOne = (float) PinOneCurrent/PinOneAverage ;
RatioPinTwo = (float) PinTwoCurrent/PinTwoAverage ;
RatioPinThree = (float) PinThreeCurrent/PinThreeAverage ;
RatioPinFour = (float) PinFourCurrent/PinFourAverage ;
RatioPinFive = (float) PinFiveCurrent/PinFiveAverage ;
déterminer quel ratio est le plus important et définit la position de l’objectif
définir la position de l’objectif
Si (RatioPinThree < seuil & & RatioPinThree < RatioPinOne & & RatioPinThree < RatioPinTwo & & RatioPinThree < RatioPinFour & & RatioPinThree < RatioPinFive)
{GoalPosition = 3 ;
ResetTimer = 0 ; }
ElseIf (RatioPinOne < seuil & & RatioPinOne < RatioPinTwo & & RatioPinOne < RatioPinThree & & RatioPinOne < RatioPinFour & & RatioPinOne < RatioPinFive)
{GoalPosition = 1 ;
ResetTimer = 0 ; }
ElseIf (RatioPinTwo < seuil & & RatioPinTwo < RatioPinOne & & RatioPinTwo < RatioPinThree & & RatioPinTwo < RatioPinFour & & RatioPinTwo < RatioPinFive)
{GoalPosition = 2 ;
ResetTimer = 0 ; }
ElseIf (RatioPinFour < seuil & & RatioPinFour < RatioPinOne & & RatioPinFour < RatioPinTwo & & RatioPinFour < RatioPinThree & & RatioPinFour < RatioPinFive)
{GoalPosition = 4 ;
ResetTimer = 0 ; }
ElseIf (RatioPinFive < seuil & & RatioPinFive < RatioPinOne & & RatioPinFive < RatioPinTwo & & RatioPinFive < RatioPinThree & & RatioPinFive < RatioPinFour)
{GoalPosition = 5 ;
ResetTimer = 0 ; }
ElseIf (ResetTimer > 100) //after retard rétablit au poste 3
{GoalPosition = 3 ;
ResetTimer = 0 ; }
d’autre
{ResetTimer = ResetTimer + 1 ; }
GoalPositionDegrees = GoalPosition * 25 + 15 ; convertit en degrés la position de l’objectif
myservo.Write(GoalPositionDegrees) ; définit la position du servo selon la valeur à l’échelle
Delay(30) ; définit comment quckly le servo tourne (abaisser le nombre de tour plus rapidement)
}