Skip to content

Commit 1805bc1

Browse files
authored
Merge pull request #26 from dmadison/development
Version 2.0
2 parents 9a380a5 + 55badee commit 1805bc1

3 files changed

Lines changed: 58 additions & 83 deletions

File tree

.travis.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
language: C
22
env:
33
global:
4-
- IDE_VERSION=1.8.1
4+
- IDE_VERSION=1.8.13
55
matrix:
66
include:
77
- name: "WS2812B"
@@ -18,7 +18,7 @@ before_install:
1818
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino
1919

2020
# Install Libraries
21-
- arduino --install-library "FastLED:3.2.0"
21+
- arduino --install-library "FastLED:3.3.3"
2222

2323
# Sketch Compiling Functions
2424
- CYAN="\033[36m"; YELLOW="\033[33m"; NOC="\033[0m";

Arduino/LEDstream_FastLED/LEDstream_FastLED.ino

Lines changed: 49 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
1-
/* LEDstream_FastLED
2-
*
3-
* Modified version of Adalight that uses the FastLED
4-
* library (http://fastled.io) for driving led strips.
5-
*
6-
* http://github.com/dmadison/Adalight-FastLED
1+
/*
2+
* Project Adalight FastLED
3+
* @author David Madison
4+
* @link github.com/dmadison/Adalight-FastLED
5+
* @license LGPL - Copyright (c) 2017 David Madison
76
*
8-
* --------------------------------------------------------------------
97
* This program is free software: you can redistribute it and/or modify
108
* it under the terms of the GNU Lesser General Public License as published by
119
* the Free Software Foundation, either version 3 of the License, or
@@ -18,36 +16,36 @@
1816
*
1917
* You should have received a copy of the GNU Lesser General Public License
2018
* along with this program. If not, see <http://www.gnu.org/licenses/>.
21-
* --------------------------------------------------------------------
19+
*
2220
*/
2321

22+
#include <Arduino.h>
23+
2424
// --- General Settings
25-
static const uint16_t
26-
Num_Leds = 80; // strip length
27-
static const uint8_t
28-
Brightness = 255; // maximum brightness
25+
const uint16_t
26+
Num_Leds = 80; // strip length
27+
const uint8_t
28+
Brightness = 255; // maximum brightness
2929

3030
// --- FastLED Setings
31-
#define LED_TYPE WS2812B // led strip type for FastLED
32-
#define COLOR_ORDER GRB // color order for bitbang
33-
#define PIN_DATA 6 // led data output pin
34-
//#define PIN_CLOCK 7 // led data clock pin (uncomment if you're using a 4-wire LED type)
31+
#define LED_TYPE WS2812B // led strip type for FastLED
32+
#define COLOR_ORDER GRB // color order for bitbang
33+
#define PIN_DATA 6 // led data output pin
34+
// #define PIN_CLOCK 7 // led data clock pin (uncomment if you're using a 4-wire LED type)
3535

3636
// --- Serial Settings
37-
static const unsigned long
38-
SerialSpeed = 115200; // serial port speed
39-
static const uint16_t
40-
SerialTimeout = 60; // time before LEDs are shut off if no data (in seconds), 0 to disable
37+
const unsigned long
38+
SerialSpeed = 115200; // serial port speed
39+
const uint16_t
40+
SerialTimeout = 60; // time before LEDs are shut off if no data (in seconds), 0 to disable
4141

4242
// --- Optional Settings (uncomment to add)
43-
#define SERIAL_FLUSH // Serial buffer cleared on LED latch
44-
//#define CLEAR_ON_START // LEDs are cleared on reset
45-
//#define GROUND_PIN 10 // additional grounding pin (optional)
46-
//#define CALIBRATE // sets all LEDs to the color of the first
43+
#define SERIAL_FLUSH // Serial buffer cleared on LED latch
44+
// #define CLEAR_ON_START // LEDs are cleared on reset
4745

4846
// --- Debug Settings (uncomment to add)
49-
//#define DEBUG_LED 13 // toggles the Arduino's built-in LED on header match
50-
//#define DEBUG_FPS 8 // enables a pulse on LED latch
47+
// #define DEBUG_LED 13 // toggles the Arduino's built-in LED on header match
48+
// #define DEBUG_FPS 8 // enables a pulse on LED latch
5149

5250
// --------------------------------------------------------------------
5351

@@ -70,7 +68,7 @@ uint8_t * ledsRaw = (uint8_t *)leds;
7068
// XOR 0x55). LED data follows, 3 bytes per LED, in order R, G, B,
7169
// where 0 = off and 255 = max brightness.
7270

73-
static const uint8_t magic[] = {
71+
const uint8_t magic[] = {
7472
'A','d','a'};
7573
#define MAGICSIZE sizeof(magic)
7674

@@ -81,18 +79,23 @@ static const uint8_t magic[] = {
8179

8280
enum processModes_t {Header, Data} mode = Header;
8381

84-
static int16_t
85-
c;
86-
static uint16_t
87-
outPos;
88-
static uint32_t
89-
bytesRemaining;
90-
static unsigned long
91-
t,
92-
lastByteTime,
93-
lastAckTime;
94-
95-
// Debug macros initialized
82+
int16_t c; // current byte, must support -1 if no data available
83+
uint16_t outPos; // current byte index in the LED array
84+
uint32_t bytesRemaining; // count of bytes yet received, set by checksum
85+
unsigned long t, lastByteTime, lastAckTime; // millisecond timestamps
86+
87+
void headerMode();
88+
void dataMode();
89+
void timeouts();
90+
91+
// Macros initialized
92+
#ifdef SERIAL_FLUSH
93+
#undef SERIAL_FLUSH
94+
#define SERIAL_FLUSH while(Serial.available() > 0) { Serial.read(); }
95+
#else
96+
#define SERIAL_FLUSH
97+
#endif
98+
9699
#ifdef DEBUG_LED
97100
#define ON 1
98101
#define OFF 0
@@ -109,11 +112,6 @@ static unsigned long
109112
#endif
110113

111114
void setup(){
112-
#ifdef GROUND_PIN
113-
pinMode(GROUND_PIN, OUTPUT);
114-
digitalWrite(GROUND_PIN, LOW);
115-
#endif
116-
117115
#ifdef DEBUG_LED
118116
pinMode(DEBUG_LED, OUTPUT);
119117
digitalWrite(DEBUG_LED, LOW);
@@ -123,10 +121,12 @@ void setup(){
123121
pinMode(DEBUG_FPS, OUTPUT);
124122
#endif
125123

126-
#ifdef PIN_CLOCK
124+
#if defined(PIN_CLOCK) && defined(PIN_DATA)
127125
FastLED.addLeds<LED_TYPE, PIN_DATA, PIN_CLOCK, COLOR_ORDER>(leds, Num_Leds);
128-
#else
126+
#elif defined(PIN_DATA)
129127
FastLED.addLeds<LED_TYPE, PIN_DATA, COLOR_ORDER>(leds, Num_Leds);
128+
#else
129+
#error "No LED output pins defined. Check your settings at the top."
130130
#endif
131131

132132
FastLED.setBrightness(Brightness);
@@ -141,11 +141,7 @@ void setup(){
141141
lastByteTime = lastAckTime = millis(); // Set initial counters
142142
}
143143

144-
void loop(){
145-
adalight();
146-
}
147-
148-
void adalight(){
144+
void loop(){
149145
t = millis(); // Save current time
150146

151147
// If there is new serial data
@@ -208,7 +204,7 @@ void headerMode(){
208204
void dataMode(){
209205
// If LED data is not full
210206
if (outPos < sizeof(leds)){
211-
dataSet();
207+
ledsRaw[outPos++] = c; // Issue next byte
212208
}
213209
bytesRemaining--;
214210

@@ -218,25 +214,10 @@ void dataMode(){
218214
FastLED.show();
219215
D_FPS;
220216
D_LED(OFF);
221-
#ifdef SERIAL_FLUSH
222-
serialFlush();
223-
#endif
217+
SERIAL_FLUSH;
224218
}
225219
}
226220

227-
void dataSet(){
228-
#ifdef CALIBRATE
229-
if(outPos < 3)
230-
ledsRaw[outPos++] = c;
231-
else{
232-
ledsRaw[outPos] = ledsRaw[outPos%3]; // Sets RGB data to first LED color
233-
outPos++;
234-
}
235-
#else
236-
ledsRaw[outPos++] = c; // Issue next byte
237-
#endif
238-
}
239-
240221
void timeouts(){
241222
// No data received. If this persists, send an ACK packet
242223
// to host once every second to alert it to our presence.
@@ -253,9 +234,3 @@ void timeouts(){
253234
}
254235
}
255236
}
256-
257-
void serialFlush(){
258-
while(Serial.available() > 0) {
259-
Serial.read();
260-
}
261-
}

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,11 @@
66

77
This project modifies the Adalight protocol 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).
88

9-
In addition to ambilight setups, the protocol can be used to stream *any* color data over serial from a computer to supported LED strips.
9+
In addition to ambilight setups, the protocol can be used to stream any color data over serial from a computer to supported LED strips.
1010

11-
For this sketch to work, you'll need to have a copy of the FastLED library. You can download FastLED [from GitHub](https://github.com/FastLED/FastLED) or through the libraries manager of the Arduino IDE. This program was writen using FastLED 3.1.3 - note that earlier versions of FastLED are untested and may not work properly.
11+
For this sketch to work, you'll need to have a copy of the FastLED library. You can download FastLED [from GitHub](https://github.com/FastLED/FastLED) or through the libraries manager of the Arduino IDE. This program was writen using FastLED 3 - note that earlier versions of FastLED are untested and may not work properly.
1212

13-
For more information on my own ambilight setup, see [the project page](http://www.partsnotincluded.com/projects/ambilight/) on [PartsNotIncluded.com](http://www.partsnotincluded.com/).
13+
For more information on my own ambilight setup, see [the project page](https://www.partsnotincluded.com/diy-ambilight-ws2812b/) on [PartsNotIncluded.com](http://www.partsnotincluded.com/).
1414

1515
## Basic Setup
1616

@@ -20,9 +20,9 @@ Open the LEDstream_FastLED file in the Arduino IDE and customize the settings at
2020
- LED data pin
2121
- LED type
2222

23-
If you are using a 4-wire LED chipset like APA102, you will need to uncomment the `PIN_CLOCK` line and set that as well.
23+
If you are using a 4-wire LED chipset like APA102 or SK9822, you will need to uncomment the `PIN_CLOCK` line and set that as well.
2424

25-
Upload to your Arduino and use a corresponding PC application to stream color data. You can get the Processing files from the [main Adalight repository](https://github.com/adafruit/Adalight), though I would recommend using [Patrick Siegler's](https://github.com/psieg/) fork of Lightpacks's Prismatik, which you can find [here](https://github.com/psieg/Lightpack/releases).
25+
Upload to your Arduino and use a corresponding PC application to stream color data. You can get the Processing files from the [main Adalight repository](https://github.com/adafruit/Adalight), though I would recommend using Patrick Siegler's fork of Lightpacks's Prismatik, which you can find [here](https://github.com/psieg/Lightpack/releases).
2626

2727
## Additional Settings
2828

@@ -33,7 +33,7 @@ There are additional settings to allow for adjusting:
3333
- Serial speed
3434
- Serial timeout length
3535

36-
There are also optional settings to clear the LEDs on reset, configure a dedicated ground pin, and to put the Arduino into a "calibration" mode, where all LED colors match the first LED. To help with flickering, the option to flush the serial buffer after every latch is enabled by default.
36+
There are also optional settings to clear the LEDs on reset or flush the incoming serial buffer after every latch. This latter option is enabled by default to help with flickering when using WS2812B LEDs.
3737

3838
## Debug Settings
3939

@@ -45,7 +45,7 @@ The code includes two debugging options:
4545

4646
`DEBUG_FPS`, similarly, will toggle a given pin when the LEDs latch. This is useful for measuring framerate with external hardware, like a logic analyzer.
4747

48-
To enable either of these settings, uncomment their respective '#define' lines.
48+
To enable either of these settings, uncomment their respective `#define` lines.
4949

5050
## Issues and LED-types
5151

0 commit comments

Comments
 (0)