forked from Vasil-Pahomov/ArWs2812
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathanim_bt.cpp
51 lines (44 loc) · 1.06 KB
/
anim_bt.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
#include <SoftwareSerial.h>
#include "anim.h"
#include "color.h"
#include "palette.h"
#include "commands.h"
extern bool commandComplete;
extern byte command[];
//width of "spot" controlled by phone, in leds
#define SPOT_WIDTH 10
void Anim::animBT_SetUp() {
leds[10] = sparkleColor;
}
void Anim::animBT_Run() {
Color col;
int pos = -LEDS;
if (commandComplete && command[0] == CMD_MPOS) {
pos = command[1]*LEDS/256;
byte cin = command[2];
if (cin <= 63) {
col.r = cin*4;
col.g = (63-cin)*4;
col.b = 0;
} else if (cin <= 127) {
col.r = 255;
col.g = (cin - 64)*4;
col.b = col.g;
} else if (cin <= 191) {
col.r = (191 - cin) * 4;
col.g = col.r;
col.b = 255;
} else {
col.r = 0;
col.g = (cin - 192) * 4;
col.b = (255 - cin) * 4;
}
Serial.print('M');Serial.print(pos);Serial.print('-');Serial.println(cin);
}
for (int i=0;i<LEDS;i++) {
leds[i].fade(5);
if ( ((i-pos) >=0) && ((i-pos) < SPOT_WIDTH)) {
leds[i] = col;
}
}
}