1
0
Fork 0
USBStrip/USBStrip/USBStrip.ino

46 lines
844 B
Arduino
Raw Normal View History

2015-12-16 14:12:34 +08:00
#include <WS2812.h>
#define LEDCount 37
2016-01-17 14:20:14 +08:00
#define outputPin 11
2015-12-16 14:12:34 +08:00
WS2812 LED(LEDCount);
cRGB value;
void setup() {
2016-01-17 14:20:14 +08:00
//Serial.begin(230400);
Serial.begin(115200);
2015-12-16 14:12:34 +08:00
LED.setOutput(outputPin);
}
void loop() {
2016-01-17 14:20:14 +08:00
if (Serial.available() > 0) {
byte command = Serial.read();
//Serial.write(command);
2015-12-16 14:12:34 +08:00
if (command == 0x11) {
LED.sync();
2016-01-17 14:20:14 +08:00
Serial.write(0x1a);
2015-12-16 14:12:34 +08:00
}
else if (command == 0x12) {
2016-01-17 14:20:14 +08:00
while (Serial.available() < 4) {
2015-12-16 14:12:34 +08:00
}
2016-01-17 14:20:14 +08:00
int pos = Serial.read();
value.r = Serial.read();
value.g = Serial.read();
value.b = Serial.read();
2015-12-16 14:12:34 +08:00
LED.set_crgb_at(pos, value);
2016-01-17 14:20:14 +08:00
//Serial.write(pos);
//Serial.write(value.r);
//Serial.write(value.g);
//Serial.write(value.b);
Serial.write(0x1b);
2015-12-16 14:12:34 +08:00
}
else {
2016-01-17 14:20:14 +08:00
Serial.write(0x1e);
2015-12-16 14:12:34 +08:00
}
}
}