-
Notifications
You must be signed in to change notification settings - Fork 0
/
LEDMatrix8.h
172 lines (147 loc) · 5.66 KB
/
LEDMatrix8.h
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
/*
""" ############################################################################################ """
""" ############################################################################################ """
""" LED matrix (8*X) WS2812B control with Teensy4.0 """
""" V1_00 2021-12-26, Armin Rehberger """
""" Libary h-file """
""" ############################################################################################ """
""" ############################################################################################ """
*/
#ifndef LEDMatrix8_h
#define LEDMatrix8_h
#include <Arduino.h>
#define AMOUNTLINESLETTER 8 // Matrix height
#define AMOUNTCOLUMNLETTER 6 // Column per letter
#define INIT 0 // Value for initialize the scene
#define REDRAW 1 // Value for redraw the scene
// Colours
/*
#define RED 0xFF0000
#define GREEN 0x00FF00
#define BLUE 0x0000FF
#define YELLOW 0xFFFF00
#define PINK 0xFF1088
#define ORANGE 0xE05800
#define WHITE 0xFFFFFF
#define BACKGROUNDCOLUR 0x000001
*/
// Colours with less intense...
#define RED 0x160000
#define GREEN 0x001600
#define BLUE 0x000016
#define YELLOW 0x101400
#define PINK 0x120009
#define ORANGE 0x100400
#define WHITE 0x101010
#define BACKGROUNDCOLUR 0x000001
class LEDMatrix8
{
public:
// ##### Constructor (ctor)
//LEDMatrix8(const char inStringToDraw[][500], int inAmountOfPixelsDrawingArray= 0);
// Code of constructor here in LEDMatrix8.h, because of template to pass dynamic char array.
template< typename T, int X, int Y > // Template for LEDMatrix8
LEDMatrix8(T (&inStringToDraw)[X][Y], int inAmountOfPixelsDrawingArray, int inActiveStringNo)
{
// ##### Local variables
int AmountLetters;
int MinAmountDrawLetters;
int StringNo;
int i, j;
// ##### Copy values
AmountOfPixelsDrawingArray = inAmountOfPixelsDrawingArray; // ledsPerStrip * numPins e.g. 256*4 = 1024
AmountOfColumnMatrix = AmountOfPixelsDrawingArray / AMOUNTLINESLETTER; // e.g. 1024/8 = 128 column
// ##### Get amount of strings in the inStringToDraw char-array
AmountOfStrings = X;
// ##### Transfer active string no.
if(inActiveStringNo <= AmountOfStrings)
{
StringNo = inActiveStringNo;
}
else
{
StringNo = 0;
}
// ##### Check if string is to short for the matrix.
// If so, add spaces " "
MinAmountDrawLetters = (int)(((inAmountOfPixelsDrawingArray / AMOUNTLINESLETTER) / AMOUNTCOLUMNLETTER) +1);
for(i=0; i<AmountOfStrings; i++)
{
AmountLetters = strlen(inStringToDraw[i]);
if(AmountLetters < MinAmountDrawLetters)
{
for(j=AmountLetters; j<MinAmountDrawLetters; j++)
{
inStringToDraw[i][j] = ' ';
inStringToDraw[i][j+1] = '\0';
}
}
}
// ##### Fill Dynamic array with the stringlength, determine max. stringlength
StringlenStringToDraw = (int*)malloc(AmountOfStrings*sizeof(int));
MaxStringlength = 0;
for(i=0; i<AmountOfStrings; i++)
{
StringlenStringToDraw[i] = strlen(inStringToDraw[i]);
if(StringlenStringToDraw[i] > MaxStringlength)
{
MaxStringlength = StringlenStringToDraw[i]; // Global variable "MaxStringlength"
}
}
// ##### Create a copy of the input strings
StringToDraw = (char**)malloc(AmountOfStrings*sizeof(char*));
for(i=0; i<AmountOfStrings; i++)
{
StringToDraw[i] = (char*)malloc((MaxStringlength+1)*sizeof(char));
}
for(i=0; i<AmountOfStrings; i++)
{
for(j=0; j<(MaxStringlength+1); j++)
{
StringToDraw[i][j] = '\0';
}
}
for(i=0; i<AmountOfStrings; i++)
{
strcpy(StringToDraw[i], inStringToDraw[i]);
}
// ##### Initialize szene
InitSzene(INIT, StringNo);
}
// ##### Copy-Constructor (copy ctor)
// NA
// ##### Destructor (dtor)
// NA
// ##### Assignment operator
// NA
// ##### Public member methods
void InitSzene(int, int);
void ShiftDrawingArrayRight();
void ShiftDrawingArrayLeft();
void ShiftDrawingArrayUp();
void ShiftDrawingArrayDown();
void ColorScene0(int);
void ColorScene1(int);
void ColorScene2(int);
// ##### Public member variables (Attribute)
byte *DrawPixelArray; // One-dimensional array to be drawen. Needed to set the color of each pixel. Method setPixel in OctoWS2811
int *ColorPixel; // One-dimensional. This array can be used to set the color of each pixel
private:
// ##### Private member methods
void InitializeLetters(byte***, const char*, int);
void WriteLetterToDrawingMatrix(byte***, byte**, int);
void DrawingMatrixToDrawingArray(byte[], byte**, int);
// ##### Private member variables
int AmountOfPixelsDrawingArray;
int AmountOfColumnMatrix;
int AmountOfStrings;
int MaxStringlength;
int AmountOfPixelsCompleteString;
// ##### Private dynamic allocated arrays
byte ***drawingLetters; // Three-dimensional array for all letters (level), each letter has 8 line and 6 column (line vertical, column horizontal)
byte **drawingMatrix; // Two dimensional array for all letters, 8 lines and X columns (line vertical, column horizontal)
byte *drawingArray; // One-dimensional array with all the pixels of the string
int *StringlenStringToDraw; // One-dimensional array with the stringlength of the strings to be drawen
char **StringToDraw; // Two dimensional char array, copy of the input strings
};
#endif // LEDMatrix8_h