Skip to content

Instantly share code, notes, and snippets.

@marmilicious
Created June 11, 2017 05:53
Show Gist options
  • Save marmilicious/bcd3ccf8d1f4c195c153fbe06b33828e to your computer and use it in GitHub Desktop.
Save marmilicious/bcd3ccf8d1f4c195c153fbe06b33828e to your computer and use it in GitHub Desktop.
//***************************************************************
// Untested code
// For reading R,G,B serial data sent from computer to LED controller.
//
//***************************************************************
//serial read of data to feed to FastLED
#include "FastLED.h"
//setup LEDs
#define NUM_LEDS 8
#define DATA_PIN 15
CRGB leds[NUM_LEDS];
//setup software serial buffer
char buff[NUM_LEDS*3];
int buffPos = 0;
char buffChar;
void setup ()
{
Serial.begin (115200);
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
}
void loop()
{
while (Serial.available() > 0) {
buffChar = Serial.read();
if (buffPos < NUM_LEDS*3) {
buff[buffPos] = buffChar;
buffPos++;
if (buffPos == (NUM_LEDS*3)) {
//clear leds and overwrite with buffer
memset(leds, 0, sizeof(leds));
memcpy(leds, buff, sizeof(leds));
//clear buffer and reset position
memset(buff, 0, sizeof(buff));
buffPos = 0;
}
}
}
//update LEDs
FastLED.show();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment