Dot Matrix LED
- 준비물
: 라두이노 미니, Dot matrix LED
회로도
소스 코드 다운로드 ( 2018. 10. 18 업데이트 )
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 | int dataPin = PA2; // The Serial Data Pin to the Shift Register DS int latchPin = PA1; // The Latch Pin to the Shift Register ST int clockPin = PA0; // The Clock Pin to the Shift Register SH // Basic alphabet byte letters[][6] = { { 0x7F, 0x88, 0x88, 0x88, 0x7F, 0x00}, // A { 0xFF, 0x91, 0x91, 0x91, 0x6E, 0x00}, // B { 0x7E, 0x81, 0x81, 0x81, 0x42, 0x00}, // C { 0xFF, 0x81, 0x81, 0x42, 0x3C, 0x00}, // D { 0xFF, 0x91, 0x91, 0x91, 0x81, 0x00}, // E { 0xFF, 0x90, 0x90, 0x90, 0x80, 0x00}, // F { 0x7E, 0x81, 0x89, 0x89, 0x4E, 0x00}, // G { 0xFF, 0x10, 0x10, 0x10, 0xFF, 0x00}, // H { 0x81, 0x81, 0xFF, 0x81, 0x81, 0x00}, // I { 0x06, 0x01, 0x01, 0x01, 0xFE, 0x00}, // J { 0xFF, 0x18, 0x24, 0x42, 0x81, 0x00}, // K { 0xFF, 0x01, 0x01, 0x01, 0x01, 0x00}, // L { 0xFF, 0x40, 0x30, 0x40, 0xFF, 0x00}, // M { 0xFF, 0x40, 0x30, 0x08, 0xFF, 0x00}, // N { 0x7E, 0x81, 0x81, 0x81, 0x7E, 0x00}, // O { 0xFF, 0x88, 0x88, 0x88, 0x70, 0x00}, // P { 0x7E, 0x81, 0x85, 0x82, 0x7D, 0x00}, // Q { 0xFF, 0x88, 0x8C, 0x8A, 0x71, 0x00}, // R { 0x61, 0x91, 0x91, 0x91, 0x8E, 0x00}, // S { 0x80, 0x80, 0xFF, 0x80, 0x80, 0x00}, // T { 0xFE, 0x01, 0x01, 0x01, 0xFE, 0x00}, // U { 0xF0, 0x0C, 0x03, 0x0C, 0xF0, 0x00}, // V { 0xFF, 0x02, 0x0C, 0x02, 0xFF, 0x00}, // W { 0xC3, 0x24, 0x18, 0x24, 0xC3, 0x00}, // X { 0xE0, 0x10, 0x0F, 0x10, 0xE0, 0x00}, // Y { 0x83, 0x85, 0x99, 0xA1, 0xC1, 0x00}, // Z { 0x06, 0x29, 0x29, 0x29, 0x1F, 0x00}, // a { 0xFF, 0x09, 0x11, 0x11, 0x0E, 0x00}, // b { 0x1E, 0x21, 0x21, 0x21, 0x12, 0x00}, // c { 0x0E, 0x11, 0x11, 0x09, 0xFF, 0x00}, // d { 0x0E, 0x15, 0x15, 0x15, 0x0C, 0x00}, // e { 0x08, 0x7F, 0x88, 0x80, 0x40, 0x00}, // f { 0x30, 0x49, 0x49, 0x49, 0x7E, 0x00}, // g { 0xFF, 0x08, 0x10, 0x10, 0x0F, 0x00}, // h { 0x00, 0x00, 0x5F, 0x00, 0x00, 0x00}, // i { 0x02, 0x01, 0x21, 0xBE, 0x00, 0x00}, // j { 0xFF, 0x04, 0x0A, 0x11, 0x00, 0x00}, // k { 0x00, 0x81, 0xFF, 0x01, 0x00, 0x00}, // l { 0x3F, 0x20, 0x18, 0x20, 0x1F, 0x00}, // m { 0x3F, 0x10, 0x20, 0x20, 0x1F, 0x00}, // n { 0x0E, 0x11, 0x11, 0x11, 0x0E, 0x00}, // o { 0x3F, 0x24, 0x24, 0x24, 0x18, 0x00}, // p { 0x10, 0x28, 0x28, 0x18, 0x3F, 0x00}, // q { 0x1F, 0x08, 0x10, 0x10, 0x08, 0x00}, // r { 0x09, 0x15, 0x15, 0x15, 0x02, 0x00}, // s { 0x20, 0xFE, 0x21, 0x01, 0x02, 0x00}, // t { 0x1E, 0x01, 0x01, 0x02, 0x1F, 0x00}, // u { 0x1C, 0x02, 0x01, 0x02, 0x1C, 0x00}, // v { 0x1E, 0x01, 0x0E, 0x01, 0x1E, 0x00}, // w { 0x11, 0x0A, 0x04, 0x0A, 0x11, 0x00}, // x { 0x00, 0x39, 0x05, 0x05, 0x3E, 0x00}, // y { 0x11, 0x13, 0x15, 0x19, 0x11, 0x00}, // z { 0x00, 0x41, 0xFF, 0x01, 0x00, 0x00}, // 1 { 0x43, 0x85, 0x89, 0x91, 0x61, 0x00}, // 2 { 0x42, 0x81, 0x91, 0x91, 0x6E, 0x00}, // 3 { 0x18, 0x28, 0x48, 0xFF, 0x08, 0x00}, // 4 { 0xF2, 0x91, 0x91, 0x91, 0x8E, 0x00}, // 5 { 0x1E, 0x29, 0x49, 0x89, 0x86, 0x00}, // 6 { 0x80, 0x8F, 0x90, 0xA0, 0xC0, 0x00}, // 7 { 0x6E, 0x91, 0x91, 0x91, 0x6E, 0x00}, // 8 { 0x70, 0x89, 0x89, 0x8A, 0x7C, 0x00}, // 9 { 0x7E, 0x89, 0x91, 0xA1, 0x7E, 0x00}, // 0 { 0x60, 0x80, 0x8D, 0x90, 0x60, 0x00}, // ? { 0x00, 0x00, 0xFD, 0x00, 0x00, 0x00}, // ! { 0x18, 0x3C, 0x1E, 0x3C, 0x18, 0x00}, // Heart(*) { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00} // SPACE }; // character to letter mapping String letterPositions = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890?!* "; // The database for the text to scroll byte *textBytes; int nrLetters = 0; int columnPositions[8] = { 1, 2, 4, 8, 16, 32, 64, 128 }; void setup() { pinMode(dataPin, OUTPUT); // Configure Digital Pins, dsPin of 74HC595 pinMode(latchPin, OUTPUT); // ST_CP of 74HC595 pinMode(clockPin, OUTPUT); // SH_CP of 74HC595 // Text = Hello from AndyQ loadString(" *DNU* *DNU* *DNU* *DNU* *DNU* *DNU* *DNU*"); } void loop() { for ( int p = 0 ; p < (nrLetters * 6) ; p++ ) { int rowVal = 0; // Change repeat to vary the speed of the scrolling text for (int repeat = 0; repeat < 250; repeat++ ) { for ( int row = 0 ; row < 8 ; ++row ) { rowVal = textBytes[p + row]; // For some reason, columnPositions are set sanely (e.g. 1,2,4,8,16,32,64,128) // BUT the row values are inverted - so a 1 means off and a 0 is on! // so we invert the bits in the rowVal. writeOutput(~rowVal, columnPositions[row]); } } } } void loadString( String text ) { // Build up byte array nrLetters = text.length(); // Allocate memory for byte array textBytes = (byte *)malloc(nrLetters * 6 * sizeof(byte)); int pos = 0; for ( int i = 0 ; i < nrLetters ; ++i ) { int chPos = letterPositions.indexOf( text[i] ); if ( chPos == -1 ) continue; for ( int j = 0 ; j < 6 ; ++j ) { textBytes[pos++] = letters[chPos][j]; } } } void writeOutput( int rowVal, int col ) { shiftOut(dataPin, clockPin, MSBFIRST, col); // Send the column data byte shiftOut(dataPin, clockPin, MSBFIRST, rowVal); // Send the row data byte digitalWrite(latchPin, HIGH); // Pull latch HIGH to finish sending data digitalWrite(latchPin, LOW); // Pull latch LOW to send data } | cs |
예제2. 도트 매트릭스 LED '고전게임'의 그 캐릭터 소스코드
- 소스코드
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 | // include the library code: #include "config.h" #include "gfx.h" long timer = 0; byte displayMemory[8]; int k; int count; void setup() { pinMode(REG_LATCH, OUTPUT); pinMode(REG_CLOCK, OUTPUT); pinMode(REG_DATA, OUTPUT); k = 4; count = 0; loadToMemory(invader1a); } void loop() { if (millis() - timer > 1000) { timer = millis(); count++; if(count == 4) count = 0; if(count == 0) loadToMemory(invader1a); if(count == 1) loadToMemory(invader1b); if(count == 2) loadToMemory(invader2a); if(count == 3) loadToMemory(invader2b); } drawDisplayMemory(); } void update() { for (int i = 7; i > 0; i--) { displayMemory[i] = displayMemory[i - 1]; } int r = random(0,5); if (r == 0 && k > 0) k--; if (r == 2 && k < 7) k++; displayMemory[0] = 1 << k; } void drawDisplayMemory() { for (int i = 0; i < 8; i++) { displayData(0); displayData(0); displayData(1 << (7 - i)); displayData(~displayMemory[i]); delay(1); } } void clearDisplayMemory() { for (int i = 0; i < 8; i++) { displayMemory[i] = 0; } } void setPixel(byte x, byte y, byte p) { if (p > 0) { displayMemory[y] = bitSet(displayMemory[y], x); } else { displayMemory[y] = bitClear(displayMemory[y], x); } } void loadToMemory(byte data[]) { for (int i = 0; i < 8; i++) { displayMemory[i] = data[i]; } } void displayData(int data) { digitalWrite(REG_LATCH, LOW); shiftOut(REG_DATA, REG_CLOCK, LSBFIRST, data); digitalWrite(REG_LATCH, HIGH); } | cs |
- 소스코드 다운로드
'교육 자료 > Raduino mini' 카테고리의 다른 글
12. BLE4.0(HM-10) 비행제어 (0) | 2018.10.08 |
---|---|
11. SBUS 비행제어 (0) | 2018.10.08 |
6. SOUND (0) | 2018.10.01 |
5. RGB (0) | 2018.10.01 |
7. RGB + SOUND (0) | 2018.10.01 |