arduino code for hardware
This commit is contained in:
parent
cd7a6a99b2
commit
1c00d5220a
1 changed files with 58 additions and 0 deletions
58
arduino/strandtest_ws2811.ino
Normal file
58
arduino/strandtest_ws2811.ino
Normal file
|
@ -0,0 +1,58 @@
|
||||||
|
#include <Adafruit_NeoPixel.h>
|
||||||
|
|
||||||
|
#define PIN 8
|
||||||
|
|
||||||
|
// Parameter 1 = number of pixels in strip
|
||||||
|
// Parameter 2 = pin number (most are valid)
|
||||||
|
// Parameter 3 = pixel type flags, add together as needed:
|
||||||
|
// NEO_RGB Pixels are wired for RGB bitstream
|
||||||
|
// NEO_GRB Pixels are wired for GRB bitstream
|
||||||
|
// NEO_KHZ400 400 KHz bitstream (e.g. FLORA pixels)
|
||||||
|
// NEO_KHZ800 800 KHz bitstream (e.g. High Density LED strip)
|
||||||
|
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
|
||||||
|
|
||||||
|
uint8_t buff[5];
|
||||||
|
|
||||||
|
void setup() {
|
||||||
|
strip.begin();
|
||||||
|
strip.show(); // Initialize all pixels to 'off'
|
||||||
|
|
||||||
|
Serial.begin(9600);
|
||||||
|
}
|
||||||
|
|
||||||
|
void loop() {
|
||||||
|
// Some example procedures showing how to display to the pixels:
|
||||||
|
// colorSet(strip.Color(255, 192, 255), 1000); // Red
|
||||||
|
|
||||||
|
if (Serial.available() == 5) {
|
||||||
|
|
||||||
|
for (uint8_t i = 0; i < 5; i++) {
|
||||||
|
buff[i] = Serial.read();
|
||||||
|
Serial.println(buff[i], DEC);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (uint8_t p = 0; p < buff[1]; p++) {
|
||||||
|
strip.setPixelColor(p + buff[0], strip.Color(buff[2], buff[3], buff[4]));
|
||||||
|
}
|
||||||
|
|
||||||
|
strip.show();
|
||||||
|
} else if (Serial.available() > 5) {
|
||||||
|
uint8_t zc = 0;
|
||||||
|
while (Serial.available()) {
|
||||||
|
uint8_t r = Serial.read();
|
||||||
|
if (r == 0)
|
||||||
|
zc++;
|
||||||
|
else
|
||||||
|
zc = 0;
|
||||||
|
|
||||||
|
if (zc == 5)
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
// clear the buffer
|
||||||
|
while(Serial.available())
|
||||||
|
Serial.read();
|
||||||
|
|
||||||
|
delay(100); // wait 100 ms
|
||||||
|
}
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue