ENIB 2022 - groupe C : la course de chevaux : Différence entre versions
(7 révisions intermédiaires par 3 utilisateurs non affichées) | |||
Ligne 2 : | Ligne 2 : | ||
[[Fichier:Photoenib2018.jpg|600px]] | [[Fichier:Photoenib2018.jpg|600px]] | ||
− | ==Antoine Lefèvre / Félix Lefevre / Romain Ménez== | + | ==Antoine Lefèvre / Félix Lefevre / Romain Ménez / RANDRIANTSIZAFY Andry Manohisoa== |
==Liste des composants== | ==Liste des composants== | ||
− | * | + | * 2 boutons |
− | * | + | * 2 servo moteurs |
− | * | + | * Arduino D1 mini |
+ | * breadboard | ||
+ | |||
+ | ==Montage== | ||
+ | |||
==Code== | ==Code== | ||
<pre> | <pre> | ||
− | + | ////////////////////////// | |
+ | // La // | ||
+ | // Course // | ||
+ | // de // | ||
+ | // Cheveaux // | ||
+ | ////////////////////////// | ||
+ | /* | ||
+ | Une résistance de pullup c'est lorsque la broche est branchée | ||
+ | à une résistance reliée au niveau haut de la carte (HIGH) | ||
+ | Ce programme allume la led de la carte lorsqu'on appuie sur un bouton poussoir. | ||
+ | |||
+ | BROCHAGE | ||
+ | _________________ | ||
+ | / D1 mini \ | ||
+ | - |[ ]RST TX[ ]| - | ||
+ | - |[ ]A0 -GPIO RX[ ]| - | ||
+ | - |[ ]D0-16 5-D1[ ]| - Bouton 1 | ||
+ | - |[ ]D5-14 4-D2[ ]| - servo 1 | ||
+ | servo 2 - |[X]D6-12 0-D3[X]| - | ||
+ | - |[ ]D7-13 2-D4[ ]| - Bouton 2 | ||
+ | - |[ ]D8-15 GND[X]| - GND (Boutons, servo) | ||
+ | - |[ ]3V3 . 5V[X]| - servo | ||
+ | | +---+ | | ||
+ | |_______|USB|_______| | ||
+ | |||
+ | |||
+ | Matériel : | ||
+ | - une d1 mini | ||
+ | - 2 boutons poussoir | ||
+ | - des cables dupont | ||
+ | - 2 servo moteurs | ||
+ | |||
+ | ___ | ||
+ | / ___ \ | ||
+ | |_| | | | ||
+ | /_/ | ||
+ | _ ___ _ | ||
+ | |_| |___|_| |_ | ||
+ | ___|_ _| | ||
+ | |___| |_| | ||
+ | Les petits Débrouillards - décembre 2020 - CC-By-Sa http://creativecommons.org/licenses/by-nc-sa/3.0/ | ||
+ | */ | ||
+ | #include <Servo.h> // on ajoute la bibliothèque servo | ||
+ | |||
+ | // Déclaration des "variables" constantes | ||
+ | const int brocheBouton1 = 5;// Broche où est connectée le bouton | ||
+ | const int brocheBouton2 = 2; | ||
+ | |||
+ | Servo servoMoteur1; //On crée un objet servo appelé servoMoteur | ||
+ | Servo servoMoteur2; | ||
+ | |||
+ | // Variable d'etat | ||
+ | bool etatBouton1 = LOW; // Variable permettant de récupérer l'etat du bouton | ||
+ | int i = 0; | ||
+ | bool etatBouton2 = LOW; // Variable permettant de récupérer l'etat du bouton | ||
+ | int j = 0; | ||
+ | void setup() { | ||
+ | pinMode(brocheBouton1, INPUT_PULLUP);// Initialisation de la broche du bouton | ||
+ | pinMode(brocheBouton2, INPUT_PULLUP); | ||
+ | Serial.begin(9600); | ||
+ | servoMoteur1.attach(4); | ||
+ | servoMoteur1.write(0);// on initialise le servo sur l'angle 0 | ||
+ | servoMoteur2.attach(13); | ||
+ | servoMoteur2.write(0); | ||
+ | } | ||
+ | |||
+ | void loop() { | ||
+ | // Lecture de l'état du bouton et stockage dans la variable buttonState | ||
+ | etatBouton1 = digitalRead(brocheBouton1); | ||
+ | Serial.print("état du bouton 1: "); Serial.println(etatBouton1); | ||
+ | Serial.print("servo 1 : "); Serial.println(i); | ||
+ | if (etatBouton1 == LOW) { | ||
+ | i = i + 30; | ||
+ | servoMoteur1.write(i); | ||
+ | delay(100); | ||
+ | } | ||
+ | etatBouton2 = digitalRead(brocheBouton2); | ||
+ | Serial.print("état du bouton 2: "); Serial.println(etatBouton2); | ||
+ | Serial.print("servo 2 : "); Serial.println(j); | ||
+ | if (etatBouton2 == LOW) { | ||
+ | j = j + 30; | ||
+ | servoMoteur2.write(j); | ||
+ | delay(100); | ||
+ | } | ||
+ | |||
+ | if (i > 180) { | ||
+ | i = 0; | ||
+ | j = 0; | ||
+ | for (int k=1; k<90; k+=5) { | ||
+ | servoMoteur1.write(k); | ||
+ | servoMoteur2.write(k); | ||
+ | delay(50); | ||
+ | } | ||
+ | servoMoteur1.write(1); | ||
+ | servoMoteur2.write(1); | ||
+ | delay(1000); | ||
+ | } | ||
+ | if (j > 180) { | ||
+ | i = 0; | ||
+ | j = 0; | ||
+ | for (int g=1; g<90; g+=5) { | ||
+ | servoMoteur1.write(g); | ||
+ | servoMoteur2.write(g); | ||
+ | delay(50); | ||
+ | } | ||
+ | servoMoteur1.write(1); | ||
+ | servoMoteur2.write(1); | ||
+ | delay(1000); | ||
+ | } | ||
+ | } | ||
</pre> | </pre> | ||
Version actuelle datée du 19 janvier 2022 à 22:19
Sommaire
photo de l'équipe
Antoine Lefèvre / Félix Lefevre / Romain Ménez / RANDRIANTSIZAFY Andry Manohisoa
Liste des composants
- 2 boutons
- 2 servo moteurs
- Arduino D1 mini
- breadboard
Montage
Code
////////////////////////// // La // // Course // // de // // Cheveaux // ////////////////////////// /* Une résistance de pullup c'est lorsque la broche est branchée à une résistance reliée au niveau haut de la carte (HIGH) Ce programme allume la led de la carte lorsqu'on appuie sur un bouton poussoir. BROCHAGE _________________ / D1 mini \ - |[ ]RST TX[ ]| - - |[ ]A0 -GPIO RX[ ]| - - |[ ]D0-16 5-D1[ ]| - Bouton 1 - |[ ]D5-14 4-D2[ ]| - servo 1 servo 2 - |[X]D6-12 0-D3[X]| - - |[ ]D7-13 2-D4[ ]| - Bouton 2 - |[ ]D8-15 GND[X]| - GND (Boutons, servo) - |[ ]3V3 . 5V[X]| - servo | +---+ | |_______|USB|_______| Matériel : - une d1 mini - 2 boutons poussoir - des cables dupont - 2 servo moteurs ___ / ___ \ |_| | | /_/ _ ___ _ |_| |___|_| |_ ___|_ _| |___| |_| Les petits Débrouillards - décembre 2020 - CC-By-Sa http://creativecommons.org/licenses/by-nc-sa/3.0/ */ #include <Servo.h> // on ajoute la bibliothèque servo // Déclaration des "variables" constantes const int brocheBouton1 = 5;// Broche où est connectée le bouton const int brocheBouton2 = 2; Servo servoMoteur1; //On crée un objet servo appelé servoMoteur Servo servoMoteur2; // Variable d'etat bool etatBouton1 = LOW; // Variable permettant de récupérer l'etat du bouton int i = 0; bool etatBouton2 = LOW; // Variable permettant de récupérer l'etat du bouton int j = 0; void setup() { pinMode(brocheBouton1, INPUT_PULLUP);// Initialisation de la broche du bouton pinMode(brocheBouton2, INPUT_PULLUP); Serial.begin(9600); servoMoteur1.attach(4); servoMoteur1.write(0);// on initialise le servo sur l'angle 0 servoMoteur2.attach(13); servoMoteur2.write(0); } void loop() { // Lecture de l'état du bouton et stockage dans la variable buttonState etatBouton1 = digitalRead(brocheBouton1); Serial.print("état du bouton 1: "); Serial.println(etatBouton1); Serial.print("servo 1 : "); Serial.println(i); if (etatBouton1 == LOW) { i = i + 30; servoMoteur1.write(i); delay(100); } etatBouton2 = digitalRead(brocheBouton2); Serial.print("état du bouton 2: "); Serial.println(etatBouton2); Serial.print("servo 2 : "); Serial.println(j); if (etatBouton2 == LOW) { j = j + 30; servoMoteur2.write(j); delay(100); } if (i > 180) { i = 0; j = 0; for (int k=1; k<90; k+=5) { servoMoteur1.write(k); servoMoteur2.write(k); delay(50); } servoMoteur1.write(1); servoMoteur2.write(1); delay(1000); } if (j > 180) { i = 0; j = 0; for (int g=1; g<90; g+=5) { servoMoteur1.write(g); servoMoteur2.write(g); delay(50); } servoMoteur1.write(1); servoMoteur2.write(1); delay(1000); } }