Mike Fiore / Mbed 2 deprecated 4-Digit-Display-Scroller

Dependencies:   DigitDisplay mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers DisplayManager.cpp Source File

DisplayManager.cpp

00001 #include "mbed.h"
00002 #include "DisplayManager.h"
00003 
00004 DisplayManager::DisplayManager(PinName clk, PinName dio) : display(NULL) {
00005     display = new DigitDisplay(clk, dio);
00006 }
00007 
00008 DisplayManager::~DisplayManager() {
00009     if (display) delete display;
00010 }
00011 
00012 uint8_t DisplayManager::convert(uint8_t value) {
00013     switch (value) {
00014         case '0':
00015             return 0x3f;
00016         case '1':
00017             return 0x06;
00018         case '2':
00019             return 0x5b;
00020         case '3':
00021             return 0x4f;
00022         case '4':
00023             return 0x66;
00024         case '5':
00025             return 0x6d;
00026         case '6':
00027             return 0x7d;
00028         case '7':
00029             return 0x07;
00030         case '8':
00031             return 0x7f;
00032         case '9':
00033             return 0x6f;
00034         case 'a':
00035         case 'A':
00036             return 0x77;
00037         case 'b':
00038         case 'B':
00039             return 0x7c;
00040         case 'c':
00041         case 'C':
00042             return 0x39;
00043         case 'd':
00044         case 'D':
00045             return 0x5e;
00046         case 'e':
00047         case 'E':
00048             return 0x79;
00049         case 'f':
00050         case 'F':
00051             return 0x71;
00052         case 'g':
00053         case 'G':
00054             return 0x3d;
00055         case 'h':
00056         case 'H':
00057             return 0x76;
00058         case 'i':
00059         case 'I':
00060             return 0x30;
00061         case 'j':
00062         case 'J':
00063             return 0x1e;
00064         case 'k':
00065         case 'K':
00066             return 0x76;
00067         case 'l':
00068         case 'L':
00069             return 0x38;
00070         case 'm':
00071         case 'M':
00072             return 0x15;
00073         case 'n':
00074         case 'N':
00075             return 0x54;
00076         case 'o':
00077         case 'O':
00078             return 0x3f;
00079         case 'p':
00080         case 'P':
00081             return 0x73;
00082         case 'q':
00083         case 'Q':
00084             return 0x67;
00085         case 'r':
00086         case 'R':
00087             return 0x50;
00088         case 's':
00089         case 'S':
00090             return 0x6d;
00091         case 't':
00092         case 'T':
00093             return 0x78;
00094         case 'u':
00095         case 'U':
00096             return 0x3e;
00097         case 'v':
00098         case 'V':
00099             return 0x1c;
00100         case 'w':
00101         case 'W':
00102             return 0x2a;
00103         case 'x':
00104         case 'X':
00105             return 0x76;
00106         case 'y':
00107         case 'Y':
00108             return 0x6E;
00109         case 'z':
00110         case 'Z':
00111             return 0x5b;
00112         case '-':
00113             return 0x40;
00114         case '_':
00115             return 0x08;
00116             
00117         default:
00118             return 0x00;
00119     }
00120 }
00121 
00122 void DisplayManager::showMessage(char* message, int len) {
00123     int shifts = 0;
00124     char* cur = &message[0];
00125     char* back = &message[len - 1];
00126     uint8_t buf[4] = { 0x00, 0x00, 0x00, 0x00 };
00127     
00128     while (shifts <= len + 4) {
00129         buf[0] = buf[1];
00130         buf[1] = buf[2];
00131         buf[2] = buf[3];
00132         if (cur == back) {
00133             buf[3] = 0x00;
00134         } else {
00135             buf[3] = convert(*cur);
00136             cur++;
00137         }
00138         
00139         shifts++;
00140         display->writeRaw(buf);
00141         wait(0.5);
00142     }
00143     
00144     wait(1);
00145 }
00146 
00147 void DisplayManager::clear() {
00148     display->clear();
00149 }