/*Boblight is a collection of tools for driving lights connected to an external controller.
https://code.google.com/p/boblight/
Its main purpose is to create light effects from an external input,
such as a video stream (desktop capture, video player, tv card), an audio stream (jack, alsa),
or user input (lirc, http). Currently it only handles video input by desktop capture with xlib,
video capture from v4l/v4l2 devices and user input from the commandline with boblight-constant.
Note: MS WINDOWS Dlink https://github.com/markhoney/RainbowBob/tree/master/boblight-1.3-beta1
prefix can only be 1 byte long in this boblight-1.3-beta1, TODO Fix this for Ms win.
*/
/* boblightd receiver for FastLED library , boblightd device type=momo, prefix FF 8F
Please edit bobligh.conf file prefix, this will work OK on linux, MS WIN. prefix can only be 1 byte long.
capable at least for 20Hz input stream if LED count <= 150
by TPertenava
last modified by Chris O. Aug.20.14
Tested on Arduino IDE 1.0.5
FastLED 2.1 https://github.com/FastLED/FastLED/tree/FastLED2.1
Arduino Leonardo & Teensy 3.1 with Teensyduino 1.19
*/
#include "FastLED.h" // FastLED is a fast, efficient, easy-to-use Arduino library for programming addressable LED strips and pixels such as
// WS2810, WS2811, LPD8806, Neopixel, TM1803 and more.
#define NUM_LEDS 40 // 4M LONG / LED count, well Radio Shack TM1803 IC count 10 per 1M.
#define CHANNELS NUM_LEDS*3 // each output for R, G and B
#define DATA_PIN 11 //teensy 3.1 //8 // arduino output pin
#define BRIGHTNESS 255 // maximum brightness
#define SPEED 115200 //57600 //115200 // virtual serial port speed, must be the same in boblight_config
//boolean ReadyLEDSbuffer = false;
byte values[NUM_LEDS][3]; // 2-level array, 1 level is for led number, 2 level is for rgb values
CRGB leds[NUM_LEDS];
void setup()
{
delay(2000); // sanity check delay - allows reprogramming if accidently blowing power w/leds
Serial.begin(SPEED);
LEDS.setBrightness(BRIGHTNESS);
// Uncomment/edit one of the following lines for your leds arrangement.
FastLED.addLeds<TM1803, DATA_PIN, GBR>(leds, NUM_LEDS); //TM1803 Radio Shack RGB Strip v2.0
// FastLED.addLeds<TM1803, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1804, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2811, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2812B, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<UCS1903B, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<GW6205_400, DATA_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<WS2801, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<SM16716, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// FastLED.addLeds<LPD8806, DATA_PIN, CLOCK_PIN, RGB>(leds, NUM_LEDS);
// Test leds on start up
// fade up
for(int x = 0; x < 128; x++) { //color PINK LOL.
// The showColor method sets all the leds in the strip to the same color
LEDS.showColor(CRGB(x, 0, x));
delay(10);
}
// fade down
for(int x = 128; x >= 0; x--) {
LEDS.showColor(CRGB(x,0, x));
delay(10);
}
}
void WaitForPrefix()
{
uint8_t first = 0, secondD = 0;
while (secondD != 0xFF || first != 0x8F) //FF 8F PREFIX
{
while (!Serial.available());
secondD = first;
first = Serial.read();
}
/* // if Prefix found set flag true
if (first == 0xFF && secondD == 0x8F)
{
ReadyLEDSbuffer = true; //set flag
}*/
}
void loop() {
WaitForPrefix(); //jump to WaitForPrefix();
for (byte Led = 0; Led < NUM_LEDS; Led++) {
for (byte Color = 0; Color < 3; Color++) {
while(!Serial.available());
values[Led][Color] = Serial.read();
}
}
for (byte Led = 0; Led < NUM_LEDS; Led++)
{
byte red = values[Led][0];
byte green = values[Led][1];
byte blue = values[Led][2];
leds[Led] = CRGB( red, green, blue);
}
LEDS.show();
/* if (ReadyLEDSbuffer == true) { // show leds only if buffer ready
LEDS.show();
ReadyLEDSbuffer = false; //set flag to false after LEDS.show();
}else{
LEDS.showColor(CRGB(50,50, 90));
}*/
}