Ligne 110 : |
Ligne 110 : |
| <syntaxhighlight lang="c"> | | <syntaxhighlight lang="c"> |
| ... | | ... |
| + | |
| // ### HACK ### | | // ### HACK ### |
| // Ajouter vos variables hack | | // Ajouter vos variables hack |
Ligne 123 : |
Ligne 124 : |
| Servo monServo; | | Servo monServo; |
| unsigned long moteurTempsAvant = 0 ; | | unsigned long moteurTempsAvant = 0 ; |
| + | |
| ... | | ... |
| </syntaxhighlight> | | </syntaxhighlight> |
| + | |
| + | Dans la fonction setup : |
| + | <syntaxhighlight lang="c"> |
| + | void setup() { |
| + | ... |
| + | |
| + | // Exemple SERVO |
| + | monServo.attach( SERVO_MOTEUR ); |
| + | |
| + | // Le mettre à l'angle zéro |
| + | monServo.write( 0 ); |
| + | |
| + | ... |
| + | } |
| + | </syntaxhighlight> |
| + | |
| + | Dans les différentes phases, on va définir que uniquement l'alarme 1 possède un gong et les autres possèdent la mélodie. |
| | | |
| <syntaxhighlight lang="c"> | | <syntaxhighlight lang="c"> |
Ligne 164 : |
Ligne 183 : |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
− | * '''activerMoteur();''' dans cette fonction, il serait nécessaire de définir la position du servo à 0 | + | * '''activerMoteur();''' dans cette fonction, il faudrait remettre le servo à l'angle zéro, au cas ou il n'est pas encore définit à cette position. |
− | * '''jouerMoteur();''' | + | * '''jouerMoteur();''' dans cette fonction, il faudrait changer la position du servo moteur de façon à faire sonner le gong. |
− | * '''stopMoteur();''' | + | * '''stopMoteur();''' dans cette fonction, il faudrait remettre le servo à l'angle zéro. |
| | | |
| <syntaxhighlight lang="c"> | | <syntaxhighlight lang="c"> |
Ligne 195 : |
Ligne 214 : |
| </syntaxhighlight> | | </syntaxhighlight> |
| | | |
| + | La fonction '''effectuerAction''', ci dessous, permet de répèter une tâche tous les x temps. |
| + | |
| + | Cette fonction peut être réutiliser dans d'autres cas. |
| + | |
| + | <syntaxhighlight lang="c"> |
| + | /* |
| + | * Vérifier si c'est le moment d'effectuer l'action |
| + | * |
| + | * ARGUMENTS |
| + | * tempsAvant est temps précédent en milisecondes |
| + | * dureeAttente est le temps avant de relancer l'exécution |
| + | * |
| + | * RETURN |
| + | * 0 Signifie pas maintenant |
| + | * x valeur (unsigned long) : effectuer l'action + changer le tempsAvant (définie dans l'entête du code) |
| + | */ |
| + | unsigned long effectuerAction( unsigned long tempsAvant, int dureeAttente ){ |
| + | unsigned long maintenant = millis(); |
| + | |
| + | if( maintenant - tempsAvant >= dureeAttente ) |
| + | return maintenant; |
| + | |
| + | return 0; |
| + | } |
| + | </syntaxhighlight> |
| | | |
| | | |