Created
June 2, 2018 10:06
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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