-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmatrix_rainbow.ino
62 lines (55 loc) · 1.39 KB
/
matrix_rainbow.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
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(8, 8, 6,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);
void setup() {
matrix.begin();
//matrix.setTextWrap(false);
matrix.setBrightness(80);
//matrix.setTextColor(colors[0]);
}
void loop() {
rainbow(10);
//matrix.fillScreen(matrix.Color(0, 255, 0));
//matrix.drawPixel(0,0, matrix.Color(32, 32, 32));
}
void drawRow(uint8_t row, uint16_t color) {
uint16_t i;
for(i=0; i<8; i++){
matrix.drawPixel(i,row,color);
}
}
void drawDiag(uint8_t row, uint16_t color) {
uint16_t i, j;
for(i=0; i<8; i++){
for(j=0; j<8; j++){
matrix.drawPixel(i,j,color);
}
}
}
void rainbow(uint8_t wait) {
uint16_t i, j;
for(j=0; j<256; j++) {
for(i=0; i<8; i++) {
drawRow(i, Wheel((i+j) & 255));
}
matrix.show();
delay(wait);
}
}
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return matrix.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
} else if(WheelPos < 170) {
WheelPos -= 85;
return matrix.Color(255 - WheelPos * 3, 0, WheelPos * 3);
} else {
WheelPos -= 170;
return matrix.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}