Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Pour piloter un moteur pas à pas, 3 "commandes" sur le driver :
- // STEP qui permet de dire quand le moteur bouge d'un pas
- // DIR qui permet d'indiquer dans quel sens ton moteur tourne au prochain pas
- // ENABLE ( EN ) qui permet d'activer ou pas le driver.
- // NE PAS TOUCHER
- // Définit les numéros de pins
- // Moteur M1 sur X de la carte CNC shield
- const int stepPinM1 = 2;
- const int dirPinM1 = 5;
- // Moteur M2 sur X de la carte CNC shield
- const int stepPinM2 = 3;
- const int dirPinM2 = 6;
- // Moteur M3 sur X de la carte CNC shield
- const int stepPinM3 = 4;
- const int dirPinM3 = 7;
- const int enabled = 8;
- // 7 combinaisons possibles = M1 ou M2 ou M3 ou M1M2 ou M1M3 ou M2M3 ou M1M2M3
- int nbreAleatoire;
- void setup() {
- // NE PAS TOUCHER
- // Définit les broches de sortie des moteurs
- pinMode(stepPinM1, OUTPUT);
- pinMode(dirPinM1, OUTPUT);
- pinMode(stepPinM2, OUTPUT);
- pinMode(dirPinM2, OUTPUT);
- pinMode(stepPinM3, OUTPUT);
- pinMode(dirPinM3, OUTPUT);
- pinMode(enabled, OUTPUT);
- digitalWrite(enabled, LOW);
- }
- void loop() {
- //1 tour complet d'un moteur NEMA = 200 pas/tour
- //Gestion Moteur par moteur
- //MOTEUR M1
- int temps1 = random(0, 20000); // DÉFINIR LE TEMPS MINI ET MAX
- int nb_croq1 = random(50, 200); //NBRE DE PAS
- //MOTEUR M2
- int temps2 = random(0, 20000); // DÉFINIR LE TEMPS MINI ET MAX
- int nb_croq2 = random(50, 200); //NBRE DE PAS
- //MOTEUR M3
- int temps3 = random(0, 20000); // DÉFINIR LE TEMPS MINI ET MAX
- int nb_croq3 = random(50, 200); //NBRE DE PAS
- // Gestion Combo moteur
- //M1M2
- int temps4 = random(0, 20000); // DÉFINIR LE TEMPS MINI ET MAX
- int nb_croq4 = random(50, 200); //NBRE DE PAS
- //M1M3
- int temps5 = random(0, 20000); // DÉFINIR LE TEMPS MINI ET MAX
- int nb_croq5 = random(50, 200); //NBRE DE PAS
- //M2M3
- int temps6 = random(0, 20000); // DÉFINIR LE TEMPS MINI ET MAX
- int nb_croq6 = random(50, 200); //NBRE DE PAS
- //M1M2M3
- int temps7 = random(0, 20000); // DÉFINIR LE TEMPS MINI ET MAX
- int nb_croq7 = random(50, 200); //NBRE DE PAS
- // 7 combinaisons possibles = M1 M2 M3 M1M2 M1M3 M2M3 M1M2M3
- nbreAleatoire = random(1,7);
- // si on passe les 3 lignes suivantes en commentaire, les moteurs changent de sens
- digitalWrite(dirPinM1, HIGH);
- digitalWrite(dirPinM2, HIGH);
- digitalWrite(dirPinM3, HIGH);
- // Moteur 1
- if (nbreAleatoire == 1){
- for (int x = 0; x < nb_croq1; x++) {
- digitalWrite(stepPinM1, HIGH);
- delay(1);
- digitalWrite(stepPinM1, LOW);
- delay(1);
- }
- delay(temps1);
- }
- // Moteur 2
- if (nbreAleatoire == 2){
- for (int x = 0; x < nb_croq2; x++) {
- digitalWrite(stepPinM2, HIGH);
- delay(1);
- digitalWrite(stepPinM2, LOW);
- delay(1);
- }
- delay(temps2);
- }
- // Moteur 3
- if (nbreAleatoire == 3){
- for (int x = 0; x < nb_croq3; x++) {
- digitalWrite(stepPinM3, HIGH);
- delay(1);
- digitalWrite(stepPinM3, LOW);
- delay(1);
- }
- delay(temps3);
- }
- // Moteur 1 & 2
- if (nbreAleatoire == 4){
- for (int x = 0; x < nb_croq4; x++) {
- digitalWrite(stepPinM1, HIGH);
- digitalWrite(stepPinM2, HIGH);
- delay(1);
- digitalWrite(stepPinM1, LOW);
- digitalWrite(stepPinM2, LOW);
- delay(1);
- }
- delay(temps4);
- }
- // Moteur 1 & 3
- if (nbreAleatoire == 5){
- for (int x = 0; x < nb_croq5; x++) {
- digitalWrite(stepPinM1, HIGH);
- digitalWrite(stepPinM3, HIGH);
- delay(1);
- digitalWrite(stepPinM1, LOW);
- digitalWrite(stepPinM3, LOW);
- delay(1);
- }
- delay(temps5);
- }
- // Moteur 2 & 3
- if (nbreAleatoire == 6){
- for (int x = 0; x < nb_croq6; x++) {
- digitalWrite(stepPinM2, HIGH);
- digitalWrite(stepPinM3, HIGH);
- delay(1);
- digitalWrite(stepPinM2, LOW);
- digitalWrite(stepPinM3, LOW);
- delay(1);
- }
- delay(temps6);
- }
- // Moteur 1 & 2 & 3
- if (nbreAleatoire == 7){
- for (int x = 0; x < nb_croq7; x++) {
- digitalWrite(stepPinM1, HIGH);
- digitalWrite(stepPinM2, HIGH);
- digitalWrite(stepPinM3, HIGH);
- delay(1);
- digitalWrite(stepPinM1, LOW);
- digitalWrite(stepPinM2, LOW);
- digitalWrite(stepPinM3, LOW);
- delay(1);
- }
- delay(temps7);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement