IDE 1.02, UNO R3, also have LCD and a 12 key keypad0-9 and 'E' and "C'
I am writing a routine to allow a user to enter an IP address on the UNO if there is not one already entered. I have only included the code for this section
just curious if anyone sees a way to make more compact , not written in yet is the capturing of the ip and storeing it to eeprom. i would like suggestions on the most feasable way to do and also a suggestion on a way to validate whether it is a valid ip address. I have thought about validateing as it is entered for example
ABC.ABC.ABC.ABC , when A is intered only allow 0 1 or 2 to be entered and if user press three force it back to a 2. then when B is entered , allow 0-9 if A is 0 or 1 but only allow 0-5 if A = 2.
the other way is to allow anything to be typed and then when 'E' on keypad is pressed do sometype of check. what are your thoughts.
here is code so far
void getipaddress()
{
boolean goodIP = false;
byte IPpos = 1 ;
lcd.setCursor(7,0);
lcd.print("Enter IP Address");
lcd.setCursor(1,1);
lcd.print("000.000.000.000");
lcd.setCursor(1,1);
lcd.blink();
do
{
char key = keypad.getKey();
if (key != NO_KEY){
if (key == 'C')//backup
{
if (IPpos == 5 || IPpos == 9 || IPpos == 13)//skip over decimal
{
IPpos -= 2;
lcd.setCursor(IPpos, 1);
}
else if (IPpos == 1) //dont pass to left of first digit of ip
{
}
else
{
IPpos -= 1;
lcd.setCursor(IPpos, 1);
}
}
else if(key == 'E')
{
//code to validate and save to eeprom
}
else
{
if (IPpos == 3 || IPpos == 7 || IPpos == 11)//skip over decimal
{
lcd.setCursor(IPpos, 1);
lcd.print(key);
lcd.setCursor(IPpos+2, 1);
IPpos += 2;
}
else if (IPpos == 15) //dont move past last digit of ip
{
lcd.setCursor(IPpos, 1);
lcd.print(key);
lcd.setCursor(IPpos , 1);
}
else
{
lcd.setCursor(IPpos, 1);
lcd.print(key);
IPpos += 1;
}
}
}
}
while (goodIP == false);
//delay(100000000);
}