well, i'll put my code bellow.
the problem that i've been leading is that i can't make my stteper mottor go back to the last position, that's why i set "position = 0".
#include <Stepper.h>
const int stepsPerRevolution = 2048; // change this to fit the number of steps per revolution
char abrir;
int position = 0;
// ULN2003 Motor Driver Pins
#define IN1 13
#define IN2 12
#define IN3 14
#define IN4 27
// initialize the stepper library
Stepper myStepper(stepsPerRevolution, IN1, IN3, IN2, IN4);
void setup() {
// set the speed at 5 rpm
myStepper.setSpeed(5);
// initialize the serial port
Serial.begin(9600);
}
void loop() {
while (Serial.available() > 0) {
abrir = Serial.read();
if (abrir == '1' || abrir == '2') {
break;
}
}
// Se enviado "1" pelo monitor serial a Janela deve abrir //
if (abrir == '1' && position == 0) {
abrir = '0';
Serial.println("Janela aberta");
for(int i = 0; position<=5; i++);
{
myStepper.step(450);
delay(20);
}
}
// Se enviado "2" pelo monitor serial a Janela deve fechar //
while (Serial.available() > 1)
if (abrir == '2' && position == 5) {
abrir = '0';
Serial.println("Janela aberta");
for(int i = 5; position<=0; i++);
{
myStepper.step(450);
delay(20);
}
}
}
how you see, i set the where my motor has to go, and the stepps...but it's not happen.