Library for Matrix Orbital VFD2041 display. Also useable for LCD2041 modules.
Revision 4:f17ce5ab5d01, committed 2012-04-08
- Comitter:
- wsalis01
- Date:
- Sun Apr 08 20:27:22 2012 +0000
- Parent:
- 3:b96f8fff00e8
- Commit message:
- First Commit.
Changed in this revision
VFD.cpp | Show annotated file Show diff for this revision Revisions of this file |
VFD.h | Show annotated file Show diff for this revision Revisions of this file |
--- a/VFD.cpp Sat Mar 10 22:18:27 2012 +0000 +++ b/VFD.cpp Sun Apr 08 20:27:22 2012 +0000 @@ -2,116 +2,88 @@ #include <string> #include "VFD.h" -/** VFD::VFD() Constructor - * Initizlizes the I2C Bus - */ VFD::VFD() : _i2c(SDA, SCL) { - //Nothing to see here -} - -VFD::VFD(PinName data, PinName clock) : _i2c(data, clock) { - //Nothing to see here + _i2c.frequency(100000); } VFD::~VFD() { //Nothing to see here } -/** VFD2041 initialization function - * @returns I2C write() return value - */ +void VFD::start() { + _i2c.start(); +} + +void VFD::stop() { + _i2c.stop(); +} + +int VFD::send_byte(int byte) { + return _i2c.write(byte); +} + +int VFD::read_byte(int ack) { + return _i2c.read(ack); +} + int VFD::init() { const char cmd[] = {254,160,0}; int length = 3; return write(cmd, length); } -/** Prints a string to the VFD - * @param msg is a string to be printed to the display - * @returns I2c write() return value - */ -int VFD::print(string msg) { +int VFD::print(string msg) { return write(msg.data(), msg.size()); } -/** Turns on display autoscroll - * @returns I2c write() return value - */ int VFD::autoScrollOn() { const char cmd[] = {254, 81}; int length = 2; return write(cmd, length); } -/** Turns off diaplay autoscroll - * @returns I2c write() return value - */ int VFD::autoScrollOff() { const char cmd[] = {254, 82}; int length = 2; return write(cmd, length); } -/** Turns on display linewrap - * @returns I2c write() return value - */ int VFD::lineWrapOn() { const char cmd[] = {254, 67}; int length = 2; return write(cmd, length); } -/** Turns off display linewrap - * @returns I2c write() return value - */ int VFD::lineWrapOff() { const char cmd[] = {254, 68}; int length = 2; return write(cmd, length); } -/** Sets the cursor position on the display - * @param col is the column to set the cursor - * @param row is the row to set the cursor - * @returns I2c write() return value - */ int VFD::setCursor(const int col, const int row) { const char cmd[] = {254, 71, col, row}; int length = 4; return write(cmd, length); } -/** Clears the entire contents of the display - * @returns I2c write() return value - */ int VFD::clearScreen() { const char cmd[] = {254, 88}; int length = 2; return write(cmd, length); } -/** Sets the cursor position to col 0, row 0 ( top left position ) - * @returns I2c write() return value - */ int VFD::goHome() { const char cmd[] = {254, 72}; int length = 2; return write(cmd, length); } -/** Initialize memory for the display of large numbers ( 4 rows high ) - * @returns I2c write() return value - */ int VFD::initLargeNumbers() { const char cmd[] = {254, 110}; int length = 2; return write(cmd, length); } -/** Sets the brightness of the display - * @param val determines the brightness as follows: 0 -> 100%, 1 -> 75%, 2 -> 50%, 3 -> 25%. - * @returns I2c write() return value - */ int VFD::setBrightness(const int val) { if (val < 0 || val > 3) return -1; @@ -120,25 +92,14 @@ return write(cmd, length); } - -/** VFD::write - * @param data is a non-null terminated array of characters to write to the display - * @param length is the number of characters in the data array - * @returns I2C write return value - */ int VFD::write(const char * data, int length) { - int ret = _i2c.write(ADDRESS, data, length); //Performs a complete write transaction + int ret = _i2c.write(address, data, length); //Performs a complete write transaction wait_us(625); return ret; //Return I2C.write(...) return value } -/** VFD::read - * @param data is a pointer to a char array to copy read data into - * @param length is the number of characters to copy into the data array - * @returns I2C read return value - */ int VFD::read(char * data, int length) { - int ret = _i2c.read(ADDRESS, data, length); //Performs a complete write transaction + int ret = _i2c.read(address, data, length); //Performs a complete write transaction wait_us(625); return ret; //Return I2C.write(...) return value } \ No newline at end of file
--- a/VFD.h Sat Mar 10 22:18:27 2012 +0000 +++ b/VFD.h Sun Apr 08 20:27:22 2012 +0000 @@ -14,15 +14,18 @@ const PinName SDA = p28; const PinName SCL = p27; -const int ADDRESS = 0x50; +const int address = 0x50; class VFD { public: VFD(); - VFD(PinName data, PinName clock); ~VFD(); + void start(void); + void stop(void); + int send_byte(int byte); + int read_byte(int ack); int init(); - int print(string msg); + int print(const string msg); int autoScrollOn(); int autoScrollOff(); int lineWrapOn();