arduino code for hardware

This commit is contained in:
Ryan Voots 2013-08-18 13:54:42 -07:00
parent cd7a6a99b2
commit 1c00d5220a

View 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
}
}