Hello. I am stumped as to what I am doing wrong here. The purpose of this project is to roll a window shade up and down. I plan to use a separate ESP-01 running Tasmota to trigger this high/low switching by MQTT when I get it working. It will eventually be tied into my home automation system.
The goal is to have this project sit idle until a button is switched high or low, HIGH will set a stepper to go CW 20480 steps (10 revolutions) and the LOW will make the stepper go DOWN 20480 steps.
(I have the code set to 2048 for testing)
I thought that this would be simple, and I have read about 20 pages on various examples and library code, just not sure what I am doing wrong and would LOVE some fresh eyes on the code. I'm Stumped.
Currently when I run the code, it sits idle like I want
when I take pin buttonPin1 HIGH, it rotates a small amount and then stops. Not cool
when I take pin buttonPin2 High, Nothing happens, Less cool
I am sure this is something really simple, but I am lost for ideas at this point. Help?
Also, in advance, I know the accelstepper library is supposed to be better, but I don't need acceleration or micro stepping and such. Unless using it fixes my problem, I am just as happy with stepper.h.
couple more things to note, although I am not sure this is relevant is that I am uploading this to a DIGISTUMP(ATtiny) , and the stepper is a 28BYJ-48 with the appropriate driver board and correct wiring. Also, I know that my code is currently written for two buttons, but it was just me testing different options. I would prefer a single input, High/Low functionality.
#include <Stepper.h>
#define STEPS_PER_MOTOR_REVOLUTION 32
#define rollUp 2048
#define rollDown -2048
Stepper small_stepper(STEPS_PER_MOTOR_REVOLUTION, 0, 2, 1, 3);
const int buttonPin1 = 4;
const int buttonPin2 = 5;
int button1State = 0;
int button2State = 0;
void setup()
{
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop()
{
button1State = digitalRead(buttonPin1);
button2State = digitalRead(buttonPin2);
while (button1State == HIGH) {
small_stepper.setSpeed(800);
small_stepper.step(rollUp);
break;
while (button2State == HIGH) {
small_stepper.setSpeed(800);
small_stepper.step(rollDown);
break;
}
}
}
Window_shade.ino (679 Bytes)