-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathDisco.ino
95 lines (85 loc) · 2.01 KB
/
Disco.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
95
/*
enable/disable the disco mode (default = off)
*/
void disco() {
DiscoStatus = !DiscoStatus;
clearMatrix();
returnTo("/");
}
/*
draw the current disco-mode
*/
void draw_disco() {
Disco_Functions[DiscoState]();
}
/*
go to next disco mode
*/
void disco_toggle() {
DiscoState = (DiscoState + 1) % sizeof(Disco_Functions);
clearMatrix();
DiscoTmp = 0;
returnTo("/");
}
/*
random pixel beeing displayed
*/
void random_pixel() {
int addr = random(0, lc.getDeviceCount());
int index = random(0, 8);
int pos = random(0, 8);
int state = random(0, 2);
lc.setLed(addr, index, pos, state);
}
/*
cosine wave
*/
void cosine_wave() {
clearMatrix();
if (DiscoTmp == 32) {
DiscoTmp = 0;
}
for (int k = 0; k < lc.getDeviceCount(); k++) {
for (int i = 0; i < 8; i++) {
int x = (k * 8) + i;
int y = (int)(4 * cos((float)x * 0.3 + DiscoTmp) + 4 + 0.5);
for (int a = 0; a < y; a++) {
lc.setLed(k, a, 7 - i, true);
}
}
}
DiscoTmp++;
}
/*
waterworld
*/
byte fishes[1][8] = {
{B00010000, B00111000, B01000100, B01000100, B01000100, B00111000, B00010000, B00111000}, // medium fish
};
unsigned int WATERWORLD_SPEED = 200;
void waterworld() {
static unsigned long lastWaterworldDraw;
unsigned long currentDraw = millis();
if (currentDraw - lastWaterworldDraw >= WATERWORLD_SPEED || lastWaterworldDraw == 0) {
lastWaterworldDraw = currentDraw;
clearMatrix();
drawWaterWorld();
}
}
int iconPosition = 0;
void drawWaterWorld() {
int currentRow = 0;
iconPosition = iconPosition - 1;
if (iconPosition < -8) iconPosition = lc.getDeviceCount() * 8;
for (int k = 0; k < lc.getDeviceCount(); k++) {
for (int i = 0; i < 8; i++) {
currentRow++;
//currentRow is in the iconPosition Window
if (currentRow >= iconPosition && currentRow < (iconPosition + 8)) {
int rowInIconPosition = currentRow - iconPosition;
displayRow(k, i, fishes[0][rowInIconPosition]);
}
}
}
WATERWORLD_SPEED = random(100, 300);
}