From a9c35402e78087e8f1168bed9cda4679f21a6c7b Mon Sep 17 00:00:00 2001
From: Thomas-Alexandre Moreau <thomalex.moreau@gmail.com>
Date: Tue, 11 Mar 2025 11:03:30 +0100
Subject: [PATCH] Push files

---
 README.md                    |  14 ++
 robot_automatique.ino        | 248 +++++++++++++++++++++++++++++++++++
 robot_automatique_LEGACY.ino | 236 +++++++++++++++++++++++++++++++++
 3 files changed, 498 insertions(+)
 create mode 100644 README.md
 create mode 100644 robot_automatique.ino
 create mode 100644 robot_automatique_LEGACY.ino

diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7d849a0
--- /dev/null
+++ b/README.md
@@ -0,0 +1,14 @@
+# Atelier Hiver 2025
+
+## Description
+
+https://projets.cohabit.fr/redmine/projects/ateliers/wiki/Atelier_hiver_2025
+
+## Fichiers
+
+* `robot_automatique_LEGACY.ino`  
+Le fichier utilisé lors de l'atelier. 
+
+* `robot_automatique.ino`  
+Une mise à jour personnelle du fichier une fois l'atelier terminé. L'utilisation est encore plus simplifiée et permet surtout de ne pas pouvoir lancer le code du robot juste en l'alimentant (évite que le robot se déplace tout seul lorsque l'on souhaite téléverser du code). Il faut appuyer sur le bouton BOOT pour lancer le code et RST pour arrêter prématurément son exécution. [_Voir explication_](https://projets.cohabit.fr/redmine/projects/ateliers/wiki/Atelier_hiver_2025#Pour-continuer-chez-soi-mis-%C3%A0-jour-apr%C3%A8s-latelier-le-270225)
+
diff --git a/robot_automatique.ino b/robot_automatique.ino
new file mode 100644
index 0000000..ae82584
--- /dev/null
+++ b/robot_automatique.ino
@@ -0,0 +1,248 @@
+//Définition des ports pour controler les moteurs
+//Moteur gauche :
+#define IN1a 27
+#define IN2a 14
+#define IN3a 12
+#define IN4a 13
+//Moteur droit :
+#define IN1b 5
+#define IN2b 18
+#define IN3b 19
+#define IN4b 21
+
+#define BUTTON_PIN 0
+
+//Temps d'attente entre deux impulsions :
+int delayTime = 3;
+
+//Code éxécuté au démarrage (paramétrage) :
+void setup() {
+  //On indique que les ports de controle des moteurs sont des sorties (output)
+  pinMode(IN1a, OUTPUT);
+  pinMode(IN2a, OUTPUT);
+  pinMode(IN3a, OUTPUT);
+  pinMode(IN4a, OUTPUT);
+
+  pinMode(IN1b, OUTPUT);
+  pinMode(IN2b, OUTPUT);
+  pinMode(IN3b, OUTPUT);
+  pinMode(IN4b, OUTPUT);
+
+  pinMode(BUTTON_PIN, INPUT_PULLUP);
+
+  Serial.begin(115200);  //Démarrage d'une communication Série avec l'ordinateur s'il est connecté
+}
+
+//Code éxécuté en boucle jusqu'à l'extinction du robot
+void loop() {
+
+  int buttonState = digitalRead(BUTTON_PIN);
+
+  if (buttonState == LOW) {
+    delay(1000);
+    
+    // Fonctions disponibles :
+    // - forward(<distance en centimètre>);
+    // - backward(<distance en centimètre>);
+    // - left(<rotation en degré>);
+    // - right(<rotation en degré>);
+
+    // --- DEBUT DU CODE --- //
+
+    
+
+    // ---- FIN DU CODE ---- //
+  }
+}
+
+
+
+//Fonction pour convertir une longueur en cm vers un nombre de pas moteur.
+int convertLengthToSteps(float length) {
+  float result = length * 512 / (4 * 3.1415);
+  return int(result);
+}
+
+//fonction pour convertir une rotation en degrés vers un nombre de pas moteur
+int convertRotToSteps(int rotation) {
+  int result = convertLengthToSteps(rotation * 3.1415 / 180 * 7.8);
+  return result;
+}
+
+
+void forward(int length) {
+  for (int i = 0; i < convertLengthToSteps(length); i++) {
+    digitalWrite(IN4a, HIGH);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, HIGH);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, HIGH);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, HIGH);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, HIGH);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, HIGH);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, HIGH);
+    digitalWrite(IN4b, HIGH);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+  }
+}
+
+void backward(int length) {
+  for (int i = 0; i < convertLengthToSteps(length); i++) {
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, HIGH);
+    digitalWrite(IN4b, HIGH);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, HIGH);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, HIGH);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, HIGH);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, HIGH);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, HIGH);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, HIGH);
+    delay(delayTime);
+  }
+}
+
+void right(int deg) {
+  for (int i = 0; i < convertRotToSteps(deg); i++) {
+    digitalWrite(IN4a, HIGH);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, HIGH);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, HIGH);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, HIGH);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, HIGH);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, HIGH);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, HIGH);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, HIGH);
+    delay(delayTime);
+  }
+}
+
+void left(int deg) {
+  for (int i = 0; i < convertRotToSteps(deg); i++) {
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, HIGH);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, HIGH);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, HIGH);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, HIGH);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, HIGH);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, HIGH);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, HIGH);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, HIGH);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+  }
+}
+
+
+void stopMotors(void) {
+  digitalWrite(IN4a, LOW);
+  digitalWrite(IN3a, LOW);
+  digitalWrite(IN2a, LOW);
+  digitalWrite(IN1a, LOW);
+
+  digitalWrite(IN4b, LOW);
+  digitalWrite(IN3b, LOW);
+  digitalWrite(IN2b, LOW);
+  digitalWrite(IN1b, LOW);
+}
diff --git a/robot_automatique_LEGACY.ino b/robot_automatique_LEGACY.ino
new file mode 100644
index 0000000..4920ab0
--- /dev/null
+++ b/robot_automatique_LEGACY.ino
@@ -0,0 +1,236 @@
+//Définition des ports pour controler les moteurs
+//Moteur gauche :
+#define IN1a 27
+#define IN2a 14
+#define IN3a 12
+#define IN4a 13
+//Moteur droit :
+#define IN1b 5
+#define IN2b 18
+#define IN3b 19
+#define IN4b 21
+
+//Temps d'attente entre deux impulsions :
+int delayTime = 3;
+
+//Code éxécuté au démarrage (paramétrage) :
+void setup() {
+  //On indique que les ports de controle des moteurs sont des sorties (output)
+  pinMode(IN1a, OUTPUT);
+  pinMode(IN2a, OUTPUT);
+  pinMode(IN3a, OUTPUT);
+  pinMode(IN4a, OUTPUT);
+
+  pinMode(IN1b, OUTPUT);
+  pinMode(IN2b, OUTPUT);
+  pinMode(IN3b, OUTPUT);
+  pinMode(IN4b, OUTPUT);
+
+
+  Serial.begin(115200);  //Démarrage d'une communication Série avec l'ordinateur s'il est connecté
+
+  delay(2000);
+
+  // DEBUT DU CODE
+  // Fonctions disponibles : forward(<distance en cm>) | backward(<distance en cm>) | left(<rotation en degré>) | right(<rotation en degré>)
+
+  
+
+  // FIN DU CODE
+}
+
+//Code éxécuté en boucle jusqu'à l'extinction du robot
+void loop() {
+}
+
+
+
+//Fonction pour convertir une longueur en cm vers un nombre de pas moteur.
+int convertLengthToSteps(float length) {
+  float result = length * 512 / (4 * 3.1415);
+  return int(result);
+}
+
+//fonction pour convertir une rotation en degrés vers un nombre de pas moteur
+int convertRotToSteps(int rotation) {
+  int result = convertLengthToSteps(rotation * 3.1415 / 180 * 7.8);
+  return result;
+}
+
+
+void forward(int length) {
+  for (int i = 0; i < convertLengthToSteps(length); i++) {
+    digitalWrite(IN4a, HIGH);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, HIGH);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, HIGH);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, HIGH);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, HIGH);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, HIGH);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, HIGH);
+    digitalWrite(IN4b, HIGH);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+  }
+}
+
+void backward(int length) {
+  for (int i = 0; i < convertLengthToSteps(length); i++) {
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, HIGH);
+    digitalWrite(IN4b, HIGH);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, HIGH);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, HIGH);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, HIGH);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, HIGH);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, HIGH);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, HIGH);
+    delay(delayTime);
+  }
+}
+
+void right(int deg) {
+  for (int i = 0; i < convertRotToSteps(deg); i++) {
+    digitalWrite(IN4a, HIGH);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, HIGH);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, HIGH);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, HIGH);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, HIGH);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, HIGH);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, HIGH);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, HIGH);
+    delay(delayTime);
+  }
+}
+
+void left(int deg) {
+  for (int i = 0; i < convertRotToSteps(deg); i++) {
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, HIGH);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, HIGH);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, HIGH);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, HIGH);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, LOW);
+    digitalWrite(IN3a, HIGH);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, LOW);
+    digitalWrite(IN3b, HIGH);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+    digitalWrite(IN4a, HIGH);
+    digitalWrite(IN3a, LOW);
+    digitalWrite(IN2a, LOW);
+    digitalWrite(IN1a, LOW);
+    digitalWrite(IN4b, HIGH);
+    digitalWrite(IN3b, LOW);
+    digitalWrite(IN2b, LOW);
+    digitalWrite(IN1b, LOW);
+    delay(delayTime);
+  }
+}
+
+
+void stopMotors(void) {
+  digitalWrite(IN4a, LOW);
+  digitalWrite(IN3a, LOW);
+  digitalWrite(IN2a, LOW);
+  digitalWrite(IN1a, LOW);
+
+  digitalWrite(IN4b, LOW);
+  digitalWrite(IN3b, LOW);
+  digitalWrite(IN2b, LOW);
+  digitalWrite(IN1b, LOW);
+}