My program is for a cut to length application. Up and button key set the length on LCD and once the set button pressed the stepper starts to rotate the number of steps set on the LCD.
My problem is that the tow buttons (up button ad down buttons) does not work. Up button work only one press and down button too. I need to set the desired length on the LCD by continuously pressing up button or down button.
Below is my code.
Further, can any on suggest me a way to work with a keyboard instead of up and down buttons.
#include <Stepper.h>
#include<LiquidCrystal.h>
int PUL = 13; int DIR = 12; int reSet = 8; int upButton = 11; int downButton = 10; int setButton = 9;
const int rs = 7, en = 6, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
Stepper myStepper(200,12,13);
int len = 2000;
int steps;
int rev;
int prev;
void setup() {
// put your setup code here, to run once:
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("Enter the Length");
myStepper.setSpeed(60);
}
void loop() {
{ if (digitalRead(upButton) == LOW);
delay(50);
while (digitalRead(upButton) == LOW);
delay(50);
{len++;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Length: ");
lcd.setCursor(0, 1);
lcd.print(len);
}
if (digitalRead(downButton) == HIGH)
delay(50);
while (digitalRead(downButton) == HIGH);
delay(50);
{len--;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Length:");
lcd.setCursor(0, 1);
lcd.print(len);
}
if (digitalRead(setButton) == LOW); {
delay(50);
while (digitalRead(setButton) == LOW);
delay(50);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Length Set :");
rev=len/2;
steps=(rev-prev)*steps;
myStepper.step(steps);
delay(1000);
lcd.clear();
lcd.print("Ready to Cut");
prev=rev;
}
}}