Merge pull request #6 from dmadison/development

Reworked header setting types
This commit is contained in:
David Madison 2017-03-27 15:42:05 -04:00 committed by GitHub
commit c28d784191
1 changed files with 28 additions and 21 deletions

View File

@ -4,24 +4,27 @@
* library (http://fastled.io) for driving led strips. * library (http://fastled.io) for driving led strips.
* *
* http://github.com/dmadison/Adalight-FastLED * http://github.com/dmadison/Adalight-FastLED
* Last Updated: 2016-12-21 * Last Updated: 2017-03-27
*/ */
// -- General Settings // --- General Settings
#define NUM_LEDS 80 // strip length static const uint8_t
#define LED_PIN 6 // Arduino data output pin Num_Leds = 80, // strip length
#define BRIGHTNESS 255 // maximum brightness Led_Pin = 6, // Arduino data output pin
Brightness = 255; // maximum brightness
// --- FastLED Setings // --- FastLED Setings
#define LED_TYPE WS2812B // led strip type for FastLED #define LED_TYPE WS2812B // led strip type for FastLED
#define COLOR_ORDER GRB // color order for bitbang #define COLOR_ORDER GRB // color order for bitbang
// --- Serial Settings // --- Serial Settings
#define SPEED 115200 // serial port speed, max available static const unsigned long
static const unsigned long // time before LEDs are shut off, if no data SerialSpeed = 115200, // serial port speed, max available
serialTimeout = 150000; // 150 seconds SerialTimeout = 150000; // time before LEDs are shut off, if no data
// (150 seconds)
// -- Optional Settings (uncomment to add) // --- Optional Settings (uncomment to add)
//#define CLEAR_ON_START // LEDs are cleared on reset
//#define GROUND_PIN 10 // additional grounding pin (optional) //#define GROUND_PIN 10 // additional grounding pin (optional)
//#define CALIBRATE // sets all LEDs to the color of the first //#define CALIBRATE // sets all LEDs to the color of the first
@ -29,7 +32,7 @@ static const unsigned long // time before LEDs are shut off, if no data
#include <FastLED.h> #include <FastLED.h>
CRGB leds[NUM_LEDS]; CRGB leds[Num_Leds];
uint8_t * ledsRaw = (uint8_t *)leds; uint8_t * ledsRaw = (uint8_t *)leds;
// A 'magic word' (along with LED count & checksum) precedes each block // A 'magic word' (along with LED count & checksum) precedes each block
@ -60,10 +63,14 @@ void setup(){
digitalWrite(GROUND_PIN, LOW); digitalWrite(GROUND_PIN, LOW);
#endif #endif
FastLED.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS); FastLED.addLeds<LED_TYPE, Led_Pin, COLOR_ORDER>(leds, Num_Leds);
FastLED.setBrightness(BRIGHTNESS); FastLED.setBrightness(Brightness);
Serial.begin(SPEED); #ifdef CLEAR_ON_START
FastLED.show();
#endif
Serial.begin(SerialSpeed);
adalight(); adalight();
} }
@ -83,16 +90,16 @@ void adalight(){
mode = MODE_HEADER, mode = MODE_HEADER,
hi, lo, chk, i; hi, lo, chk, i;
int16_t int16_t
bytesBuffered = 0,
c; c;
int32_t uint16_t
bytesRemaining; bytesBuffered = 0;
uint32_t
bytesRemaining,
outPos;
unsigned long unsigned long
lastByteTime, lastByteTime,
lastAckTime, lastAckTime,
t; t;
int32_t
outPos = 0;
Serial.print("Ada\n"); // Send ACK string to host Serial.print("Ada\n"); // Send ACK string to host
@ -119,8 +126,8 @@ void adalight(){
lastAckTime = t; // Reset counter lastAckTime = t; // Reset counter
} }
// If no data received for an extended time, turn off all LEDs. // If no data received for an extended time, turn off all LEDs.
if((t - lastByteTime) > serialTimeout) { if((t - lastByteTime) > SerialTimeout) {
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB)); //filling Led array by zeroes memset(leds, 0, Num_Leds * sizeof(struct CRGB)); //filling Led array by zeroes
FastLED.show(); FastLED.show();
lastByteTime = t; // Reset counter lastByteTime = t; // Reset counter
} }
@ -145,7 +152,7 @@ void adalight(){
bytesRemaining = 3L * (256L * (long)hi + (long)lo + 1L); bytesRemaining = 3L * (256L * (long)hi + (long)lo + 1L);
bytesBuffered -= 3; bytesBuffered -= 3;
outPos = 0; outPos = 0;
memset(leds, 0, NUM_LEDS * sizeof(struct CRGB)); memset(leds, 0, Num_Leds * sizeof(struct CRGB));
mode = MODE_DATA; // Proceed to latch wait mode mode = MODE_DATA; // Proceed to latch wait mode
} }
else { else {