I'm writing a library that writes to a VFD (vacuum fluorescent display), and would like to take advantage of Print. I looked at the LiquidCrystal library as an example, except the VFD uses a serial interface. However, the Serial functions, in a library, does not seem to work - no rx or tx leds during usage. After searching, found this read-only topic: Arduino Forum
It suggests: "This code allows you to use any library that inherits the Print object. [ethernet serial softwareserial etc etx]" and proceeds to add a MyLibrary class that inherits the Print object.
I'm not sure this is the way to go for writing a shared library, and after all, none of the LiquidCrystal examples have this. Is there a good solution to creating a library that uses Serial and a member of the Print class? Thanks!
Derive your class from Stream and then implement the virtual functions. I did that here for example:
class DebugOutput : public Stream
{
private:
// blah blah
public:
void begin () { } // whatever
virtual int available (void);
virtual int peek (void);
virtual int read (void);
virtual void flush (void);
virtual size_t write (byte c);
using Print::write; // pull in write(str) and write(buf, size) from Print
}; // end of DebugOutput