-
Notifications
You must be signed in to change notification settings - Fork 0
/
scroller.cpp
93 lines (73 loc) · 2.3 KB
/
scroller.cpp
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
#include "Arduino.h"
#include "PropFont.h"
#include "LedControl.h"
#define DISPLAYS 1
//returns false on abort
bool scroller(LedControl & lc, char *msg, int wait, int abort_pin1=0, int abort_pin2=0)
{
int curcharix = 0;
int curcharbit = 0;
int curcharixsave = 0;
int curcharbitsave = 0;
int curcharixsave2 = 0;
int curcharbitsave2 = 0;
char curchar;
int msgsize=strlen(msg);
int abort_state1=digitalRead(abort_pin1);
int abort_state2=digitalRead(abort_pin2);
int i,j,k;
while(abort_pin1==0 || abort_pin2==0 || (digitalRead(abort_pin1)==abort_state1 && digitalRead(abort_pin2)==abort_state2))
{
curcharixsave2 = curcharix;
curcharbitsave2 = curcharbit;
for (i=DISPLAYS-1;i>=0;i--) // Loop through our 1 display
{
for (j=0;j<8;j++) // Set up rows on current display
{
byte outputbyte = 0;
curchar = msg[curcharix];
curcharixsave = curcharix;
curcharbitsave = curcharbit;
for (k=7;k>=0;k--) // Copy over data for 8 columns to current row and send it to current display
{
// This byte is the bitmap of the current character for the current row
byte currentcharbits = pgm_read_byte(&Font8x5[((curchar-32)*8)+j]);
if (currentcharbits & (1<<curcharbit))
outputbyte |= (1<<k);
// advance the current character bit of current character
curcharbit ++;
if (curcharbit > pgm_read_byte(&lentbl_S[curchar-32])) // we are past the end of this character, so advance.
{
curcharbit = 0;
curcharix += 1;
if (curcharix+1 > msgsize) curcharix=0;
curchar = msg[curcharix];
}
}
lc.setColumn(i, 7-j, outputbyte);
if (j != 7) // if this is not the last row, roll back advancement, if it is, leave the counters advanced.
{
curcharix = curcharixsave;
curcharbit = curcharbitsave;
}
}
}
curcharix = curcharixsave2;
curcharbit = curcharbitsave2;
curchar = msg[curcharix];
// advance the current character bit of current character
curcharbit ++;
if (curcharbit > pgm_read_byte(&lentbl_S[curchar-32])) // we are past the end of this character, so advance.
{
curcharbit = 0;
curcharix += 1;
if (curcharix+1 >= msgsize) {
return(true);
}
curchar = msg[curcharix];
}
delay(wait);
}
lc.clearDisplay(0);
return(false);
}