Merge pull request #4 from dmadison/generalize

Generalization
This commit is contained in:
David Madison 2016-12-21 14:39:41 -05:00 committed by GitHub
commit 93c85a8f3a
2 changed files with 53 additions and 30 deletions

View File

@ -1,18 +1,33 @@
// Slightly modified Adalight protocol implementation that uses FastLED
// library (http://fastled.io) for driving WS2811/WS2812 led strip
#include "FastLED.h"
/* LEDstream_FastLED
*
* Modified version of Adalight protocol that uses the FastLED
* library (http://fastled.io) for driving led strips.
*
* http://github.com/dmadison/Adalight-FastLED
* Last Updated: 2016-12-21
*/
// -- General Settings
#define NUM_LEDS 80 // strip length
#define LED_PIN 6 // Arduino data output pin
#define GROUND_PIN 10 // additional grounding pin (optional)
#define BRIGHTNESS 255 // maximum brightness
#define SPEED 115200 // serial port speed, max available
//#define CALIBRATE // uncomment to set calibration mode
// If no serial data is received for a while, the LEDs are shut off
// automatically. Value in milliseconds.
static const unsigned long serialTimeout = 150000; // 150 seconds
// --- FastLED Setings
#define LED_TYPE WS2812B // led strip type for FastLED
#define COLOR_ORDER GRB // color order for bitbang
// --- Serial Settings
#define SPEED 115200 // serial port speed, max available
static const unsigned long // time before LEDs are shut off, if no data
serialTimeout = 150000; // 150 seconds
// -- Optional Settings (uncomment to add)
//#define GROUND_PIN 10 // additional grounding pin (optional)
//#define CALIBRATE // sets all LEDs to the color of the first
// --------------------------------------------------------------------
#include <FastLED.h>
CRGB leds[NUM_LEDS];
uint8_t * ledsRaw = (uint8_t *)leds;
@ -39,18 +54,28 @@ static const uint8_t magic[] = {
#define MODE_HEADER 0
#define MODE_DATA 2
void setup()
{
void setup(){
#ifdef GROUND_PIN
pinMode(GROUND_PIN, OUTPUT);
digitalWrite(GROUND_PIN, LOW);
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
#endif
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
Serial.begin(SPEED);
adalight();
}
void adalight(){
// Dirty trick: the circular buffer for serial data is 256 bytes,
// and the "in" and "out" indices are unsigned 8-bit types -- this
// much simplifies the cases where in/out need to "wrap around" the
// beginning/end of the buffer. Otherwise there'd be a ton of bit-
// masking and/or conditional code every time one of these indices
// needs to change, slowing things down tremendously.
uint8_t
buffer[256],
indexIn = 0,
@ -69,8 +94,6 @@ void setup()
int32_t
outPos = 0;
Serial.begin(SPEED); // Teensy/32u4 disregards baud rate; is OK!
Serial.print("Ada\n"); // Send ACK string to host
lastByteTime = lastAckTime = millis();
@ -166,5 +189,5 @@ void setup()
void loop()
{
// Not used. See note in setup() function.
// Not used. See note in adalight() function.
}

View File

@ -1,29 +1,29 @@
## Synopsis
This is the standard Adalight library, modified to work with the FastLED library ([fastled.io](http://fastled.io)) and 3-pin WS2812B LED strips (2016-era Adafruit NeoPixels).
This is the Adalight library with the Arduino code modified to use [FastLED](https://github.com/FastLED/FastLED) ([fastled.io](http://fastled.io)). This expands Adalight to, in theory, work with [any supported FastLED strip](https://github.com/FastLED/FastLED/wiki/Chipset-reference) including WS2812B (aka Adafruit NeoPixels).
In addition to ambilight setups, the protocol can be used to stream any color data from a computer to a WS2812B strip (data rate limited by serial throughput).
In addition to ambilight setups, the protocol can be used to stream *any* color data from a computer to supported LED strips (data rate limited by serial throughput).
## Configuration
Open the WS2812B file in the Arduino IDE and edit the definitions at the top for your setup. Specifically:
Open the LEDstream_FastLED file in the Arduino IDE and edit the setting definitions at the top for your setup. These include:
- Number of LEDs
- LED data pin
- LED grounding pin (optional)
- Brightness
- Max brightness
- LED type
- LED color order
- Serial speed
- Serial timeout length
There are also optional settings to configure a dedicated ground pin and to put the Arduino into a "calibration" mode, where all LED colors match the first LED.
Upload to your Arduino and use a corresponding PC application to stream color data. The Processing files are included, though I would recommend using Patrick Siegler's (@psieg) fork of Lightpacks's Prismatik, which you can find [here](https://github.com/psieg/Lightpack).
## Tutorial
If you'd like you can follow Adafruit's tutorial, which is fairly comprehensive for the WS2801 they use but is otherwise out of date. You can find the tutorial here:
<https://learn.adafruit.com/adalight-diy-ambient-tv-lighting>
## Issues and LED-types
I've only tested the code with the WS2812B strips I have on hand, but so far it performs flawlessly. If you find an issue with the code or can confirm that it works with another chipset, please let me know!
## License