-
Notifications
You must be signed in to change notification settings - Fork 0
/
ST2_Matrix.ino
95 lines (73 loc) · 3.33 KB
/
ST2_Matrix.ino
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
//*******************************************************************************************************************
// Called by Timer 1 Interrupt to draw next column in LED matrix
//*******************************************************************************************************************
// Only light one ROW (and one column) ie one pixel at a time. = lower current draw, but lower refresh rate.
void LEDupdateTWO() // ONE ROW of selected column at a time
{
if(ROWBITINDEX >6)
{
Mcolumn = Mcolumn+1; // Prep for next column
if(Mcolumn >19)
{
Mcolumn =0;
}
PORTB = (PORTB & B10000000); // Clear last column
PORTC = (PORTC & B11110000) | B00001111;
if(Mcolumn <16) // Matrix column (from 0 to 19)
{
PORTB = (PORTB & B01111111); //| (0<<PORTB7); // Decode digit Col. 1 to 16 - Select De-Mux chip
PORTD = (PORTD & B00001111) | (Mcolumn << 4); // Decode address to 74HC154
}
else
{
PORTB = (1<<PORTB7); // Decode digit Col. 17 to 20 - UN-Select De-Mux chip
PORTC = (PORTC & B11110000) | ~(1<<(Mcolumn-16)); // Using PC0 to PC4 to address col. 17 to 20 directly
}
ROWBITINDEX = 0;
}
else
{
PORTB = (PORTB & B10000000);
if(bitRead(LEDMAT[Mcolumn],ROWBITINDEX))
{
// PORTB = (PORTB & B10000000);
bitSet(PORTB,ROWBITINDEX);
}
if(Mcolumn <16) // Matrix column (from 0 to 19)
{
delayMicroseconds(120);
}
// else
// {
// bitClear(PORTB,ROWBITINDEX);
// }
ROWBITINDEX = ROWBITINDEX +1;
}
}
//*******************************************************************************************************************
// Called by Timer 1 Interrupt to draw next column in LED matrix
//*******************************************************************************************************************
// This version of LED refresh / drawing lights full column at once = higher current draw (but can be brighter)
void LEDupdate() // All ROWs of selected column at the same time
{
PORTB = (PORTB & B10000000); // Clear last column
PORTC = (PORTC & B11110000) | B00001111;
if(Mcolumn <16) // Matrix column (from 0 to 19)
{
PORTB = (PORTB & B01111111); //| (0<<PORTB7); // Decode digit Col. 1 to 16 - Select De-Mux chip
PORTD = (PORTD & B00001111) | (Mcolumn << 4); // Decode address to 74HC154
}
else
{
PORTB = (1<<PORTB7); // Decode digit Col. 17 to 20 - UN-Select De-Mux chip
PORTC = (PORTC & B11110000) | ~(1<<(Mcolumn-16)); // Using PC0 to PC4 to address col. 17 to 20 directly
}
// ---
PORTB = (PORTB & B10000000) | (LEDMAT[Mcolumn]); // Light LEDs - turn on ROWs
// ---
Mcolumn = Mcolumn+1; // Prep for next column
if(Mcolumn >19)
{
Mcolumn =0;
}
}