-
Notifications
You must be signed in to change notification settings - Fork 0
/
LEDroutines.ino
50 lines (42 loc) · 1.04 KB
/
LEDroutines.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
void LedAllOff() {
digitalWrite(redPin, LOW);
digitalWrite(bluPin, LOW);
digitalWrite(grnPin, LOW);
}
void LedSet() {
analogWrite(redPin, redVal);
analogWrite(grnPin, grnVal);
analogWrite(bluPin, bluVal);
}
///////////////////////////////////////////////////////////////////////
void MQTTleds(char* topic, byte* payload, unsigned int msglength) {
String input;
input.reserve(4);
int ledVal = 0;
for (int i = 1; i < msglength; i++) { //decode comma delimited byte array... hopefully...
input.concat(String((char)payload[i]));
}
ledVal = input.toInt();
if (ledVal > 100) {
ledVal = 255;
}
if (topic[4] == 'R') {
redVal = ledVal * 4;
}
if (topic[4] == 'G') {
grnVal = ledVal * 4;
}
if (topic[4] == 'B') {
bluVal = ledVal * 4;
}
LedSet();
}
//////////////////////////////////////////////////////////////////////
void MQTTsetColour(char* topic, byte* payload, unsigned int msglength){
String input;
input.reserve(4);
if(msglength==6 && topic[0]==','){
for(int i=0;topic[i]==!',';i++){
}
}
}