KEYPAD Problems
KEYPAD Problems
#include <Keypad.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
//LCD
LiquidCrystal_I2C lcd = LiquidCrystal_I2C(0x3F, 16, 2);
//keypad
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] = {
{'1', '2', '3', 'A'},
{'4', '5', '6', 'B'},
{'7', '8', '9', 'C'},
{'*', '0', '#', 'D'}
};
byte rowPins[ROWS] = {32, 30, 28, 26}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {40, 38, 36, 34}; //connect to the column pinouts of the
keypad
void setup() {
lcd.init();
lcd.backlight();
Serial.begin(9600);
}
void loop() {
char key;
startup();
do {
key = keypad.getKey();
} while (key == NO_KEY);
if (key == 'A') {
delay(500);
Manual();
}
if (key == 'B') {
delay(500);
Automatic();
}
}
void startup()
{
char key;
lcd.setCursor(0, 0);
lcd.print ("Manual = A");
lcd.setCursor(0, 1);
lcd.print ("Auto = B");
delay(100);
}
void Manual()
{
//bunch of codes for Manual function of the program calibration and etc
}
void Automatic()
{
void program()
{
void control()
{
lcd.clear();
lcd.print ("# to stop");
char key;
do {
key = keypad.getKey();
} while (key == NO_KEY);
delay(2000);
if (key == '#')
Reset();
if (key == NO_KEY)
program();
}
void Reset()
{
while (percentage != 0)
{
Serial.println (location);
lcd.clear();
stepper.setCurrentPosition(0);
while (stepper.currentPosition() != 259)
{
lcd.setCursor(0, 0);
lcd.print("Closing Valve");
stepper.setSpeed(50);
stepper.runSpeed();
}
location = (location) - 259;
percentage = (float)location / 4144 * 100;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("Percentage:");
lcd.setCursor(0, 1);
lcd.print (percentage);
delay(1000);
RPM();
LoadSensor();
if (percentage == 0)
break;
}
return 0;