Introducing the LiquidCrystal NKC Library!

That a full project with all the bells and whistles :smiley:
I looked at it, and there are a few things that can be improved.

☛ Indents and tabs:
Could you use indents of 2 spaces. There are now tabs in the source code and the indents are all over the place.

☛ Wire.setClock is buggy:
The minimum SCL clock frequency is 50kHz. The real minimum is a little lower, but I keep 50kHz as a minimum. 10kHz does not work.

#define I2C_SLOW  10000

☛ Delay between Wire.write() has no influence on the bus:
This makes no sense:

Wire.beginTransmission(g_i2c_address);
Wire.write(0xFE);
delayMicroseconds(I2CDELAY);
Wire.write(command);
delayMicroseconds(I2CDELAY);
Wire.endTransmission();
delayMicroseconds(I2CDELAY);

All those delays will do nothing for the I2C bus signals. You can remove them.
If the display needs some time after sending a command, then add a delay after the Wire.endTransmission().

☛ Delay between Serial.write() is very tricky:
There is a 64 byte serial buffer. If you put something in that buffer and wait before putting in the next byte in that buffer, then it depends on the baudrate if that has any influence. Since your delay is small, it has no influence.

Serial.write(0xFE);
delayMicroseconds(RS232DELAY);
Serial.write(command);
delayMicroseconds(RS232DELAY);
Serial.write(value);
delayMicroseconds(RS232DELAY);

A serial device rarely requires a extra long stop-bit or a gap between the data bytes. You can remove those delays.

1 Like