본문 바로가기

교육 자료/Raduino mini

8. Dot Matrix LED

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= {
  { 0x7F0x880x880x880x7F0x00}, //  A
  { 0xFF0x910x910x910x6E0x00}, //  B
  { 0x7E0x810x810x810x420x00}, //  C
  { 0xFF0x810x810x420x3C0x00}, //  D
  { 0xFF0x910x910x910x810x00}, //  E
  { 0xFF0x900x900x900x800x00}, //  F
  { 0x7E0x810x890x890x4E0x00}, //  G
  { 0xFF0x100x100x100xFF0x00}, //  H
  { 0x810x810xFF0x810x810x00}, //  I
  { 0x060x010x010x010xFE0x00}, //  J
  { 0xFF0x180x240x420x810x00}, //  K
  { 0xFF0x010x010x010x010x00}, //  L
  { 0xFF0x400x300x400xFF0x00}, //  M
  { 0xFF0x400x300x080xFF0x00}, //  N
  { 0x7E0x810x810x810x7E0x00}, //  O
  { 0xFF0x880x880x880x700x00}, //  P
  { 0x7E0x810x850x820x7D0x00}, //  Q
  { 0xFF0x880x8C0x8A0x710x00}, //  R
  { 0x610x910x910x910x8E0x00}, //  S
  { 0x800x800xFF0x800x800x00}, //  T
  { 0xFE0x010x010x010xFE0x00}, //  U
  { 0xF00x0C0x030x0C0xF00x00}, //  V
  { 0xFF0x020x0C0x020xFF0x00}, //  W
  { 0xC30x240x180x240xC30x00}, //  X
  { 0xE00x100x0F0x100xE00x00}, //  Y
  { 0x830x850x990xA10xC10x00}, //  Z
  { 0x060x290x290x290x1F0x00}, //  a
  { 0xFF0x090x110x110x0E0x00}, //  b
  { 0x1E0x210x210x210x120x00}, //  c
  { 0x0E0x110x110x090xFF0x00}, //  d
  { 0x0E0x150x150x150x0C0x00}, //  e
  { 0x080x7F0x880x800x400x00}, //  f
  { 0x300x490x490x490x7E0x00}, //  g
  { 0xFF0x080x100x100x0F0x00}, //  h
  { 0x000x000x5F0x000x000x00}, //  i
  { 0x020x010x210xBE0x000x00}, //  j
  { 0xFF0x040x0A0x110x000x00}, //  k
  { 0x000x810xFF0x010x000x00}, //  l
  { 0x3F0x200x180x200x1F0x00}, //  m
  { 0x3F0x100x200x200x1F0x00}, //  n
  { 0x0E0x110x110x110x0E0x00}, //  o
  { 0x3F0x240x240x240x180x00}, //  p
  { 0x100x280x280x180x3F0x00}, //  q
  { 0x1F0x080x100x100x080x00}, //  r
  { 0x090x150x150x150x020x00}, //  s
  { 0x200xFE0x210x010x020x00}, //  t
  { 0x1E0x010x010x020x1F0x00}, //  u
  { 0x1C0x020x010x020x1C0x00}, //  v
  { 0x1E0x010x0E0x010x1E0x00}, //  w
  { 0x110x0A0x040x0A0x110x00}, //  x
  { 0x000x390x050x050x3E0x00}, //  y
  { 0x110x130x150x190x110x00}, //  z
  { 0x000x410xFF0x010x000x00}, //  1
  { 0x430x850x890x910x610x00}, //  2
  { 0x420x810x910x910x6E0x00}, //  3
  { 0x180x280x480xFF0x080x00}, //  4
  { 0xF20x910x910x910x8E0x00}, //  5
  { 0x1E0x290x490x890x860x00}, //  6
  { 0x800x8F0x900xA00xC00x00}, //  7
  { 0x6E0x910x910x910x6E0x00}, //  8
  { 0x700x890x890x8A0x7C0x00}, //  9
  { 0x7E0x890x910xA10x7E0x00}, //  0
  { 0x600x800x8D0x900x600x00}, //  ?
  { 0x000x000xFD0x000x000x00}, //  !
  { 0x180x3C0x1E0x3C0x180x00}, // Heart(*)
  { 0x000x000x000x000x000x00}  // SPACE
};
 
// character to letter mapping
String letterPositions = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz1234567890?!* ";
 
// The database for the text to scroll
byte *textBytes;
int nrLetters = 0;
int columnPositions[8= { 1248163264128 };
 
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