Este código del 1er caso
int smDirectionPin = 3; //Direction pin Nano Pin 3 connected to DIR pin of Easy Driver
int smStepPin = 2; //Stepper pin Nano Pin 2 connected to STEP pin of Easy Driver
void setup(){
/*Sets all pin to output; the microcontroller will send them(the pins) bits, it will not expect to receive any bits from thiese pins.*/
pinMode(smDirectionPin, OUTPUT);
pinMode(smStepPin, OUTPUT);
Serial.begin(9600);
}
void loop(){
digitalWrite(smDirectionPin, HIGH); //Writes the direction to the EasyDriver DIR pin. (HIGH is clockwise).
/*Slowly turns the motor 1600 steps*/
for (int i = 0; i < 1600; i++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(700);
digitalWrite(smStepPin, LOW);
delayMicroseconds(700);
}
delay(1000); //Pauses for a second (the motor does not need to pause between switching direction, so you can safely remove this)
digitalWrite(smDirectionPin, LOW); //Writes the direction to the EasyDriver DIR pin. (LOW is counter clockwise).
/*Turns the motor fast 1600 steps*/
for (int i = 0; i < 1600; i++){
digitalWrite(smStepPin, HIGH);
delayMicroseconds(70);
digitalWrite(smStepPin, LOW);
delayMicroseconds(70);
}
delay(1000);
}
debería ser igual a este
/* Arduino Stepper Control with Potentiometer
Created by Yvan / https://Brainy-Bits.com
This code is in the public domain...
You can: copy it, use it, modify it, share it or just plain ignore it!
Thx!
*/
#include
// Library created by Mike McCauley at http://www.airspayce.com/mikem/arduino/AccelStepper/
// AccelStepper Setup
AccelStepper stepper(1, 2, 3); // 1 = Easy Driver interface
// Nano Pin 2 connected to STEP pin of Easy Driver
// Nano Pin 3 connected to DIR pin of Easy Driver
// Variables to store current, previous and move position
int val = 0;
int previous = 0;
int long newval = 0;
void setup() {
stepper.setMaxSpeed(4800); // Set speed fast enough to follow pot rotation
stepper.setAcceleration(4800); // High Acceleration to follow pot rotation
}
void loop() {
val = analogRead(A4); // Read Potentiometer current value
if ((val > previous+6) || (val < previous-6)) { // Check that a move of the pot is at least > or < than 6
newval = map(val, 0, 1023, 0, 1600); // Map value (1600 = 1 stepper shaft rotation)
stepper.runToNewPosition(newval); // Move stepper to new position
previous = val; // save current value into variable previous
}
}
Entonces no hay error salvo que si el segundo funciona y lo comparas con el primero veras que los pines STEP y DIR estan cambiados. Por eso la primer versión la puse como debe ir y no como sugieres que la has usado.