hi guys i have this programme that allows me to push a button to start a mouvement and stoppage of a stepper motor for a certain amount of times example: motor move for: 20 seconds then stop for 10 seconds then move for 4 seconds then stop for 30 seconds etc... "move" is doing few steps cw and ccw
now i want to add an lcd so that when i press the bouton it show that he is in state of movement and countdown for time and when in stoppage show stoppage and cowntdown... im very bad at coding and i don't know how to do it i only find "hello world" examples in the internet here is my code :
#include <elapsedMillis.h>
#include <StepperDriver.h>
int motor_steps = 200; //
int step_divisition = 1;
int en_pin = 6;
int cw_pin = 4;
int clk_pin = 5;
unsigned int period =3000;
unsigned int period2 = 4000;
unsigned int period3 =2000;
unsigned int period4 =2000;
const int buttonPin = 8;
//int buttonState = 0;
int buttonPushCounter = 0; // counter for the number of button presses
int buttonState = LOW; // current state of the button
int lastButtonState = 0; // previous state of the button
//long tempsmouv =
//long tempsarret =
StepperDriver ss(motor_steps, step_divisition, en_pin, cw_pin, clk_pin);
void mouvement(){
ss.setSpeed(150);
ss.step(300);
delay(400);
ss.step(-300);
delay(400);
}
void arret(){
ss.setSpeed(0);
}
void setup() {
// put your setup code here, to run once:
pinMode(buttonPin, INPUT);
Serial.begin(9600);
/*while( digitalRead(buttonPin) == HIGH );
delay( 20 ); // because I am NOT going to explain debounce here
while( digitalRead( buttonPin ) == LOW ); // release to end this loop
Serial.println("bouton is pushed");*/
}
void loop() {
buttonState = digitalRead(buttonPin);
// compare the buttonState to its previous state
if (buttonState != lastButtonState) {
// if the state has changed, increment the counter
if (buttonState == HIGH) {
buttonPushCounter++;
elapsedMillis timeElapsed;
while(timeElapsed < period) {
Serial.println("test1");
mouvement();
}
elapsedMillis timeElapsed2;
while(timeElapsed2 < period2 ) {
Serial.println("test2");
arret();
}
elapsedMillis timeElapsed3;
while(timeElapsed3 < period3 ) {
Serial.println("test1");
mouvement();
}
elapsedMillis timeElapsed4;
while(timeElapsed4 < period4 ) {
Serial.println("test2");
arret();
}
}
while(1);
}
}