-
Notifications
You must be signed in to change notification settings - Fork 0
/
ctrl_chase.cpp
88 lines (79 loc) · 1.43 KB
/
ctrl_chase.cpp
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
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#include <unistd.h>
#include <time.h>
#include "ledcontrol.h"
int nsdelay = 2000000/60;
void fillinchase(float ir, int rgb)
{
int brightness;
int i;
int pos = (int)ir;
brightness = (ir - pos)*32;
for (i = 0; i < 4; i++) {
switch (rgb) {
case 1:
ledbuffer[pos].r = brightness;
break;
case 2:
ledbuffer[pos].g = brightness;
break;
case 0:
ledbuffer[pos].b = brightness;
break;
}
pos++;
if (pos > MAXLEDS)
pos = 0;
brightness += 48;
}
for (i = 0; i < 5; i++) {
switch (rgb) {
case 1:
ledbuffer[pos].r = brightness;
break;
case 2:
ledbuffer[pos].g = brightness;
break;
case 0:
ledbuffer[pos].b = brightness;
break;
}
pos++;
if (pos > MAXLEDS)
pos = 0;
brightness -= 48;
}
}
void ctrl_chase(int secs)
{
float ir = 0;
float ig = 0;
float igc = 0;
float ib = 0;
time_t start = time(NULL);
time_t now;
while (1) {
fillinchase(ir, 0);
fillinchase(ig, 1);
fillinchase(ib, 2);
flushbuffer();
ir += .1;
igc += .01;
ig = sin(igc) * (MAXLEDS/2) + MAXLEDS/2;
ib -= .1;
if (ir > MAXLEDS)
ir -= MAXLEDS;
if (ig > MAXLEDS)
ig -= MAXLEDS;
if (ib > MAXLEDS)
ib -= MAXLEDS;
if (ib < 0)
ib += MAXLEDS;
now = time(NULL);
if (start + secs < now)
break;
usleep(nsdelay);
}
}