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

View File

@ -1,29 +1,29 @@
## Synopsis ## 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 ## 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 - Number of LEDs
- LED data pin - LED data pin
- LED grounding pin (optional) - Max brightness
- Brightness - LED type
- LED color order
- Serial speed - Serial speed
- Serial timeout length - 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). 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 ## Issues and LED-types
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>
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 ## License