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
| static const int indices[] = { 0,4,8,12,16,19,22,26,30,33,37,42,45,52,59,63,67,71,75,79,82,86,91,96,101,106,111,116,121,126,131,136,141,146,151,156,161,163,165,167 };
static const unsigned char fontdata[] = { 63,72,72,63,127,73,73,54,62,65,65,34,127,65,65,62,127,73,65,127,72,64,62,65,69,39,127,8,8,127,65,127,65,2,1,1,126,127,8,20,34,65,127,1,1,63,64,64,60,64,64,63,127,32,16,8,4,2,127,127,65,65,127,127,72,72,48,62,65,71,62,127,72,76,51,50,73,73,38,64,127,64,126,1,1,126,112,12,3,12,112,126,1,15,1,126,65,54,8,54,65,96,16,15,16,96,67,69,73,81,97,62,69,73,81,62,17,33,127,1,1,71,73,73,73,49,65,65,73,73,54,24,40,72,127,8,121,73,73,73,6,62,73,73,73,6,65,66,68,72,112,54,73,73,73,54,48,73,73,73,62,3,3,123,123,27,27,127};
static int outputPins[] = { 12, 11, 10, 9, 8, 7, 6 };
static char text[] = "ANDREW";
void setup()
{
for (int i = 6; i<=12; ++i)
{
pinMode(i, OUTPUT);
digitalWrite(i, HIGH);
}
pinMode(13, OUTPUT);
digitalWrite(13, LOW);
delay(2000);
}
void loop()
{
byte row = 0;
byte endRow = 0;
char* currentChar = text;
while (1)
{
if (*currentChar == 0)
currentChar = text;
if ( row == endRow )
{
char t = *currentChar;
currentChar++;
t = t - 'A';
row = indices[t];
endRow = indices[t+1];
}
while (row != endRow)
{
byte mask = 64;
for (byte pin = 0; pin < (sizeof( outputPins) / sizeof(outputPins[0])); ++pin )
{
digitalWrite( outputPins[pin], (fontdata[row]&mask)? HIGH : LOW );
mask = mask / 2; // divide mask by two, moving it down one bit
}
row++;
delay(1);
}
for (byte pin = 0; pin < (sizeof( outputPins) / sizeof(outputPins[0])); ++pin )
{
digitalWrite( outputPins[pin], LOW);
}
delay(1);
}
} |