I have a stepper and a Wemos D1. However, there is something wrong with the Wemos as I can not use libaries with the stepper. I found a code that work. However, it is for full step but I want to use half step, and my programming skills are not sufficient to understand the code. Is there some one how understands what needs to be changed to transfere the code to half step?
// ESP-12F(WeMos D1 mini)
#define IN1 14 //GPIO 14
#define IN2 12 //GPIO 12
#define IN3 13 //GPIO 13
#define IN4 15 //GPIO 15
const int NBSTEPS = 4095;
const int STEPTIME = 900;
int Step = 0;
boolean Clockwise = true;
int arrayDefault[4] = {LOW, LOW, LOW, LOW};
int stepsMatrix[8][4] = {
{LOW, LOW, LOW, HIGH},
{LOW, LOW, HIGH, HIGH},
{LOW, LOW, HIGH, LOW},
{LOW, HIGH, HIGH, LOW},
{LOW, HIGH, LOW, LOW},
{HIGH, HIGH, LOW, LOW},
{HIGH, LOW, LOW, LOW},
{HIGH, LOW, LOW, HIGH},
};
unsigned long lastTime = 0L;
unsigned long time = 0L;
void writeStep(int outArray[4]);
void stepper();
void setDirection();
void setup() {
//Arduino UNO
//Serial.begin(9600);
//ESP8266
Serial.begin(115200);
Serial.println("Starting...");
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
}
void loop() {
unsigned long currentMicros;
int stepsLeft = NBSTEPS;
time = 0;
lastTime = micros();
while (stepsLeft > 0) {
currentMicros = micros();
if (currentMicros - lastTime >= STEPTIME) {
stepper();
time += micros() - lastTime;
lastTime = micros();
stepsLeft--;
}
delay(1);
}
Serial.println(time);
Serial.println("Wait...!");
delay(400);
//Clockwise = !Clockwise;
stepsLeft = NBSTEPS;
}
void writeStep(int outArray[4]) {
digitalWrite(IN1, outArray[0]);
digitalWrite(IN2, outArray[1]);
digitalWrite(IN3, outArray[2]);
digitalWrite(IN4, outArray[3]);
}
void stepper() {
if ((Step >= 0) && (Step < 8)) {
writeStep(stepsMatrix[Step]);
} else {
writeStep(arrayDefault);
}
setDirection();
}
void setDirection() {
(Clockwise == true) ? (Step++) : (Step--);
if (Step > 7) {
Step = 0;
} else if (Step < 0) {
Step = 7;
}
}