scroller for 4 digit display, rides on top of DigitDisplay and scrolls messages of arbitrary length
Dependencies: DigitDisplay mbed
DisplayManager/DisplayManager.cpp@0:f8d65945b096, 2014-09-07 (annotated)
- Committer:
- mfiore
- Date:
- Sun Sep 07 05:30:25 2014 +0000
- Revision:
- 0:f8d65945b096
initial commit - looks good and supports 0-9, a-b, hyphen, and underscore
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mfiore | 0:f8d65945b096 | 1 | #include "mbed.h" |
mfiore | 0:f8d65945b096 | 2 | #include "DisplayManager.h" |
mfiore | 0:f8d65945b096 | 3 | |
mfiore | 0:f8d65945b096 | 4 | DisplayManager::DisplayManager(PinName clk, PinName dio) : display(NULL) { |
mfiore | 0:f8d65945b096 | 5 | display = new DigitDisplay(clk, dio); |
mfiore | 0:f8d65945b096 | 6 | } |
mfiore | 0:f8d65945b096 | 7 | |
mfiore | 0:f8d65945b096 | 8 | DisplayManager::~DisplayManager() { |
mfiore | 0:f8d65945b096 | 9 | if (display) delete display; |
mfiore | 0:f8d65945b096 | 10 | } |
mfiore | 0:f8d65945b096 | 11 | |
mfiore | 0:f8d65945b096 | 12 | uint8_t DisplayManager::convert(uint8_t value) { |
mfiore | 0:f8d65945b096 | 13 | switch (value) { |
mfiore | 0:f8d65945b096 | 14 | case '0': |
mfiore | 0:f8d65945b096 | 15 | return 0x3f; |
mfiore | 0:f8d65945b096 | 16 | case '1': |
mfiore | 0:f8d65945b096 | 17 | return 0x06; |
mfiore | 0:f8d65945b096 | 18 | case '2': |
mfiore | 0:f8d65945b096 | 19 | return 0x5b; |
mfiore | 0:f8d65945b096 | 20 | case '3': |
mfiore | 0:f8d65945b096 | 21 | return 0x4f; |
mfiore | 0:f8d65945b096 | 22 | case '4': |
mfiore | 0:f8d65945b096 | 23 | return 0x66; |
mfiore | 0:f8d65945b096 | 24 | case '5': |
mfiore | 0:f8d65945b096 | 25 | return 0x6d; |
mfiore | 0:f8d65945b096 | 26 | case '6': |
mfiore | 0:f8d65945b096 | 27 | return 0x7d; |
mfiore | 0:f8d65945b096 | 28 | case '7': |
mfiore | 0:f8d65945b096 | 29 | return 0x07; |
mfiore | 0:f8d65945b096 | 30 | case '8': |
mfiore | 0:f8d65945b096 | 31 | return 0x7f; |
mfiore | 0:f8d65945b096 | 32 | case '9': |
mfiore | 0:f8d65945b096 | 33 | return 0x6f; |
mfiore | 0:f8d65945b096 | 34 | case 'a': |
mfiore | 0:f8d65945b096 | 35 | case 'A': |
mfiore | 0:f8d65945b096 | 36 | return 0x77; |
mfiore | 0:f8d65945b096 | 37 | case 'b': |
mfiore | 0:f8d65945b096 | 38 | case 'B': |
mfiore | 0:f8d65945b096 | 39 | return 0x7c; |
mfiore | 0:f8d65945b096 | 40 | case 'c': |
mfiore | 0:f8d65945b096 | 41 | case 'C': |
mfiore | 0:f8d65945b096 | 42 | return 0x39; |
mfiore | 0:f8d65945b096 | 43 | case 'd': |
mfiore | 0:f8d65945b096 | 44 | case 'D': |
mfiore | 0:f8d65945b096 | 45 | return 0x5e; |
mfiore | 0:f8d65945b096 | 46 | case 'e': |
mfiore | 0:f8d65945b096 | 47 | case 'E': |
mfiore | 0:f8d65945b096 | 48 | return 0x79; |
mfiore | 0:f8d65945b096 | 49 | case 'f': |
mfiore | 0:f8d65945b096 | 50 | case 'F': |
mfiore | 0:f8d65945b096 | 51 | return 0x71; |
mfiore | 0:f8d65945b096 | 52 | case 'g': |
mfiore | 0:f8d65945b096 | 53 | case 'G': |
mfiore | 0:f8d65945b096 | 54 | return 0x3d; |
mfiore | 0:f8d65945b096 | 55 | case 'h': |
mfiore | 0:f8d65945b096 | 56 | case 'H': |
mfiore | 0:f8d65945b096 | 57 | return 0x76; |
mfiore | 0:f8d65945b096 | 58 | case 'i': |
mfiore | 0:f8d65945b096 | 59 | case 'I': |
mfiore | 0:f8d65945b096 | 60 | return 0x30; |
mfiore | 0:f8d65945b096 | 61 | case 'j': |
mfiore | 0:f8d65945b096 | 62 | case 'J': |
mfiore | 0:f8d65945b096 | 63 | return 0x1e; |
mfiore | 0:f8d65945b096 | 64 | case 'k': |
mfiore | 0:f8d65945b096 | 65 | case 'K': |
mfiore | 0:f8d65945b096 | 66 | return 0x76; |
mfiore | 0:f8d65945b096 | 67 | case 'l': |
mfiore | 0:f8d65945b096 | 68 | case 'L': |
mfiore | 0:f8d65945b096 | 69 | return 0x38; |
mfiore | 0:f8d65945b096 | 70 | case 'm': |
mfiore | 0:f8d65945b096 | 71 | case 'M': |
mfiore | 0:f8d65945b096 | 72 | return 0x15; |
mfiore | 0:f8d65945b096 | 73 | case 'n': |
mfiore | 0:f8d65945b096 | 74 | case 'N': |
mfiore | 0:f8d65945b096 | 75 | return 0x54; |
mfiore | 0:f8d65945b096 | 76 | case 'o': |
mfiore | 0:f8d65945b096 | 77 | case 'O': |
mfiore | 0:f8d65945b096 | 78 | return 0x3f; |
mfiore | 0:f8d65945b096 | 79 | case 'p': |
mfiore | 0:f8d65945b096 | 80 | case 'P': |
mfiore | 0:f8d65945b096 | 81 | return 0x73; |
mfiore | 0:f8d65945b096 | 82 | case 'q': |
mfiore | 0:f8d65945b096 | 83 | case 'Q': |
mfiore | 0:f8d65945b096 | 84 | return 0x67; |
mfiore | 0:f8d65945b096 | 85 | case 'r': |
mfiore | 0:f8d65945b096 | 86 | case 'R': |
mfiore | 0:f8d65945b096 | 87 | return 0x50; |
mfiore | 0:f8d65945b096 | 88 | case 's': |
mfiore | 0:f8d65945b096 | 89 | case 'S': |
mfiore | 0:f8d65945b096 | 90 | return 0x6d; |
mfiore | 0:f8d65945b096 | 91 | case 't': |
mfiore | 0:f8d65945b096 | 92 | case 'T': |
mfiore | 0:f8d65945b096 | 93 | return 0x78; |
mfiore | 0:f8d65945b096 | 94 | case 'u': |
mfiore | 0:f8d65945b096 | 95 | case 'U': |
mfiore | 0:f8d65945b096 | 96 | return 0x3e; |
mfiore | 0:f8d65945b096 | 97 | case 'v': |
mfiore | 0:f8d65945b096 | 98 | case 'V': |
mfiore | 0:f8d65945b096 | 99 | return 0x1c; |
mfiore | 0:f8d65945b096 | 100 | case 'w': |
mfiore | 0:f8d65945b096 | 101 | case 'W': |
mfiore | 0:f8d65945b096 | 102 | return 0x2a; |
mfiore | 0:f8d65945b096 | 103 | case 'x': |
mfiore | 0:f8d65945b096 | 104 | case 'X': |
mfiore | 0:f8d65945b096 | 105 | return 0x76; |
mfiore | 0:f8d65945b096 | 106 | case 'y': |
mfiore | 0:f8d65945b096 | 107 | case 'Y': |
mfiore | 0:f8d65945b096 | 108 | return 0x6E; |
mfiore | 0:f8d65945b096 | 109 | case 'z': |
mfiore | 0:f8d65945b096 | 110 | case 'Z': |
mfiore | 0:f8d65945b096 | 111 | return 0x5b; |
mfiore | 0:f8d65945b096 | 112 | case '-': |
mfiore | 0:f8d65945b096 | 113 | return 0x40; |
mfiore | 0:f8d65945b096 | 114 | case '_': |
mfiore | 0:f8d65945b096 | 115 | return 0x08; |
mfiore | 0:f8d65945b096 | 116 | |
mfiore | 0:f8d65945b096 | 117 | default: |
mfiore | 0:f8d65945b096 | 118 | return 0x00; |
mfiore | 0:f8d65945b096 | 119 | } |
mfiore | 0:f8d65945b096 | 120 | } |
mfiore | 0:f8d65945b096 | 121 | |
mfiore | 0:f8d65945b096 | 122 | void DisplayManager::showMessage(char* message, int len) { |
mfiore | 0:f8d65945b096 | 123 | int shifts = 0; |
mfiore | 0:f8d65945b096 | 124 | char* cur = &message[0]; |
mfiore | 0:f8d65945b096 | 125 | char* back = &message[len - 1]; |
mfiore | 0:f8d65945b096 | 126 | uint8_t buf[4] = { 0x00, 0x00, 0x00, 0x00 }; |
mfiore | 0:f8d65945b096 | 127 | |
mfiore | 0:f8d65945b096 | 128 | while (shifts <= len + 4) { |
mfiore | 0:f8d65945b096 | 129 | buf[0] = buf[1]; |
mfiore | 0:f8d65945b096 | 130 | buf[1] = buf[2]; |
mfiore | 0:f8d65945b096 | 131 | buf[2] = buf[3]; |
mfiore | 0:f8d65945b096 | 132 | if (cur == back) { |
mfiore | 0:f8d65945b096 | 133 | buf[3] = 0x00; |
mfiore | 0:f8d65945b096 | 134 | } else { |
mfiore | 0:f8d65945b096 | 135 | buf[3] = convert(*cur); |
mfiore | 0:f8d65945b096 | 136 | cur++; |
mfiore | 0:f8d65945b096 | 137 | } |
mfiore | 0:f8d65945b096 | 138 | |
mfiore | 0:f8d65945b096 | 139 | shifts++; |
mfiore | 0:f8d65945b096 | 140 | display->writeRaw(buf); |
mfiore | 0:f8d65945b096 | 141 | wait(0.5); |
mfiore | 0:f8d65945b096 | 142 | } |
mfiore | 0:f8d65945b096 | 143 | |
mfiore | 0:f8d65945b096 | 144 | wait(1); |
mfiore | 0:f8d65945b096 | 145 | } |
mfiore | 0:f8d65945b096 | 146 | |
mfiore | 0:f8d65945b096 | 147 | void DisplayManager::clear() { |
mfiore | 0:f8d65945b096 | 148 | display->clear(); |
mfiore | 0:f8d65945b096 | 149 | } |