Library for Matrix Orbital VFD2041 display. Also useable for LCD2041 modules.
VFD.cpp@4:f17ce5ab5d01, 2012-04-08 (annotated)
- Committer:
- wsalis01
- Date:
- Sun Apr 08 20:27:22 2012 +0000
- Revision:
- 4:f17ce5ab5d01
- Parent:
- 3:b96f8fff00e8
First Commit.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
wsalis01 | 0:f0e9065504cd | 1 | #include "mbed.h" |
wsalis01 | 0:f0e9065504cd | 2 | #include <string> |
wsalis01 | 0:f0e9065504cd | 3 | #include "VFD.h" |
wsalis01 | 0:f0e9065504cd | 4 | |
wsalis01 | 0:f0e9065504cd | 5 | VFD::VFD() : _i2c(SDA, SCL) { |
wsalis01 | 4:f17ce5ab5d01 | 6 | _i2c.frequency(100000); |
wsalis01 | 3:b96f8fff00e8 | 7 | } |
wsalis01 | 3:b96f8fff00e8 | 8 | |
wsalis01 | 0:f0e9065504cd | 9 | VFD::~VFD() { |
wsalis01 | 0:f0e9065504cd | 10 | //Nothing to see here |
wsalis01 | 0:f0e9065504cd | 11 | } |
wsalis01 | 0:f0e9065504cd | 12 | |
wsalis01 | 4:f17ce5ab5d01 | 13 | void VFD::start() { |
wsalis01 | 4:f17ce5ab5d01 | 14 | _i2c.start(); |
wsalis01 | 4:f17ce5ab5d01 | 15 | } |
wsalis01 | 4:f17ce5ab5d01 | 16 | |
wsalis01 | 4:f17ce5ab5d01 | 17 | void VFD::stop() { |
wsalis01 | 4:f17ce5ab5d01 | 18 | _i2c.stop(); |
wsalis01 | 4:f17ce5ab5d01 | 19 | } |
wsalis01 | 4:f17ce5ab5d01 | 20 | |
wsalis01 | 4:f17ce5ab5d01 | 21 | int VFD::send_byte(int byte) { |
wsalis01 | 4:f17ce5ab5d01 | 22 | return _i2c.write(byte); |
wsalis01 | 4:f17ce5ab5d01 | 23 | } |
wsalis01 | 4:f17ce5ab5d01 | 24 | |
wsalis01 | 4:f17ce5ab5d01 | 25 | int VFD::read_byte(int ack) { |
wsalis01 | 4:f17ce5ab5d01 | 26 | return _i2c.read(ack); |
wsalis01 | 4:f17ce5ab5d01 | 27 | } |
wsalis01 | 4:f17ce5ab5d01 | 28 | |
wsalis01 | 0:f0e9065504cd | 29 | int VFD::init() { |
wsalis01 | 0:f0e9065504cd | 30 | const char cmd[] = {254,160,0}; |
wsalis01 | 0:f0e9065504cd | 31 | int length = 3; |
wsalis01 | 0:f0e9065504cd | 32 | return write(cmd, length); |
wsalis01 | 0:f0e9065504cd | 33 | } |
wsalis01 | 0:f0e9065504cd | 34 | |
wsalis01 | 4:f17ce5ab5d01 | 35 | int VFD::print(string msg) { |
wsalis01 | 2:b170a67a8dae | 36 | return write(msg.data(), msg.size()); |
wsalis01 | 0:f0e9065504cd | 37 | } |
wsalis01 | 0:f0e9065504cd | 38 | |
wsalis01 | 0:f0e9065504cd | 39 | int VFD::autoScrollOn() { |
wsalis01 | 0:f0e9065504cd | 40 | const char cmd[] = {254, 81}; |
wsalis01 | 0:f0e9065504cd | 41 | int length = 2; |
wsalis01 | 0:f0e9065504cd | 42 | return write(cmd, length); |
wsalis01 | 0:f0e9065504cd | 43 | } |
wsalis01 | 0:f0e9065504cd | 44 | |
wsalis01 | 0:f0e9065504cd | 45 | int VFD::autoScrollOff() { |
wsalis01 | 0:f0e9065504cd | 46 | const char cmd[] = {254, 82}; |
wsalis01 | 0:f0e9065504cd | 47 | int length = 2; |
wsalis01 | 0:f0e9065504cd | 48 | return write(cmd, length); |
wsalis01 | 0:f0e9065504cd | 49 | } |
wsalis01 | 0:f0e9065504cd | 50 | |
wsalis01 | 0:f0e9065504cd | 51 | int VFD::lineWrapOn() { |
wsalis01 | 0:f0e9065504cd | 52 | const char cmd[] = {254, 67}; |
wsalis01 | 0:f0e9065504cd | 53 | int length = 2; |
wsalis01 | 0:f0e9065504cd | 54 | return write(cmd, length); |
wsalis01 | 0:f0e9065504cd | 55 | } |
wsalis01 | 0:f0e9065504cd | 56 | |
wsalis01 | 0:f0e9065504cd | 57 | int VFD::lineWrapOff() { |
wsalis01 | 0:f0e9065504cd | 58 | const char cmd[] = {254, 68}; |
wsalis01 | 0:f0e9065504cd | 59 | int length = 2; |
wsalis01 | 0:f0e9065504cd | 60 | return write(cmd, length); |
wsalis01 | 0:f0e9065504cd | 61 | } |
wsalis01 | 0:f0e9065504cd | 62 | |
wsalis01 | 0:f0e9065504cd | 63 | int VFD::setCursor(const int col, const int row) { |
wsalis01 | 0:f0e9065504cd | 64 | const char cmd[] = {254, 71, col, row}; |
wsalis01 | 0:f0e9065504cd | 65 | int length = 4; |
wsalis01 | 0:f0e9065504cd | 66 | return write(cmd, length); |
wsalis01 | 0:f0e9065504cd | 67 | } |
wsalis01 | 0:f0e9065504cd | 68 | |
wsalis01 | 0:f0e9065504cd | 69 | int VFD::clearScreen() { |
wsalis01 | 0:f0e9065504cd | 70 | const char cmd[] = {254, 88}; |
wsalis01 | 0:f0e9065504cd | 71 | int length = 2; |
wsalis01 | 0:f0e9065504cd | 72 | return write(cmd, length); |
wsalis01 | 0:f0e9065504cd | 73 | } |
wsalis01 | 0:f0e9065504cd | 74 | |
wsalis01 | 0:f0e9065504cd | 75 | int VFD::goHome() { |
wsalis01 | 0:f0e9065504cd | 76 | const char cmd[] = {254, 72}; |
wsalis01 | 0:f0e9065504cd | 77 | int length = 2; |
wsalis01 | 0:f0e9065504cd | 78 | return write(cmd, length); |
wsalis01 | 0:f0e9065504cd | 79 | } |
wsalis01 | 0:f0e9065504cd | 80 | |
wsalis01 | 0:f0e9065504cd | 81 | int VFD::initLargeNumbers() { |
wsalis01 | 0:f0e9065504cd | 82 | const char cmd[] = {254, 110}; |
wsalis01 | 0:f0e9065504cd | 83 | int length = 2; |
wsalis01 | 0:f0e9065504cd | 84 | return write(cmd, length); |
wsalis01 | 0:f0e9065504cd | 85 | } |
wsalis01 | 0:f0e9065504cd | 86 | |
wsalis01 | 0:f0e9065504cd | 87 | int VFD::setBrightness(const int val) { |
wsalis01 | 0:f0e9065504cd | 88 | if (val < 0 || val > 3) |
wsalis01 | 0:f0e9065504cd | 89 | return -1; |
wsalis01 | 0:f0e9065504cd | 90 | const char cmd[] = {254, 89, val}; |
wsalis01 | 0:f0e9065504cd | 91 | int length = 3; |
wsalis01 | 0:f0e9065504cd | 92 | return write(cmd, length); |
wsalis01 | 0:f0e9065504cd | 93 | } |
wsalis01 | 0:f0e9065504cd | 94 | |
wsalis01 | 0:f0e9065504cd | 95 | int VFD::write(const char * data, int length) { |
wsalis01 | 4:f17ce5ab5d01 | 96 | int ret = _i2c.write(address, data, length); //Performs a complete write transaction |
wsalis01 | 0:f0e9065504cd | 97 | wait_us(625); |
wsalis01 | 0:f0e9065504cd | 98 | return ret; //Return I2C.write(...) return value |
wsalis01 | 0:f0e9065504cd | 99 | } |
wsalis01 | 0:f0e9065504cd | 100 | |
wsalis01 | 0:f0e9065504cd | 101 | int VFD::read(char * data, int length) { |
wsalis01 | 4:f17ce5ab5d01 | 102 | int ret = _i2c.read(address, data, length); //Performs a complete write transaction |
wsalis01 | 0:f0e9065504cd | 103 | wait_us(625); |
wsalis01 | 0:f0e9065504cd | 104 | return ret; //Return I2C.write(...) return value |
wsalis01 | 0:f0e9065504cd | 105 | } |