LPC1768 programm for the led matrix.
Dependencies: BufferedSerial DS3231 mbed-rtos mbed
main.cpp@1:3a39b1439456, 2016-08-03 (annotated)
- Committer:
- JOEV
- Date:
- Wed Aug 03 07:28:20 2016 +0000
- Revision:
- 1:3a39b1439456
- Parent:
- 0:41f9c251097c
- Child:
- 2:d5472e4a55bf
Features:; >Animated Frames (needs to be done with an Editor); >Set speed with a Poti; >expendable
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
JOEV | 0:41f9c251097c | 1 | #include <mbed.h> |
JOEV | 0:41f9c251097c | 2 | #include <string> |
JOEV | 0:41f9c251097c | 3 | #include <ctype.h> |
JOEV | 0:41f9c251097c | 4 | |
JOEV | 0:41f9c251097c | 5 | |
JOEV | 0:41f9c251097c | 6 | //------------------------------------------------------------------------------------------------------ |
JOEV | 0:41f9c251097c | 7 | // Analog I/O, Digital I/O, etc. |
JOEV | 0:41f9c251097c | 8 | //------------------------------------------------------------------------------------------------------ |
JOEV | 1:3a39b1439456 | 9 | DigitalOut ds1(p5), oe1(p6), stcp1(p7), shcp1(p8), mr1(p9); |
JOEV | 1:3a39b1439456 | 10 | AnalogIn ain(p20); |
JOEV | 1:3a39b1439456 | 11 | Ticker tick; |
JOEV | 0:41f9c251097c | 12 | /* |
JOEV | 0:41f9c251097c | 13 | DS normal Serial Data Output Schreibt vor ob das LED 0 oder 1 ist. |
JOEV | 0:41f9c251097c | 14 | OE invertiert Output-Enable Aktiviert oder deaktiviert die LEDs. |
JOEV | 0:41f9c251097c | 15 | SHCP normal Shift register clk Setzt Position mit kurzen Impulsen fest. |
JOEV | 0:41f9c251097c | 16 | STCP normal Storage reg. clk Setzt Reihe mit kurzen Impulsen fest. |
JOEV | 0:41f9c251097c | 17 | MR invertiert Master reset resetet den Storage. Muss mit STCP angezeigt werden. |
JOEV | 1:3a39b1439456 | 18 | |
JOEV | 0:41f9c251097c | 19 | */ |
JOEV | 0:41f9c251097c | 20 | //------------------------------------------------------------------------------------------------------ |
JOEV | 0:41f9c251097c | 21 | // Voids & Ticker, Ints, etc. |
JOEV | 0:41f9c251097c | 22 | //------------------------------------------------------------------------------------------------------ |
JOEV | 1:3a39b1439456 | 23 | int a = 0, x, y, z, t, temp, speed=10; |
JOEV | 0:41f9c251097c | 24 | |
JOEV | 1:3a39b1439456 | 25 | int zahl[][8] ={ |
JOEV | 1:3a39b1439456 | 26 | {255,255,112,56,56,112,255,255}, |
JOEV | 1:3a39b1439456 | 27 | {255,112,56,56,112,255,255,0}, |
JOEV | 1:3a39b1439456 | 28 | {112,56,56,112,255,255,0,2}, |
JOEV | 1:3a39b1439456 | 29 | {56,56,112,255,255,0,2,23}, |
JOEV | 1:3a39b1439456 | 30 | {56,112,255,255,0,2,23,21}, |
JOEV | 1:3a39b1439456 | 31 | {112,255,255,0,2,23,21,21}, |
JOEV | 1:3a39b1439456 | 32 | {255,255,0,2,23,21,21,31}, |
JOEV | 1:3a39b1439456 | 33 | {255,0,2,23,21,21,31,15}, |
JOEV | 1:3a39b1439456 | 34 | {0,2,23,21,21,31,15,0}, |
JOEV | 1:3a39b1439456 | 35 | {2,23,21,21,31,15,0,17}, |
JOEV | 1:3a39b1439456 | 36 | {23,21,21,31,15,0,17,27}, |
JOEV | 1:3a39b1439456 | 37 | {21,21,31,15,0,17,27,14}, |
JOEV | 1:3a39b1439456 | 38 | {21,31,15,0,17,27,14,14}, |
JOEV | 1:3a39b1439456 | 39 | {31,15,0,17,27,14,14,27}, |
JOEV | 1:3a39b1439456 | 40 | {15,0,17,27,14,14,27,17}, |
JOEV | 1:3a39b1439456 | 41 | {0,17,27,14,14,27,17,0}, |
JOEV | 1:3a39b1439456 | 42 | {17,27,14,14,27,17,0,14}, |
JOEV | 1:3a39b1439456 | 43 | {27,14,14,27,17,0,14,31}, |
JOEV | 1:3a39b1439456 | 44 | {14,14,27,17,0,14,31,17}, |
JOEV | 1:3a39b1439456 | 45 | {14,27,17,0,14,31,17,17}, |
JOEV | 1:3a39b1439456 | 46 | {27,17,0,14,31,17,17,31}, |
JOEV | 1:3a39b1439456 | 47 | {17,0,14,31,17,17,31,14}, |
JOEV | 1:3a39b1439456 | 48 | {0,14,31,17,17,31,14,0}, |
JOEV | 1:3a39b1439456 | 49 | {14,31,17,17,31,14,0,31}, |
JOEV | 1:3a39b1439456 | 50 | {31,17,17,31,14,0,31,31}, |
JOEV | 1:3a39b1439456 | 51 | {17,17,31,14,0,31,31,24}, |
JOEV | 1:3a39b1439456 | 52 | {17,31,14,0,31,31,24,24}, |
JOEV | 1:3a39b1439456 | 53 | {31,14,0,31,31,24,24,31}, |
JOEV | 1:3a39b1439456 | 54 | {14,0,31,31,24,24,31,15}, |
JOEV | 1:3a39b1439456 | 55 | {0,31,31,24,24,31,15,0}, |
JOEV | 1:3a39b1439456 | 56 | {31,31,24,24,31,15,0,0}, |
JOEV | 1:3a39b1439456 | 57 | {31,24,24,31,15,0,0,0}, |
JOEV | 1:3a39b1439456 | 58 | {24,24,31,15,0,0,0,0}, |
JOEV | 1:3a39b1439456 | 59 | {24,31,15,0,0,0,0,0}, |
JOEV | 1:3a39b1439456 | 60 | {31,15,0,0,0,0,0,0}, |
JOEV | 1:3a39b1439456 | 61 | {15,0,0,0,0,0,0,0}, |
JOEV | 1:3a39b1439456 | 62 | {0,0,0,0,0,0,0,0}, |
JOEV | 1:3a39b1439456 | 63 | {0,0,0,0,0,0,0,255}, |
JOEV | 1:3a39b1439456 | 64 | {0,0,0,0,0,0,255,255}, |
JOEV | 1:3a39b1439456 | 65 | {0,0,0,0,0,255,255,112}, |
JOEV | 1:3a39b1439456 | 66 | {0,0,0,0,255,255,112,56}, |
JOEV | 1:3a39b1439456 | 67 | {0,0,0,255,255,112,56,56}, |
JOEV | 1:3a39b1439456 | 68 | {0,0,255,255,112,56,56,112}, |
JOEV | 1:3a39b1439456 | 69 | {0,255,255,112,56,56,112,255} |
JOEV | 0:41f9c251097c | 70 | |
JOEV | 0:41f9c251097c | 71 | |
JOEV | 1:3a39b1439456 | 72 | }; |
JOEV | 1:3a39b1439456 | 73 | |
JOEV | 1:3a39b1439456 | 74 | int const size_y = sizeof(zahl) / sizeof(zahl[0]); |
JOEV | 1:3a39b1439456 | 75 | int const size_x = sizeof(zahl[0]) / sizeof(zahl[0][0]); |
JOEV | 1:3a39b1439456 | 76 | |
JOEV | 1:3a39b1439456 | 77 | bool row_temp[8]; |
JOEV | 1:3a39b1439456 | 78 | void shift_srg(), reset_srg(), setSpeed(); //, set_srg(bool status_[]); |
JOEV | 1:3a39b1439456 | 79 | //------------------------------------------------------------------------------------------------------ |
JOEV | 1:3a39b1439456 | 80 | // Vorgang |
JOEV | 1:3a39b1439456 | 81 | //------------------------------------------------------------------------------------------------------ |
JOEV | 1:3a39b1439456 | 82 | /* |
JOEV | 1:3a39b1439456 | 83 | Zuerst müssen die ersten 8 DS den Wert 1 entsprechen, weil diese für die Kathoden Seite der Matrix ist. |
JOEV | 1:3a39b1439456 | 84 | Die beiden 74HC595-ICs sind miteinander über dem Q7s und DS verbunden. Was aus dem ersten IC herauskommt, |
JOEV | 1:3a39b1439456 | 85 | wird beim zweiten als Eingangswert benützt. |
JOEV | 1:3a39b1439456 | 86 | */ |
JOEV | 0:41f9c251097c | 87 | //------------------------------------------------------------------------------------------------------ |
JOEV | 0:41f9c251097c | 88 | // Main |
JOEV | 0:41f9c251097c | 89 | //------------------------------------------------------------------------------------------------------ |
JOEV | 0:41f9c251097c | 90 | int main() |
JOEV | 0:41f9c251097c | 91 | { |
JOEV | 1:3a39b1439456 | 92 | mr1 = 1; |
JOEV | 1:3a39b1439456 | 93 | oe1 = 0; |
JOEV | 1:3a39b1439456 | 94 | ds1 = 0; |
JOEV | 1:3a39b1439456 | 95 | stcp1 = 0; |
JOEV | 1:3a39b1439456 | 96 | shcp1 = 0; |
JOEV | 1:3a39b1439456 | 97 | |
JOEV | 1:3a39b1439456 | 98 | tick.attach(&setSpeed,0.005); |
JOEV | 0:41f9c251097c | 99 | reset_srg(); |
JOEV | 1:3a39b1439456 | 100 | |
JOEV | 1:3a39b1439456 | 101 | |
JOEV | 1:3a39b1439456 | 102 | |
JOEV | 0:41f9c251097c | 103 | while(1) |
JOEV | 1:3a39b1439456 | 104 | { |
JOEV | 1:3a39b1439456 | 105 | for(t = 0; t < speed; t++) |
JOEV | 0:41f9c251097c | 106 | { |
JOEV | 1:3a39b1439456 | 107 | for(z = 0; z < 8; z++) |
JOEV | 0:41f9c251097c | 108 | { |
JOEV | 1:3a39b1439456 | 109 | |
JOEV | 1:3a39b1439456 | 110 | for(y = 0; y < 8; y++) |
JOEV | 0:41f9c251097c | 111 | { |
JOEV | 1:3a39b1439456 | 112 | row_temp[y] = (zahl[a][z] >> y) & 1; |
JOEV | 1:3a39b1439456 | 113 | } |
JOEV | 1:3a39b1439456 | 114 | |
JOEV | 1:3a39b1439456 | 115 | for(x = 0; x < 8; x++) |
JOEV | 1:3a39b1439456 | 116 | { |
JOEV | 1:3a39b1439456 | 117 | if(x == z) |
JOEV | 0:41f9c251097c | 118 | { |
JOEV | 1:3a39b1439456 | 119 | ds1 = 1; |
JOEV | 1:3a39b1439456 | 120 | } |
JOEV | 1:3a39b1439456 | 121 | else |
JOEV | 0:41f9c251097c | 122 | { |
JOEV | 1:3a39b1439456 | 123 | ds1 = 0; |
JOEV | 1:3a39b1439456 | 124 | } |
JOEV | 1:3a39b1439456 | 125 | shift_srg(); |
JOEV | 1:3a39b1439456 | 126 | } |
JOEV | 1:3a39b1439456 | 127 | |
JOEV | 1:3a39b1439456 | 128 | for(x = 0; x < 8; x++) |
JOEV | 1:3a39b1439456 | 129 | { |
JOEV | 1:3a39b1439456 | 130 | ds1 = row_temp[x]; |
JOEV | 1:3a39b1439456 | 131 | shift_srg(); |
JOEV | 1:3a39b1439456 | 132 | } |
JOEV | 1:3a39b1439456 | 133 | |
JOEV | 1:3a39b1439456 | 134 | stcp1 = 1; |
JOEV | 1:3a39b1439456 | 135 | wait_ms(0.1); |
JOEV | 1:3a39b1439456 | 136 | stcp1 = 0; |
JOEV | 1:3a39b1439456 | 137 | |
JOEV | 1:3a39b1439456 | 138 | } |
JOEV | 1:3a39b1439456 | 139 | } |
JOEV | 1:3a39b1439456 | 140 | a++; |
JOEV | 1:3a39b1439456 | 141 | if(a == size_y) |
JOEV | 1:3a39b1439456 | 142 | a = 0; |
JOEV | 1:3a39b1439456 | 143 | } |
JOEV | 0:41f9c251097c | 144 | } // Ende main |
JOEV | 0:41f9c251097c | 145 | |
JOEV | 0:41f9c251097c | 146 | |
JOEV | 0:41f9c251097c | 147 | //------------------------------------------------------------------------------------------------------ |
JOEV | 0:41f9c251097c | 148 | // Voids & Floats |
JOEV | 0:41f9c251097c | 149 | //------------------------------------------------------------------------------------------------------ |
JOEV | 0:41f9c251097c | 150 | |
JOEV | 1:3a39b1439456 | 151 | void shift_srg() |
JOEV | 0:41f9c251097c | 152 | { |
JOEV | 1:3a39b1439456 | 153 | wait_ms(0.1); // Perioden-Dauer 2ms, später verkürzen |
JOEV | 0:41f9c251097c | 154 | shcp1 = 1; |
JOEV | 1:3a39b1439456 | 155 | wait_ms(0.1); |
JOEV | 0:41f9c251097c | 156 | shcp1 = 0; |
JOEV | 0:41f9c251097c | 157 | } |
JOEV | 0:41f9c251097c | 158 | |
JOEV | 0:41f9c251097c | 159 | void reset_srg() |
JOEV | 0:41f9c251097c | 160 | { |
JOEV | 0:41f9c251097c | 161 | mr1 = 0; |
JOEV | 1:3a39b1439456 | 162 | wait_ms(0.1); // Reset-Puls 1ms, später verkürzen |
JOEV | 0:41f9c251097c | 163 | mr1 = 1; |
JOEV | 0:41f9c251097c | 164 | } |
JOEV | 0:41f9c251097c | 165 | |
JOEV | 1:3a39b1439456 | 166 | void setSpeed() |
JOEV | 1:3a39b1439456 | 167 | { |
JOEV | 1:3a39b1439456 | 168 | speed = ain * 1000; |
JOEV | 1:3a39b1439456 | 169 | } |
JOEV | 1:3a39b1439456 | 170 | |
JOEV | 0:41f9c251097c | 171 | /* |
JOEV | 1:3a39b1439456 | 172 | for(x = 0; x < 16; x++) |
JOEV | 0:41f9c251097c | 173 | { |
JOEV | 1:3a39b1439456 | 174 | switch(x) |
JOEV | 1:3a39b1439456 | 175 | { // 0-7 = Kathode, 8-15 = Anoden |
JOEV | 1:3a39b1439456 | 176 | case 7: case 9: case 10: case 11: case 13: case 14: case 15: |
JOEV | 1:3a39b1439456 | 177 | ds1 = 1; |
JOEV | 1:3a39b1439456 | 178 | shift_srg(); |
JOEV | 1:3a39b1439456 | 179 | break; |
JOEV | 1:3a39b1439456 | 180 | default: |
JOEV | 1:3a39b1439456 | 181 | ds1 = 0; |
JOEV | 1:3a39b1439456 | 182 | shift_srg(); |
JOEV | 1:3a39b1439456 | 183 | break; |
JOEV | 1:3a39b1439456 | 184 | } |
JOEV | 1:3a39b1439456 | 185 | }*/ |
JOEV | 0:41f9c251097c | 186 |