arduino 1.02
Uno R3
vfd\lcd display via I2C
i am using the ethernet class distributed with the IDE
here are code snippets, I have removed everything in the loop since it does not pertain to the specific issue
my goal is to be able to change the ip address via a keypad and display (i will store it later)
i would like to display and modify the existing IP (it is ip and assigned in code)
if i do this
IPAddress ip(192,168,10, 177);
lcd.print(ip)
it display correctly on lcd, if i change the 10 to 010, it will print the ip address as 192.168.8.177 instead of 192.168.10.177
i would really like to know if there is a way to the ipaddress that is stored in ip into another format so that i can display it as 192.168.010.177 (note leadng 0) so i can easily change via keypad
(that portion of code works but need 3 digits then decimal three digits the decimal etc. and i dont want to have to type the dots when typing it(also working)
#include <Keypad_I2C.h>
#include <EEPROM.h>
#include <avr/wdt.h>
#include <SPI.h>
#include <Ethernet.h>
#include <Keypad.h>
#include <MagStripe.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x20,6,5,4,0,1,2,3);
int SEvent = 0; // incoming serial byte
int EGMTx = 0;
int TimeOut =20;
byte enable[5] = {0x01,0x0E,0x01,0x45,0xD1};
byte mac[] = {0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };
IPAddress ip(192,168,10,177);
IPAddress gateway(192,168,10, 2);
IPAddress subnet(255, 255, 255, 0);
const byte rows = 3; //four rows
const byte cols = 4; //three columns
char keys[rows][cols] = {
{'1','2','3','C'} ,
{'4','5','6','0'} ,
{'7','8','9','E'}};
byte rowPins[rows] = {0,1,2}; //connect to the row pinouts of the keypad
byte colPins[cols] = {6,5,4,3}; //connect to the column pinouts of the keypad
int i2caddress = 0x21;
Keypad_I2C keypad = Keypad_I2C( makeKeymap(keys), rowPins, colPins, rows, cols, i2caddress );
template<class T>
void MyLCD(byte col, byte row, T t);
// function definition
template<class T>
void MyLCD(byte col, byte row, T t)
{
lcd.setCursor(col,row);
lcd.setCursor(col,row);
lcd.print(t);
}
MagStripe card;
/*
* Track 3 is the one that can contain the most characters (107).
* We add one more to accomodate the final '\0', as the data is a C string...
*/
static const byte DATA_BUFFER_LEN = 108;
static char data[DATA_BUFFER_LEN];
static bool cardinsert = 0;
static bool cardallin = 0;
short myChars = 0;
byte mySrvCmd = 0;
// telnet defaults to port 23
EthernetServer server(8888);
boolean alreadyConnected = false; // whether or not the client was connected previously
long previousMillis = 0;
long interval = 1000;
long lpcount = 0;
byte sendInfo = 0;
int value;
void setup() {
lcd.begin(20, 2);
if ( value = EEPROM.read(0) == 255)
{
lcd.setCursor(0, 0);
//size_t before = getFreeMemory ();
//lcd.print(before);
getipaddress();
delay(1000000);
}
// initialize the ethernet device
Ethernet.begin(mac, ip, gateway, subnet);
// start listening for clients
//server.begin();
// Open serial communications and wait for port to open:
lcd.print("CMS");
lcd.setCursor(10, 0);
lcd.print("No Card ");
lcd.setCursor(5, 1);
lcd.print("Insert Card ");
}
void loop() {
}
void getipaddress()
{
//char IPaddr[16]= {'0','0','0','.','0','0','0','.','0','0','0','.','0','0','0' };
char IPaddr[16]= {ip};
boolean goodIP = false;
byte IPpos = 1 ;
lcd.setCursor(7,0);
lcd.print("Enter IP Address");
lcd.setCursor(1,1);
lcd.print(ip);
//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
wdt_enable (WDTO_1S);
while (true) ;
if (IPpos == 15)
{
lcd.setCursor(4, 0);
lcd.print(IPaddr);
}
else if (IPpos == 3 || IPpos == 7 || IPpos == 11)
{
lcd.setCursor(IPpos+2, 1);
IPpos += 2;
}
else
{
lcd.setCursor(IPpos+1, 1);
IPpos += 1;
}
}
else
{
if (IPpos == 1 || IPpos == 5 || IPpos == 9 || IPpos == 13)
{
if (key > '2')
{
key = '2';
}
lcd.setCursor(IPpos, 1);
IPaddr[IPpos - 1] = key;
lcd.print(key);
IPpos += 1;
}
else if (IPpos == 2 || IPpos == 6 || IPpos == 10 || IPpos == 14)
{
if (IPaddr[IPpos - 2] == '2' && key > '5')
{
key = '5';
}
lcd.setCursor(IPpos, 1);
IPaddr[IPpos - 1] = key;
lcd.print(key);
IPpos += 1;
}
else if (IPpos == 3 || IPpos == 7 || IPpos == 11 || IPpos == 15)//skip over decimal
{
if (IPaddr[IPpos - 3] == '2' && IPaddr[IPpos - 2] == '5' && key > '5')
{
key = '5';
}
else if (IPaddr[IPpos - 3] == '0' && IPaddr[IPpos - 2] == '0' && key == '0' && (IPpos == 3 || IPpos == 15))
{
key = '1';
}
lcd.setCursor(IPpos, 1);
IPaddr[IPpos - 1] = key;
lcd.print(key);
if (IPpos == 15)
{
lcd.setCursor(IPpos , 1);
}
else
{
lcd.setCursor(IPpos+2, 1);
IPpos += 2;
}
}
else
{
//lcd.setCursor(IPpos, 1);
//lcd.print(key);
//IPpos += 1;
}
}
}
}
while (goodIP == false);
}