아두이노/활용

아두이노 64x16 도트 매트릭스 사용하기

원원 2017. 10. 31. 15:09

안녕하세요. 오늘은 64x16 도트매트릭스를 아두이노 Uno로 제어해보겠습니다. 일단 모듈이 완성품으로 팔아서 사용하기가 매우 쉽습니다.

모델명은 따로 없고 약간씩 바꿔서 판매하는곳이 많아서 가장 싼곳에서 구매하면 됩니다.

 


 

 

 

 

 

사용된 IC는 74HC245,74HC595,74HC138,74HC04,APM4953입니다.

왼쪽부분에는 아두이노 디지털핀에 연결해주면되고 오른쪽부분에는 vcc와 gnd를 연결해주면 됩니다.

 

 

 

 


예제코드

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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
#include <pgmspace.h>
 
// Connections to board
const byte latchPin=8;
const byte clockPin=12;
const byte data_R1=10;
const byte data_R2=11;
const byte en_74138=2;
const byte la_74138=3;
const byte lb_74138=4;
const byte lc_74138=5;
const byte ld_74138=6;
byte ScanRow = 0;
unsigned long counter;
 
 
const char message[] = "wowon.tistory.com    ";
int speed = 35;
 
byte buffer[256= { // Display buffer (which is scanned by the interrupt timer) of 8x32 bytes
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
  0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,
};
// ---------------------------------------------------------------------------------------------------
// FONTS sourced from various locations on the internet
// full ASCII character set (8x16) (1520 bytes)
const uint8_t font8x16_basic[] PROGMEM = {
        /*   (32) */ 0x000x000x000x000x000x000x000x000x000x000x000x000x000x000x000x00,  
    /* ! (33) */ 0x000x000x000x180x3C0x3C0x3C0x180x180x180x000x180x180x000x000x00,
    /* " (34) */ 0x000x000x660x660x660x240x000x000x000x000x000x000x000x000x000x00,
    /* # (35) */ 0x000x000x000x000x6C0x6C0xFE0x6C0x6C0x6C0xFE0x6C0x6C0x000x000x00,
    /* $ (36) */ 0x000x180x180x7C0xC60xC20xC00x7C0x060x060x860xC60x7C0x180x180x00,    
        /* % (37) */ 0x000x000x000x000x000xC20xC60x0C0x180x300x600xC60x860x000x000x00,
    /* & (38) */ 0x000x000x000x380x6C0x6C0x380x760xDC0xCC0xCC0xCC0x760x000x000x00,
    /* ' (39) */ 0x000x000x300x300x300x600x000x000x000x000x000x000x000x000x000x00,
    /* ( (40) */ 0x000x000x000x0C0x180x300x300x300x300x300x300x180x0C0x000x000x00,
    /* ) (41) */ 0x000x000x000x300x180x0C0x0C0x0C0x0C0x0C0x0C0x180x300x000x000x00,
    /* * (42) */ 0x000x000x000x000x000x000x660x3C0xFF0x3C0x660x000x000x000x000x00,
    /* + (43) */ 0x000x000x000x000x000x000x180x180x7E0x180x180x000x000x000x000x00,
    /* , (44) */ 0x000x000x000x000x000x000x000x000x000x000x180x180x180x300x000x00,
    /* - (45) */ 0x000x000x000x000x000x000x000x000xFE0x000x000x000x000x000x000x00,
    /* . (46) */ 0x000x000x000x000x000x000x000x000x000x000x000x180x180x000x000x00,
    /* / (47) */ 0x000x000x000x000x000x020x060x0C0x180x300x600xC00x800x000x000x00,
    /* 0 (48) */ 0x000x000x000x3C0x660xC30xC30xDB0xDB0xC30xC30x660x3C0x000x000x00,
    /* 1 (49) */ 0x000x000x000x180x380x780x180x180x180x180x180x180x7E0x000x000x00,
    /* 2 (50) */ 0x000x000x000x7C0xC60x060x0C0x180x300x600xC00xC60xFE0x000x000x00,
    /* 3 (51) */ 0x000x000x000x7C0xC60x060x060x3C0x060x060x060xC60x7C0x000x000x00,
    /* 4 (52) */ 0x000x000x000x0C0x1C0x3C0x6C0xCC0xFE0x0C0x0C0x0C0x1E0x000x000x00,
    /* 5 (53) */ 0x000x000x000xFE0xC00xC00xC00xFC0x060x060x060xC60x7C0x000x000x00,
    /* 6 (54) */ 0x000x000x000x380x600xC00xC00xFC0xC60xC60xC60xC60x7C0x000x000x00,
    /* 7 (55) */ 0x000x000x000xFE0xC60x060x060x0C0x180x300x300x300x300x000x000x00,
    /* 8 (56) */ 0x000x000x000x7C0xC60xC60xC60x7C0xC60xC60xC60xC60x7C0x000x000x00,
    /* 9 (57) */ 0x000x000x000x7C0xC60xC60xC60x7E0x060x060x060x0C0x780x000x000x00,
    /* : (58) */ 0x000x000x000x000x000x180x180x000x000x000x180x180x000x000x000x00,
    /* ; (59) */ 0x000x000x000x000x000x180x180x000x000x000x180x180x300x000x000x00,
    /* < (60) */ 0x000x000x000x000x060x0C0x180x300x600x300x180x0C0x060x000x000x00,
    /* = (61) */ 0x000x000x000x000x000x000x7E0x000x000x7E0x000x000x000x000x000x00,
    /* > (62) */ 0x000x000x000x000x600x300x180x0C0x060x0C0x180x300x600x000x000x00,
    /* ? (63) */ 0x000x000x000x7C0xC60xC60x0C0x180x180x180x000x180x180x000x000x00,
    /* @ (64) */ 0x000x000x000x000x7C0xC60xC60xDE0xDE0xDE0xDC0xC00x7C0x000x000x00,
    /* A (65) */ 0x000x000x000x100x380x6C0xC60xC60xFE0xC60xC60xC60xC60x000x000x00,
    /* B (66) */ 0x000x000x000xFC0x660x660x660x7C0x660x660x660x660xFC0x000x000x00,
    /* C (67) */ 0x000x000x000x3C0x660xC20xC00xC00xC00xC00xC20x660x3C0x000x000x00,
    /* D (68) */ 0x000x000x000xF80x6C0x660x660x660x660x660x660x6C0xF80x000x000x00,
    /* E (69) */ 0x000x000x000xFE0x660x620x680x780x680x600x620x660xFE0x000x000x00,
    /* F (70) */ 0x000x000x000xFE0x660x620x680x780x680x600x600x600xF00x000x000x00,
    /* G (71) */ 0x000x000x000x3C0x660xC20xC00xC00xDE0xC60xC60x660x3A0x000x000x00,
    /* H (72) */ 0x000x000x000xC60xC60xC60xC60xFE0xC60xC60xC60xC60xC60x000x000x00,
    /* I (73) */ 0x000x000x000x3C0x180x180x180x180x180x180x180x180x3C0x000x000x00,
    /* J (74) */ 0x000x000x000x1E0x0C0x0C0x0C0x0C0x0C0xCC0xCC0xCC0x780x000x000x00,
    /* K (75) */ 0x000x000x000xE60x660x660x6C0x780x780x6C0x660x660xE60x000x000x00,
    /* L (76) */ 0x000x000x000xF00x600x600x600x600x600x600x620x660xFE0x000x000x00,
    /* M (77) */ 0x000x000x000xC30xE70xFF0xFF0xDB0xC30xC30xC30xC30xC30x000x000x00,
    /* N (78) */ 0x000x000x000xC60xE60xF60xFE0xDE0xCE0xC60xC60xC60xC60x000x000x00,
    /* O (79) */ 0x000x000x000x7C0xC60xC60xC60xC60xC60xC60xC60xC60x7C0x000x000x00,
    /* P (80) */ 0x000x000x000xFC0x660x660x660x7C0x600x600x600x600xF00x000x000x00,
    /* Q (81) */ 0x000x000x000x7C0xC60xC60xC60xC60xC60xC60xD60xDE0x7C0x0C0x0E0x00,
    /* R (82) */ 0x000x000x000xFC0x660x660x660x7C0x6C0x660x660x660xE60x000x000x00,
    /* S (83) */ 0x000x000x000x7C0xC60xC60x600x380x0C0x060xC60xC60x7C0x000x000x00,
    /* T (84) */ 0x000x000x000xFF0xDB0x990x180x180x180x180x180x180x3C0x000x000x00,
    /* U (85) */ 0x000x000x000xC60xC60xC60xC60xC60xC60xC60xC60xC60x7C0x000x000x00,
    /* V (86) */ 0x000x000x000xC30xC30xC30xC30xC30xC30xC30x660x3C0x180x000x000x00,
    /* W (87) */ 0x000x000x000xC30xC30xC30xC30xC30xDB0xDB0xFF0x660x660x000x000x00,
    /* X (88) */ 0x000x000x000xC30xC30x660x3C0x180x180x3C0x660xC30xC30x000x000x00,
    /* Y (89) */ 0x000x000x000xC30xC30xC30x660x3C0x180x180x180x180x3C0x000x000x00,
    /* Z (90) */ 0x000x000x000xFF0xC30x860x0C0x180x300x600xC10xC30xFF0x000x000x00,
    /* [ (91) */ 0x000x000x000x3C0x300x300x300x300x300x300x300x300x3C0x000x000x00,
    /* \ (92) */ 0x000x000x000x000x800xC00xE00x700x380x1C0x0E0x060x020x000x000x00,
    /* ] (93) */ 0x000x000x000x3C0x0C0x0C0x0C0x0C0x0C0x0C0x0C0x0C0x3C0x000x000x00,
    /* ^ (94) */ 0x000x100x380x6C0xC60x000x000x000x000x000x000x000x000x000x000x00,
    /* _ (95) */ 0x000x000x000x000x000x000x000x000x000x000x000x000x000x000xFF0x00,
    /* ` (96) */ 0x000x300x300x180x000x000x000x000x000x000x000x000x000x000x000x00,
    /* a (97) */ 0x000x000x000x000x000x000x780x0C0x7C0xCC0xCC0xCC0x760x000x000x00,
    /* b (98) */ 0x000x000x000xE00x600x600x780x6C0x660x660x660x660x7C0x000x000x00,
    /* c (99) */ 0x000x000x000x000x000x000x7C0xC60xC00xC00xC00xC60x7C0x000x000x00,
    /* d (100) */ 0x000x000x000x1C0x0C0x0C0x3C0x6C0xCC0xCC0xCC0xCC0x760x000x000x00,
    /* e (101) */ 0x000x000x000x000x000x000x7C0xC60xFE0xC00xC00xC60x7C0x000x000x00,
    /* f (102) */ 0x000x000x000x380x6C0x640x600xF00x600x600x600x600xF00x000x000x00,
    /* g (103) */ 0x000x000x000x000x000x000x760xCC0xCC0xCC0xCC0xCC0x7C0x0C0xCC0x78,
    /* h (104) */ 0x000x000x000xE00x600x600x6C0x760x660x660x660x660xE60x000x000x00,
    /* i (105) */ 0x000x000x000x180x180x000x380x180x180x180x180x180x3C0x000x000x00,
    /* j (106) */ 0x000x000x000x060x060x000x0E0x060x060x060x060x060x060x660x660x3C,
    /* k (107) */ 0x000x000x000xE00x600x600x660x6C0x780x780x6C0x660xE60x000x000x00,
    /* l (108) */ 0x000x000x000x380x180x180x180x180x180x180x180x180x3C0x000x000x00,
    /* m (109) */ 0x000x000x000x000x000x000xE60xFF0xDB0xDB0xDB0xDB0xDB0x000x000x00,
    /* n (110) */ 0x000x000x000x000x000x000xDC0x660x660x660x660x660x660x000x000x00,
    /* o (111) */ 0x000x000x000x000x000x000x7C0xC60xC60xC60xC60xC60x7C0x000x000x00,
    /* p (112) */ 0x000x000x000x000x000x000xDC0x660x660x660x660x660x7C0x600x600xF0,
    /* q (113) */ 0x000x000x000x000x000x000x760xCC0xCC0xCC0xCC0xCC0x7C0x0C0x0C0x1E,
    /* r (114) */ 0x000x000x000x000x000x000xDC0x760x660x600x600x600xF00x000x000x00,
    /* s (115) */ 0x000x000x000x000x000x000x7C0xC60x600x380x0C0xC60x7C0x000x000x00,
    /* t (116) */ 0x000x000x000x100x300x300xFC0x300x300x300x300x360x1C0x000x000x00,
    /* u (117) */ 0x000x000x000x000x000x000xCC0xCC0xCC0xCC0xCC0xCC0x760x000x000x00,
    /* v (118) */ 0x000x000x000x000x000x000xC30xC30xC30xC30x660x3C0x180x000x000x00,
    /* w (119) */ 0x000x000x000x000x000x000xC30xC30xC30xDB0xDB0xFF0x660x000x000x00,
    /* x (120) */ 0x000x000x000x000x000x000xC30x660x3C0x180x3C0x660xC30x000x000x00,
    /* y (121) */ 0x000x000x000x000x000x000xC60xC60xC60xC60xC60xC60x7E0x060x0C0xF8,
    /* z (122) */ 0x000x000x000x000x000x000xFE0xCC0x180x300x600xC60xFE0x000x000x00,
    /* { (123) */ 0x000x000x000x0E0x180x180x180x700x180x180x180x180x0E0x000x000x00,
    /* | (124) */ 0x000x000x000x180x180x180x180x000x180x180x180x180x180x000x000x00,
    /* } (125) */ 0x000x000x000x700x180x180x180x0E0x180x180x180x180x700x000x000x00,
    /* ~ (126) */ 0x000x000x000x760xDC0x000x000x000x000x000x000x000x000x000x000x00,
        /* BLK(127)*/ 0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF0xFF,
};
// Routine to print a single character in one of 8 columns
// Inputs:
// x is one of (0,16,24,32,40,48,56), 
// y (0 to 16 or 24 depending upon font size),
// n is either (0 to 9) or an ascii value, 
// font=0 for big font, 2 for small font, 
// inverse is true for an inverted character
void drawChar(uint16_t x, uint16_t y, byte n, byte font, boolean inverse) { 
    byte charbytes[16], fontrows, xover8 = x>>3
    int index;
    if (!= (x % 8)) return;    // x not a multiple of 8
    if ((n>9&& (n<32)) return// invalid character
    if (font==0) fontrows=16else fontrows=8;
    if ((n>=0&& (n<=9)) index=(n+16)*fontrows; else index=(n-32)*fontrows; // go to the right code for this character
 
// addressing start at buffer and add y (rows) * (WIDTH is 64 so WIDTH/8) is 8 plus (x / 8) is 0 to 7
    byte *pDst = buffer + (y << 3+ xover8;
    for (byte i=0;i<fontrows;i++) {  // fill up the charbytes array with the right bits
      if (font==0) charbytes[i] = pgm_read_byte(&(font8x16_basic[index+i]));
      // reverse bit order for fonts 0 and 1
      if (font != 0) {
        charbytes[i] = (charbytes[i] & 0xF0>> | (charbytes[i] & 0x0F<< 4;
        charbytes[i] = (charbytes[i] & 0xCC>> | (charbytes[i] & 0x33<< 2;
        charbytes[i] = (charbytes[i] & 0xAA>> | (charbytes[i] & 0x55<< 1;
      };
      if (inverse) charbytes[i] = ~charbytes[i];
      };
    const byte *pSrc = charbytes; // point at the first set of 8 pixels    
    for (byte i=0; i<fontrows; i++) {
        *pDst = *pSrc;     // populate the destination byte
        pDst += 8;         // go to next row on buffer
        pSrc++;            // go to next set of 8 pixels in character
    }
};
 
void moveLeft(byte pixels, byte rowstart, byte rowstop) { // routine to move certain rows on the screen "pixels" pixels to the left
byte row, column; 
short unsigned int address;
  for (column=0;column<8;column++) { 
    for (row=rowstart;row<rowstop;row++) {
      address = (row<<3+ column; /// right here!
      if (column==7
         buffer[address] = buffer[address]<<pixels; // shuffle pixels left on last column and fill with a blank
        else {                // shuffle pixels left and add leftmost pixels from next column
         byte incomingchar = buffer[address+1];
         buffer[address] = buffer[address]<<pixels;
         for (byte x=0;x<pixels;x++) { buffer[address] += ((incomingchar & (128>>x)) >> (7-x))<<(pixels-x-1); };
         }
     }
  }
};
 
 
 
void shiftOut(byte row) { // fast routine to shove out 8 columns into two rows via board's shift registers
  for(byte column=0;column<8;column++) {
    byte index = column + (row<<3);  
    for(byte i=0;i<8;i++) {    
      PORTB &=~(3<<(data_R1-8));                                 // data_R2 is LOW; data_R1 is LOW;
      PORTB &=~(1<<(clockPin-8));                                // digitalWrite(clockPin,LOW);
      PORTB |= !((buffer[index]>>(7-i)) & 0x01<< (data_R1-8);  // top set of rows
      PORTB |= !((buffer[index+128]>>(7-i)) & 0x01<< (data_R2-8); // bottom set of rows
      PORTB |= 1<<(clockPin-8);                                  // digitalWrite(clockPin,HIGH);
    };
  };
};
 
ISR(TIMER2_COMPA_vect){  
     cli();
     digitalWrite(en_74138, HIGH);     // Turn off display
     shiftOut(ScanRow);                // Shift out 8 columns
     digitalWrite(latchPin, LOW);
     digitalWrite(latchPin, HIGH);
     PORTD = (ScanRow << 3| (PORTD & 0X87); // Highlight row: pins 3 4 5 6 (la_74138 lb_74138 lc_74138 ld_74138)
     digitalWrite(en_74138, LOW);     // Turn on display
     ScanRow++;                       // Do the next pair of rows next time this routine is called
     if (ScanRow==16) ScanRow=0;
     sei();
};
 
void setup() {
 
// Set up Timer2 as the scanning interrupt timer
  cli(); // clear interrupts
  TCCR2A = 0; TCCR2B = 0; TCNT2  = 0;
  TCCR2B |= (<< CS12) | (<< CS10);     // Set 1024 prescaler
               // 160Hz scan rate = 10 frames/second (16 pairs of rows)
  OCR2A = 97;  // 97 = (16,000,000 / (1024*160)) - 1
  TCCR2A |= (<< WGM21); TIMSK2 |= (<< OCIE2A);
  
  pinMode(latchPin,OUTPUT);  pinMode(clockPin,OUTPUT);
  pinMode(data_R1,OUTPUT);   pinMode(data_R2,OUTPUT);
    
  pinMode(en_74138,OUTPUT);
  pinMode(la_74138,OUTPUT);  pinMode(lb_74138,OUTPUT);
  pinMode(lc_74138,OUTPUT);  pinMode(ld_74138,OUTPUT);
  
  digitalWrite(en_74138, LOW);
  digitalWrite(data_R1, HIGH); digitalWrite(data_R2, HIGH);
  counter = millis();
  sei(); //allow interrupts
};
 
void loop() {  
static int count=0;
 
 
 
 
    
// display next character of message
    drawChar(56,16,message[count%(sizeof(message)-1)],0,false);
    count = (count + 1);
    // move the text 7 pixels (not 8 because it looks better) to the left
    for (byte i=0; i<4; i++) {
       delay(speed); //속도조절
       moveLeft(2,16,32);
    };
};
 
 
cs

* pgmspace.h: No such file or directory 에러가 뜨면 #include <pgmspace.h>를 지우고 

#include <avr/pgmspace.h>를 넣으세요

 

17,18번줄에 문구와 속도를 지정해주면 됩니다.

2번핀 : EN

3번핀 : LA

4번핀 : LB

5번핀 : LC

6번핀 : LD

8번핀 : LT

11번핀 : R1

12번핀: SK

 

 

 

 

'아두이노 > 활용' 카테고리의 다른 글

아두이노를 이용해서 릴레이제어하기  (0) 2023.11.26
아두이노로 RC카 만들기  (1) 2017.05.23