hola necesito ayuda cuento con la adafruit motor shield v1 conectada a un arduino mega y no puedo dar delay a los motores intente con la funcion millis pero tampoco este es mi codigo:
#include <AFMotor.h>
int final1 = 24;
int final2 = 25;
int final3 = 26;
int final4 = 27;
int valor = 0;
AF_Stepper motor(250, 1);
AF_Stepper motor2(250, 2);
unsigned long previousMillis = 0;
const long interval = 5000;
int movmotor = 0;
void setup()
{
pinMode(final1, INPUT);
pinMode(final2, INPUT);
pinMode(final3, INPUT);
pinMode(final4, INPUT);
Serial.begin(9600);
Serial.println("Stepper test!");
motor.setSpeed(100); // 50 rpm
motor2.setSpeed(250);
motor.release();
motor2.release();
}
void loop()
{
// final1 = digitalRead(24);
final2 = digitalRead(25);
//final3 = digitalRead(26);
final4 = digitalRead(27);
if(final2==HIGH){
valor = 1;
Serial.println("1 y 2 accionados");
}
if(final4==HIGH){
valor = 2;
Serial.println("3 y 4 accionados");
}
if( valor == 0 ){
motor.step(1,BACKWARD, MICROSTEP);
Serial.println("Subiendo");
}
if( valor == 1 ){
motor.step(1,BACKWARD, MICROSTEP);
Serial.println("Subiendo");
}
unsigned long currentMillis = millis();
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if( valor == 2){
movmotor = 0;
} else {
movmotor = 1;
}
// set the LED with the ledState of the variable:
motor.step(movmotor,FORWARD, MICROSTEP);
}
}