Library for Matrix Orbital VFD2041 display. Also useable for LCD2041 modules.

Files at this revision

API Documentation at this revision

Comitter:
wsalis01
Date:
Mon Mar 05 03:42:10 2012 +0000
Child:
1:770ec826c555
Commit message:

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
mbed.bld Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VFD.cpp	Mon Mar 05 03:42:10 2012 +0000
@@ -0,0 +1,92 @@
+#include "mbed.h"
+#include <string>
+#include "VFD.h"
+
+VFD::VFD() : _i2c(SDA, SCL) {
+    //Nothing to see here
+}
+
+VFD::~VFD() {
+    //Nothing to see here
+}
+
+int VFD::init() {
+    const char cmd[] = {254,160,0};
+    int length = 3;
+    return write(cmd, length);
+}
+
+int VFD::print(char * msg) {
+    int len = msg.size();
+    char * cmd = new char(len);
+    memcpy(cmd, msg.data(), len);
+    return write(cmd, len);
+}
+
+int VFD::autoScrollOn() {
+    const char cmd[] = {254, 81};
+    int length = 2;
+    return write(cmd, length);
+}
+
+int VFD::autoScrollOff() {
+    const char cmd[] = {254, 82};
+    int length = 2;
+    return write(cmd, length);
+}
+
+int VFD::lineWrapOn() {
+    const char cmd[] = {254, 67};
+    int length = 2;
+    return write(cmd, length);
+}
+
+int VFD::lineWrapOff() {
+    const char cmd[] = {254, 68};
+    int length = 2;
+    return write(cmd, length);
+}
+
+int VFD::setCursor(const int col, const int row) {
+    const char cmd[] = {254, 71, col, row};
+    int length = 4;
+    return write(cmd, length);
+}
+
+int VFD::clearScreen() {
+    const char cmd[] = {254, 88};
+    int length = 2;
+    return write(cmd, length);
+}
+
+int VFD::goHome() {
+    const char cmd[] = {254, 72};
+    int length = 2;
+    return write(cmd, length);
+}
+
+int VFD::initLargeNumbers() {
+    const char cmd[] = {254, 110};
+    int length = 2;
+    return write(cmd, length);
+}
+
+int VFD::setBrightness(const int val) {
+    if (val < 0 || val > 3)
+        return -1;
+    const char cmd[] = {254, 89, val};
+    int length = 3;
+    return write(cmd, length);
+}
+
+int VFD::write(const char * data, int length) {
+    int ret = _i2c.write(address, data, length); //Performs a complete write transaction
+    wait_us(625);
+    return ret; //Return I2C.write(...) return value
+}
+
+int VFD::read(char * data, int length) {
+    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
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/VFD.h	Mon Mar 05 03:42:10 2012 +0000
@@ -0,0 +1,40 @@
+/*
+ * File: VfD/VFD.h
+ * Author: William Jessup Salisbury
+ * Company: Tufts Hybrid Racing Team
+ * Copyright: CC BY-NC-SA 3.0
+ * Date: 3/11/2012
+ */
+
+#ifndef VFD_H
+#define VFD_H
+
+#include "mbed.h"
+#include <string>
+
+const PinName SDA = p28;
+const PinName SCL = p27;
+const int address = 0x50;
+
+class VFD {
+public:
+    VFD();
+    ~VFD();
+    int init();
+    int print(const string msg);
+    int autoScrollOn();
+    int autoScrollOff();
+    int lineWrapOn();
+    int lineWrapOff();
+    int setCursor(const int col, const int row);
+    int clearScreen();
+    int goHome();
+    int initLargeNumbers();
+    int setBrightness(const int val);
+private:
+    I2C _i2c;
+    int write(const char * data, int length);
+    int read(char * data, int length);
+};
+
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Mon Mar 05 03:42:10 2012 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/4c0c40fd0593