exercices:arduino
Différences
Ci-dessous, les différences entre deux révisions de la page.
| Les deux révisions précédentesRévision précédenteProchaine révision | Révision précédente | ||
| exercices:arduino [2026/10/08 09:24] – [Arduino moteur 2 sens Via L293D] admin | exercices:arduino [2026/10/08 15:33] (Version actuelle) – [Code Block] admin | ||
|---|---|---|---|
| Ligne 281: | Ligne 281: | ||
| ====== Arduino moteur 2 sens Via L293D ====== | ====== Arduino moteur 2 sens Via L293D ====== | ||
| + | |||
| + | == Doc L293D == | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | [[https:// | ||
| + | |||
| + | [[start: | ||
| {{ : | {{ : | ||
| {{ : | {{ : | ||
| + | |||
| + | == Plans == | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | {{ : | ||
| + | |||
| + | == Code Block == | ||
| + | |||
| + | **Tinkercad** | ||
| + | {{ : | ||
| + | |||
| + | **Vittascience** | ||
| + | {{ : | ||
| + | |||
| + | == Code C++ == | ||
| + | |||
| + | <code c arduinomoteurL293D.ino> | ||
| + | // Motor A connections | ||
| + | int enA = 9; | ||
| + | int in1 = 8; | ||
| + | int in2 = 7; | ||
| + | |||
| + | void setup() { | ||
| + | // Set all the motor control pins to outputs | ||
| + | pinMode(enA, | ||
| + | pinMode(in1, | ||
| + | pinMode(in2, | ||
| + | | ||
| + | |||
| + | // Turn off motors - Initial state | ||
| + | digitalWrite(in1, | ||
| + | digitalWrite(in2, | ||
| + | |||
| + | } | ||
| + | |||
| + | void loop() { | ||
| + | directionControl(); | ||
| + | delay(1000); | ||
| + | speedControl(); | ||
| + | delay(1000); | ||
| + | } | ||
| + | |||
| + | // This function lets you control spinning direction of motors | ||
| + | void directionControl() { | ||
| + | // Set motors to maximum speed | ||
| + | digitalWrite(enA, | ||
| + | | ||
| + | |||
| + | // Turn on motor A | ||
| + | digitalWrite(in1, | ||
| + | digitalWrite(in2, | ||
| + | delay(2000); | ||
| + | |||
| + | // Now change motor directions | ||
| + | digitalWrite(in1, | ||
| + | digitalWrite(in2, | ||
| + | delay(2000); | ||
| + | |||
| + | // Turn off motors | ||
| + | digitalWrite(in1, | ||
| + | digitalWrite(in2, | ||
| + | } | ||
| + | |||
| + | // This function lets you control speed of the motors | ||
| + | void speedControl() { | ||
| + | // Turn on motors | ||
| + | digitalWrite(in1, | ||
| + | digitalWrite(in2, | ||
| + | | ||
| + | |||
| + | // Accelerate from zero to maximum speed | ||
| + | for (int i = 0; i < 256; i++) { | ||
| + | analogWrite(enA, | ||
| + | delay(20); | ||
| + | } | ||
| + | |||
| + | // Decelerate from maximum speed to zero | ||
| + | for (int i = 255; i >= 0; --i) { | ||
| + | analogWrite(enA, | ||
| + | delay(20); | ||
| + | } | ||
| + | |||
| + | // Now turn off motors | ||
| + | digitalWrite(in1, | ||
| + | digitalWrite(in2, | ||
| + | } | ||
| + | </ | ||
| + | |||
/home/chanteri/www/fablab37110/data/attic/exercices/arduino.1791444250.txt.gz · Dernière modification : de admin
