Skip to content

Instantly share code, notes, and snippets.

@Keyes
Last active May 25, 2020 20:00
Show Gist options
  • Save Keyes/269de707a7ffa4b8c97c50e24a76e2cb to your computer and use it in GitHub Desktop.
Save Keyes/269de707a7ffa4b8c97c50e24a76e2cb to your computer and use it in GitHub Desktop.
//#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
// On a Trinket or Gemma we suggest changing this to 1:
#define LED_PIN 6
// How many NeoPixels are attached to the Arduino?
#define LED_COUNT 12
// Declare our NeoPixel strip object:
//Adafruit_NeoPixel strip(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
#define CHUNK_SIZE 25
int ledCounter = 0;
int chunkCounter = 1;
void sendReady() {
//Serial.flush();
//Serial.println();
Serial.print(1);
}
void setup() {
/*strip.begin(); // INITIALIZE NeoPixel strip object (REQUIRED)
strip.show(); // Turn OFF all pixels ASAP
strip.setBrightness(100); // Set BRIGHTNESS to about 1/5 (max = 255)
*/
Serial.begin(9600);
sendReady();
}
void loop() {
if (Serial.available()) {
//Serial.println("got value");
unsigned char buffer[3];
if (Serial.readBytes(buffer, 3) == 3) {
/*Serial.print("LED:");
Serial.print(ledCounter);
Serial.print("-RGB:");
Serial.print(buffer[0]);
Serial.print(",");
Serial.print(buffer[1]);
Serial.print(",");
Serial.print(buffer[2]);
Serial.println();*/
//strip.setPixelColor(ledCounter, strip.Color(buffer[0],buffer[1],buffer[2]));
ledCounter++;
if (ledCounter > chunkCounter * CHUNK_SIZE) {
chunkCounter++;
sendReady();
}
if (ledCounter > 150) {
//strip.show();
ledCounter = 0;
chunkCounter = 1;
}
} else {
Serial.println("ERROR, did not receive enough values");
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment