Created
August 18, 2013 18:04
-
-
Save ypelletier/6263031 to your computer and use it in GitHub Desktop.
Contrôle de deux moteurs cc au moyen d'un circuit intégré L293D ou L6205N.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/********************************************************************** | |
* Contrôle de deux moteurs cc au moyen d'un circuit intégré L293D ou L6205N. | |
* http://electroniqueamateur.blogspot.ca/2013/06/controler-deux-moteurs-cc-avec-un-l6205.html | |
***********************************************************************/ | |
#define motorPin1a 3 // Marche avant du premier moteur | |
#define motorPin1b 4 // Marche arrière du premier moteur | |
#define speedPin1 9 // Enable pin pour le premier moteur | |
#define motorPin2a 5 // Marche avant du deuxième moteur | |
#define motorPin2b 6 // Marche arrière du deuxième moteur | |
#define speedPin2 10 // Enable pin pour le deuxième moteur | |
int Mspeed = 0; // vitesse du moteur (0 à 1023) | |
unsigned long time; | |
void setup() { | |
// réglage des pins à output | |
pinMode(motorPin1a, OUTPUT); | |
pinMode(motorPin1b, OUTPUT); | |
pinMode(speedPin1, OUTPUT); | |
pinMode(motorPin2a, OUTPUT); | |
pinMode(motorPin2b, OUTPUT); | |
pinMode(speedPin2, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
// les deux moteurs en marche avant, à vitesse moyenne, pendant 10 secondes | |
Serial.println("Vitesse moyenne, marche avant"); | |
Mspeed = 500; // 0 à 1023 | |
time = millis(); | |
while((millis()-time) < 10000){ | |
analogWrite(speedPin1, Mspeed); | |
digitalWrite(motorPin1a, LOW); | |
digitalWrite(motorPin1b, HIGH); | |
analogWrite(speedPin2, Mspeed); | |
digitalWrite(motorPin2a, LOW); | |
digitalWrite(motorPin2b, HIGH); | |
} | |
delay(2000); | |
// un seul moteur en marche, à vitesse lente | |
Serial.println("Vitesse lente, moteur 1 en marche avant"); | |
Mspeed = 50; // 0 à 1023 | |
time = millis(); | |
while((millis()-time) < 2000){ | |
analogWrite(speedPin1, Mspeed); | |
digitalWrite(motorPin1a, LOW); | |
digitalWrite(motorPin1b, HIGH); | |
analogWrite(speedPin2, Mspeed); | |
digitalWrite(motorPin2a, LOW); | |
digitalWrite(motorPin2b, LOW); | |
} | |
delay(2000); | |
// l'autre moteur en marche arrière, vitesse maximale | |
Serial.println("Vitesse rapide, moteur 2 en marche arrière"); | |
Mspeed = 1000; // 0 à 1023 | |
time = millis(); | |
while((millis()-time) < 2000){ | |
analogWrite(speedPin1, Mspeed); | |
digitalWrite(motorPin1a, LOW); | |
digitalWrite(motorPin1b, LOW); | |
analogWrite(speedPin2, Mspeed); | |
digitalWrite(motorPin2a, HIGH); | |
digitalWrite(motorPin2b, LOW); | |
} | |
delay(2000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment