-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathneopixelController.ino
More file actions
56 lines (43 loc) · 1.12 KB
/
neopixelController.ino
File metadata and controls
56 lines (43 loc) · 1.12 KB
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
#include <CmdMessenger.h> //CmdMessenger
#include <Adafruit_NeoPixel.h> // Adafruit NeoPixel
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN 7
// How many NeoPixels are attached to the Arduino?
#define NUMPIXELS 12
Adafruit_NeoPixel pixels = Adafruit_NeoPixel(NUMPIXELS, PIN, NEO_GRB + NEO_KHZ800);
CmdMessenger cmdMessenger = CmdMessenger(Serial);
enum
{
//Commands
kSetLed,
kChangeBrightness
};
void attachCommandCallbacks()
{
cmdMessenger.attach(kSetLed, setLed);
cmdMessenger.attach(kChangeBrightness, changeBrightness);
}
void setLed()
{
float ind = cmdMessenger.readFloatArg();
float r = cmdMessenger.readFloatArg();
float g = cmdMessenger.readFloatArg();
float b = cmdMessenger.readFloatArg();
pixels.setPixelColor(ind, pixels.Color(r,g,b));
pixels.show();
}
void changeBrightness()
{
float brightness = cmdMessenger.readFloatArg();
pixels.setBrightness(brightness);
pixels.show();
}
void setup(){
pixels.begin();
Serial.begin(115200);
cmdMessenger.printLfCr();
attachCommandCallbacks();
}
void loop(){
cmdMessenger.feedinSerialData();
}