I was working with the Software Serial Lib to create a new library for a Serial LCD display. I was having a problem with getting an x-y positioning routine to work right reliably. To make a long story short, if you call print(x) and the value of x is zero (0) nothing prints.
The workhorse routine printNumber() is shown below. The call to printByte('0') is the problem. It should be print('0') . I believe printByte() is a HW Serial routine. I suspect the '0' was being sent back up the serial line to the Arduino IDE which blissfully ignored it. When I changed the code from printByte('0') to print('0') it would now print the '0' when invoked as print(x) where 'x' has a value of zero.
Further proof of the pudding is the recompiled demo sketch is 1200-1300 bytes smaller! I suspect that number corresponds to the HWSerial object size that is no longer being loaded.
I have written three libraries and corrected a fourth (the Software serial). My reason for creating the first was as a basis for the LCD module. But there are any number of modules one might interface to an Arduino which have one way serial communictions and it seemed logical to create libraries for each direction so you don't waste a precious second pin.
1 - SWSerialXmit - a transmitt serial only library (simple surgery on the original SoftwareSerial)
2 - SWSerialRcv - a receive serial only library (same)
3 - SWSerialLCDPHA - a transmit only software serial library specifically for an LCD display
running under a Peter Anderson controller chip.
4 - SoftwareSerial - the Arduino 08 delivered library corrected as mentioned above.
These four libs can be found in a zipfile on my website http://www.wulfden.org/Arduino/ArduinoSWSerLibs.zip.
The short demo sketch I wrote to show off the new lib with a 4x20 display on one of my K107 serial LCD controller boards (http://www.wulfden.org/k107/) with an Anderson chip is available at http://www.wulfden.org/Arduino/LCDPHA_Demo.zip.
cheers ... BBR
// Private Methods /////////////////////////////////////////////////////////////
void SoftwareSerial::printNumber(unsigned long n, uint8_t base)
{
unsigned char buf[8 * sizeof(long)]; // Assumes 8-bit chars.
unsigned long i = 0;
if (n == 0) {
printByte('0');
return;
}
while (n > 0) {
buf[i++] = n % base;
n /= base;
}