I've been trying, for over a week now, to create a program that will store my keypad presses into variable, and with a press of an enter, it will switch to the next variable to store the presses. The program is made to load addresses (mainly IP addresses) to different devices over serial connections. Because there are different types of addresses, each time the user press enter in the keypad (made the # button to a '\r' char) the program needs to switch to the next type of address and get the key presses from the keypad and store them until the next '\r' press. My problem is that I don't know how to store those addresses in the Arduino, and switch to a different "char" (I used char because I didn't knew how to convert them to store key presses into string) every '\r' press. I've included the handler for this part of my code. This is my first post here so if anything is missing let me know. thanks ahead.
bool handlerManualEntry( void )
{
static uint8_t stateManualEntry = statesFunc::ST_INIT;
char keyval = ReadKey();
switch( stateManualEntry )
{
case statesFunc::ST_INIT:
//do whatever inits you need here (screen, variables etc)
stateManualEntry = statesFunc::ST_RUN;
break;
case statesFunc::ST_RUN:
//is there a keypress?
if( keyval != NO_KEY )
{
switch( keyval )
{
case '\r':
//when we get a return, send it to the serial port
Serial.print( '\n' );
u8g2log.print('\f');
for(int i=0; i<6; i++)
{
if(i == 0)
{
Serial.print(ethernetIP);
}
else if(i == 1)
{
Serial.print(ethernetSubnet);
}
else if(i == 2)
{
Serial.print(ethernetGetway);
}
else if(i == 3)
{
Serial.print(vmeIP);
}
else if(i == 4)
{
Serial.print(vmeSubnet);
}
else if(i == 5)
{
Serial.print(eventPort);
}
else if(i == 6)
{
Serial.print(timeOut);
}
}
//and finish out by returning the state to INIT and returning true
//stateManualEntry = statesFunc::ST_INIT;
//return true;
break;
case 'D':
u8g2log.print('N');
Serial.print('N');
break;
case 'C':
u8g2log.print('Y');
Serial.print('Y');
break;
default:
//for any other key, print to the serial port and LCD
u8g2log.print(keyval);
enterAddresses();
break;
}
}
break;
}
return false;
}
void enterAddresses()
{
int x;
if(keyval != '\r')
{
if(pointer == 1)
{
keyval = keypad.getKey();
u8g2log.print(keyval);
ethernetIP += keyval;
}
else if(pointer == 2)
{
keyval = keypad.getKey();
u8g2log.print(keyval);
ethernetSubnet += keyval;
}
}
else if(pointer == 3)
{
keyval = keypad.getKey();
u8g2log.print(keyval);
ethernetGetway += keyval;
}
else if(pointer == 4)
{
keyval = keypad.getKey();
u8g2log.print(keyval);
vmeIP += keyval;
}
else if(pointer == 5)
{
keyval = keypad.getKey();
u8g2log.print(keyval);
vmeSubnet += keyval;
}
else if(pointer == 6)
{
keyval = keypad.getKey();
u8g2log.print(keyval);
eventPort += keyval;
}
else if(pointer == 7)
{
keyval = keypad.getKey();
u8g2log.print(keyval);
timeOut += keyval;
}
pointer++;
u8g2log.print('\f');
}
char keys[ROWS][COLS] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'.','0','\r','D'}
};
byte rowPins[ROWS]={39,41,43,45};
byte colPins[COLS]={31,33,35,37};
//Create an object of keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char keyval;
for(int i=0; i<6; i++)
to run sevenSerial.print()
commands in sequence?