Skip to content

Commit

Permalink
Merge pull request #26 from dmadison/development
Browse files Browse the repository at this point in the history
Version 2.0
  • Loading branch information
dmadison authored Sep 5, 2020
2 parents 9a380a5 + 55badee commit 1805bc1
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 83 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
language: C
env:
global:
- IDE_VERSION=1.8.1
- IDE_VERSION=1.8.13
matrix:
include:
- name: "WS2812B"
Expand All @@ -18,7 +18,7 @@ before_install:
- sudo ln -s /usr/local/share/arduino/arduino /usr/local/bin/arduino

# Install Libraries
- arduino --install-library "FastLED:3.2.0"
- arduino --install-library "FastLED:3.3.3"

# Sketch Compiling Functions
- CYAN="\033[36m"; YELLOW="\033[33m"; NOC="\033[0m";
Expand Down
123 changes: 49 additions & 74 deletions Arduino/LEDstream_FastLED/LEDstream_FastLED.ino
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/* LEDstream_FastLED
*
* Modified version of Adalight that uses the FastLED
* library (http://fastled.io) for driving led strips.
*
* http://github.com/dmadison/Adalight-FastLED
/*
* Project Adalight FastLED
* @author David Madison
* @link github.com/dmadison/Adalight-FastLED
* @license LGPL - Copyright (c) 2017 David Madison
*
* --------------------------------------------------------------------
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
Expand All @@ -18,36 +16,36 @@
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
* --------------------------------------------------------------------
*
*/

#include <Arduino.h>

// --- General Settings
static const uint16_t
Num_Leds = 80; // strip length
static const uint8_t
Brightness = 255; // maximum brightness
const uint16_t
Num_Leds = 80; // strip length
const uint8_t
Brightness = 255; // maximum brightness

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

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

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

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

// --------------------------------------------------------------------

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

static const uint8_t magic[] = {
const uint8_t magic[] = {
'A','d','a'};
#define MAGICSIZE sizeof(magic)

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

enum processModes_t {Header, Data} mode = Header;

static int16_t
c;
static uint16_t
outPos;
static uint32_t
bytesRemaining;
static unsigned long
t,
lastByteTime,
lastAckTime;

// Debug macros initialized
int16_t c; // current byte, must support -1 if no data available
uint16_t outPos; // current byte index in the LED array
uint32_t bytesRemaining; // count of bytes yet received, set by checksum
unsigned long t, lastByteTime, lastAckTime; // millisecond timestamps

void headerMode();
void dataMode();
void timeouts();

// Macros initialized
#ifdef SERIAL_FLUSH
#undef SERIAL_FLUSH
#define SERIAL_FLUSH while(Serial.available() > 0) { Serial.read(); }
#else
#define SERIAL_FLUSH
#endif

#ifdef DEBUG_LED
#define ON 1
#define OFF 0
Expand All @@ -109,11 +112,6 @@ static unsigned long
#endif

void setup(){
#ifdef GROUND_PIN
pinMode(GROUND_PIN, OUTPUT);
digitalWrite(GROUND_PIN, LOW);
#endif

#ifdef DEBUG_LED
pinMode(DEBUG_LED, OUTPUT);
digitalWrite(DEBUG_LED, LOW);
Expand All @@ -123,10 +121,12 @@ void setup(){
pinMode(DEBUG_FPS, OUTPUT);
#endif

#ifdef PIN_CLOCK
#if defined(PIN_CLOCK) && defined(PIN_DATA)
FastLED.addLeds<LED_TYPE, PIN_DATA, PIN_CLOCK, COLOR_ORDER>(leds, Num_Leds);
#else
#elif defined(PIN_DATA)
FastLED.addLeds<LED_TYPE, PIN_DATA, COLOR_ORDER>(leds, Num_Leds);
#else
#error "No LED output pins defined. Check your settings at the top."
#endif

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

void loop(){
adalight();
}

void adalight(){
void loop(){
t = millis(); // Save current time

// If there is new serial data
Expand Down Expand Up @@ -208,7 +204,7 @@ void headerMode(){
void dataMode(){
// If LED data is not full
if (outPos < sizeof(leds)){
dataSet();
ledsRaw[outPos++] = c; // Issue next byte
}
bytesRemaining--;

Expand All @@ -218,25 +214,10 @@ void dataMode(){
FastLED.show();
D_FPS;
D_LED(OFF);
#ifdef SERIAL_FLUSH
serialFlush();
#endif
SERIAL_FLUSH;
}
}

void dataSet(){
#ifdef CALIBRATE
if(outPos < 3)
ledsRaw[outPos++] = c;
else{
ledsRaw[outPos] = ledsRaw[outPos%3]; // Sets RGB data to first LED color
outPos++;
}
#else
ledsRaw[outPos++] = c; // Issue next byte
#endif
}

void timeouts(){
// No data received. If this persists, send an ACK packet
// to host once every second to alert it to our presence.
Expand All @@ -253,9 +234,3 @@ void timeouts(){
}
}
}

void serialFlush(){
while(Serial.available() > 0) {
Serial.read();
}
}
14 changes: 7 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@

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).

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

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.
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.

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/).
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/).

## Basic Setup

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

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.
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.

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).
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).

## Additional Settings

Expand All @@ -33,7 +33,7 @@ There are additional settings to allow for adjusting:
- Serial speed
- Serial timeout length

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.
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.

## Debug Settings

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

`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.

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

## Issues and LED-types

Expand Down

0 comments on commit 1805bc1

Please sign in to comment.