In the function I want the program to wait for 4 key inputs from the keypad and display them to the LCD and when the user presses the # key it clears the LCD and displays a message. Using a while statement and then an if statement brings up two lines per block on a 16x2 LCD.
#include <LiquidCrystal.h>
#include <Keypad.h>
#include <Stepper.h>
#define STEPS 200
#define ledRed 8
#define ledGreen 9
#define input1 52
#define input2 53
const int numRows = 2;
const int numCols = 16;
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = { 40, 50, 48, 44 };
byte colPins[COLS] = { 42, 38, 46 };
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
LiquidCrystal lcd( 12, 11, 5, 4, 3, 2 );
Stepper stepper(STEPS, 36, 34, 32, 30);
Stepper stepper2(STEPS, 28, 26, 24, 22);
int bays = 10;
int steps = 0;
void setup()
{
pinMode(input1, INPUT);
pinMode(input2, INPUT);
pinMode(ledRed, OUTPUT);
pinMode(ledGreen, OUTPUT);
lcd.begin(numCols, numRows);
lcd.print("Welcome");
lcd.setCursor(0, 1);
stepper.setSpeed(30);
}
void loop()
{
lcdin();
}
int opengate(int i)
{
int val = digitalRead(input1);
if (val == LOW)
{
steps = 50;
stepper.step(steps);
delay(10000);
steps = -50;
stepper.step(steps);
delay(1000);
}
i = i - 1;
return i;
}
int closegate(int i)
{
int val = digitalRead(input2);
if (val == LOW)
{
steps = 50;
stepper2.step(steps);
delay(10000);
steps = -50;
stepper2.step(steps);
delay(1000);
}
i = i + 1;
return i;
}
int ledlight(int i)
{
if (i >= 1)
{
digitalWrite(ledGreen, HIGH);
lcd.clear();
lcd.print("Input passcode:");
lcd.setCursor(0, 1);
}
else
{
digitalWrite(ledRed, HIGH);
lcd.clear();
lcd.print("No spots left");
lcd.setCursor(0, 1);
}
}
int lcdin()
{
char key = kpd.getKey();
while(key != '#')
{
lcd.print(key);
}
if (key == '#')
{
lcd.clear();
lcd.print("Input passcode:");
lcd.setCursor(0, 1);
}
}
int lcdout()
{
char key = kpd.getKey();
if (key)
{
switch(key)
{
case '#':
lcd.clear();
lcd.print("Thx for coming");
delay(5000);
lcd.clear();
lcd.print("Input passcode:");
lcd.setCursor(0, 1);
break;
default:
lcd.print(key);
}
}
}