I have a new question. I added an ELSE IF that let me find ‘#’ key pushes and that worked. I got it to go to a different function. Once there, I look for ‘1’ or ‘2’ but it doesn’t see it. I tried asking the program to look for key2 but that didn’t work.
How can I branch and look for another input.
This is the code that I have so far. When I enter 4 integers and then hit ‘C’ or ‘D’, I get i.e. 1234>. If I enter 5 or more characters I get an error but when hit ‘C’ or ‘D’, I get what I want. When I hit ‘#’, I ask:
Automatic Manual
1 or 2
but when a ‘1’ or ‘2’ is pushed, Serial.print finds no record of it.
#include <Keypad.h>
#include <Wire.h>
#include <Adafruit_MCP23017.h>
#include <Adafruit_RGBLCDShield.h>
Adafruit_RGBLCDShield lcd = Adafruit_RGBLCDShield();
int in;
int DIR;
int Value;
int autoInputFork;
int inputDigitCount = 0;
bool direction;
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] = {45, 43, 41, 39}; //connect to the row pinouts of the keypad 37, 35, 33, 31
byte colPins[COLS] = {37, 35, 33, 31}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(9,0);
lcd.print(" ");
lcd.setCursor(9,1);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("Pick < or > Bk*");
lcd.setCursor(14,0);
lcd.setCursor(0,1);
lcd.print("Manual Mode");
lcd.setCursor(12,1);
}
void loop()
{
//>>>> oldLocation = stepsToNextStation;
int in;
int DIR;
int newDir;
int oldLocation;
int oldDirection;
char ch;
newDir = DIR;
getNumber();
}
void getNumber()
{
char key1 = keypad.getKey();
if (key1)
{
in = key1;
if ( in >='0' && in <='9' )
{
if(inputDigitCount >= 4 )
{
tooManyDigits();
}
else
{
inputDigitCount = inputDigitCount + 1;
Serial.println(inputDigitCount);
lcd.print(key1);
Value = Value * 10 + (in - '0');
}
}
else if ( in == 'A' )
{
//>> raiseTheBoom();
}
else if ( in == 'B' )
{
//>> lowerTheBoom();
}
else if ( in == 'C' )
{
DIR = 1;
goLeft();
}
else if ( in == 'D' )
{
// direction = true;
DIR = -1;
goRight();
}
else if ( in == '*' )
{
manualReEntryPoint();
}
else if ( in == '#' )
{
manualEntryPoint(); // <<<<<<<<<<<<<<<<<<<<<<<<
}
}
}
void manualEntryPoint() // <<<<<<<<<<<<<<<<<<<<<<<<<
{
Value = 0;
inputDigitCount = 0;
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("Automatic Manual");
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" 1 or 2 ");
inputDigitCount = 0;
Value = 0;
char key2 = keypad.getKey();
if (key2)
{
lcd.setCursor(0,0);
lcd.print(key2);
autoInputFork = key2;
Value = Value * 10 + (autoInputFork - '0');
if(autoInputFork == '1' )
{
//do something
}
else if(autoInputFork == '2')
{
Serial.print("Get Number");
lcd.setCursor(9,0);
lcd.print(" ");
lcd.setCursor(9,1);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("Pick < or > Bk*");
lcd.setCursor(14,0);
lcd.setCursor(0,1);
lcd.print("Manual Mode");
lcd.setCursor(12,1);
}
}
}
void manualReEntryPoint()
{
Serial.print("manualReEntryPoint");
lcd.setCursor(12,1);
lcd.print(" ");
inputDigitCount = 0;
Value = 0;
lcd.setCursor(12,1);
}
void tooManyDigits()
{
Serial.println("Only 4 digits are allowed ");
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print(" ");
lcd.setCursor(0,1);
lcd.print("Manual Mode");
lcd.setCursor(0,0);
lcd.print("Only 4 digits ");
delay(1000);
lcd.setCursor(0,0);
lcd.print(" ");
lcd.setCursor(0,0);
lcd.print("Pick < or > Bk*");
}
void moveToNextStation(int stepsToNextStation, int DIR)
{
//This will be removed when incorporated into bigger program.
}
void goLeft()
{
Serial.print(Value);
Serial.println( (direction ? "<": ">"));
lcd.setCursor(12,1);
lcd.print(" ");
inputDigitCount = 0;
Value = 0;
lcd.setCursor(12,1);
//>> moveToNextStation(stepsToNextStation, DIR);
}
void goRight()
{
Serial.print(Value);
Serial.println( (direction ? "<": ">"));
lcd.setCursor(12,1);
lcd.print(" ");
inputDigitCount = 0;
Value = 0;
lcd.setCursor(12,1);
//>> moveToNextStation(stepsToNextStation, DIR);
}