Skip to content

Instantly share code, notes, and snippets.

@LatvianModder
Created June 2, 2018 10:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save LatvianModder/cef49525b8bad23c4015c92aa6b94fd8 to your computer and use it in GitHub Desktop.
Save LatvianModder/cef49525b8bad23c4015c92aa6b94fd8 to your computer and use it in GitHub Desktop.
Code for Arduino to read data from serial and display it on a led strip
#include "FastLED.h"
#define NUM_LEDS 300
#define DATA_PIN 3
CRGB leds[NUM_LEDS];
void setup() {
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
FastLED.setTemperature(Tungsten100W);
FastLED.setBrightness(30);
for(int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB::Black;
}
FastLED.show();
Serial.begin(1000000);
delay(150);
Serial.println();
}
void loop()
{
while(Serial.available())
{
FastLED.setBrightness(slowRead());
for(int i = 0; i < NUM_LEDS; i++)
{
int r = slowRead();
int g = slowRead();
int b = slowRead();
if(r + g + b == 0)
{
leds[i] = CRGB::Black;
}
else
{
leds[i] = CRGB(r, g, b);
}
}
FastLED.show();
Serial.println();
}
}
int slowRead()
{
while(Serial.available() <= 0);
return Serial.read() & 0xFF;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment