//SETA43 //http: / / seta43.duckdns.org //http: / / seta43.blogspot.com #define dirPin 2 #define stepPin 3 #define enablePin 13 void setup() { pinMode(enablePin, OUTPUT); pinMode(stepPin, OUTPUT); pinMode(dirPin, OUTPUT); } void loop() { Pasos(200,1,1000); delay(500); Pasos(200,0,1000); delay(500); } void Pasos(int pasos,bool direccion,int timePaso) { digitalWrite(dirPin, direccion); digitalWrite(enablePin, LOW); for(int i = 0; i < pasos; i++) { digitalWrite(stepPin, HIGH); delayMicroseconds(timePaso); digitalWrite(stepPin, LOW); delayMicroseconds(timePaso); } digitalWrite(enablePin, HIGH); } |
//modificado por SETA43 //http: / / seta43.duckdns.org //http: / / seta43.blogspot.com //https://www.luisllamas.es/motor-paso-paso-28byj-48-arduino-driver-uln2003/ //definicion de pins const int motorPin1 = 2; // 28BYJ48 In1 const int motorPin2 = 3; // 28BYJ48 In2 const int motorPin3 = 4; // 28BYJ48 In3 const int motorPin4 = 5; // 28BYJ48 In4 int stepCounter = 0; // contador para los pasos int stepsPerRev = 4076; // pasos para una vuelta completa #define FASE3 #ifdef FASE1 //secuencia 1-fase const int numSteps = 4; const int stepsLookup[4] = { B1000, B0100, B0010, B0001 }; #endif #ifdef FASE2 //secuencia 2-fases const int numSteps = 4; const int stepsLookup[4] = { B1100, B0110, B0011, B1001 }; #endif #ifdef FASE3 //secuencia media fase const int numSteps = 8; const int stepsLookup[8] = { B1000, B1100, B0100, B0110, B0010, B0011, B0001, B1001 }; #endif void setup() { //declarar pines como salida pinMode(motorPin1, OUTPUT); pinMode(motorPin2, OUTPUT); pinMode(motorPin3, OUTPUT); pinMode(motorPin4, OUTPUT); } void loop() { Pasos(1000,1,1000); delay(500); Pasos(1000,0,1000); delay(500); } void Pasos(int pasos,bool direccion,int timePaso) { for(int i = 0; i < pasos; i++) { if(direccion==1) { stepCounter++; if (stepCounter >= numSteps) stepCounter = 0; setOutput(stepCounter); delayMicroseconds(timePaso); } else { stepCounter--; if (stepCounter < 0) stepCounter = numSteps - 1; setOutput(stepCounter); delayMicroseconds(timePaso); } } digitalWrite(motorPin1, 0); digitalWrite(motorPin2, 0); digitalWrite(motorPin3, 0); digitalWrite(motorPin4, 0); } void setOutput(int step) { digitalWrite(motorPin1, bitRead(stepsLookup[step], 0)); digitalWrite(motorPin2, bitRead(stepsLookup[step], 1)); digitalWrite(motorPin3, bitRead(stepsLookup[step], 2)); digitalWrite(motorPin4, bitRead(stepsLookup[step], 3)); } |