forked from slawa19/IKEA-LED-Table
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstarsAnimation1.ino
63 lines (55 loc) · 1.41 KB
/
starsAnimation1.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
/* LedTable
*
* Written by: Klaas De Craemer, Ing. David Hrbaty
*
* Basic animation with fading stars
*/
#define NB_NEWSTARS 1
boolean starsRunning;
void initStars(){
starsRunning = true;
}
void runStars(){
initStars();
clearTablePixels();
showPixels();
unsigned long prevStarsCreationTime = 0;
unsigned long prevUpdateTime = 0;
unsigned long curTime = 0;
while(starsRunning){
dimLeds(0.97);
//Create new stars if enough time has passed since last time
curTime = millis();
if ((curTime - prevStarsCreationTime) > 1600){
for (int i=0; i<NB_NEWSTARS; i++){
boolean positionOk = false;
int n = 0;
//Generate random positions until valid
while (!positionOk){
n = random(FIELD_WIDTH*FIELD_HEIGHT);
if (getPixel(n) == 0)
positionOk = true;
}
// //Get random color
// if (random(2)==0)
// leds.setPixel(n,YELLOW);
// else
setPixel(n,BLUE);
}
prevStarsCreationTime = curTime;
}
showPixels();
//Check input keys
do{
readInput();
if (curControl == BTN_EXIT){
starsRunning = false;
break;
}
curTime = millis();
delay(10);
}
while ((curTime - prevUpdateTime) <80);//Once enough time has passed, proceed. The lower this number, the faster the game is
prevUpdateTime = curTime;
}
}