From d42a83be455a502dd3cd7d17e8a53a2372dac4c5 Mon Sep 17 00:00:00 2001 From: David Madison Date: Wed, 3 May 2017 12:48:48 -0400 Subject: [PATCH] Cleaned up debug LED implementation Cleaner to use, and should be easier to add elsewhere in the future --- .../LEDstream_FastLED/LEDstream_FastLED.ino | 25 +++++++++++-------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/Arduino/LEDstream_FastLED/LEDstream_FastLED.ino b/Arduino/LEDstream_FastLED/LEDstream_FastLED.ino index aec1dad..f4c4d1b 100644 --- a/Arduino/LEDstream_FastLED/LEDstream_FastLED.ino +++ b/Arduino/LEDstream_FastLED/LEDstream_FastLED.ino @@ -27,8 +27,9 @@ static const unsigned long //#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 DEBUG_LED 13 // turns on the Arduino's built-in LED - // if the magic word + checksum match + +// --- Debug Settings (uncomment to add) +//#define DEBUG_LED 13 // toggles the Arduino's built-in LED on header match // -------------------------------------------------------------------- @@ -63,6 +64,16 @@ static const uint8_t magic[] = { #define MODE_HEADER 0 #define MODE_DATA 1 +// Debug statement initialized +#ifdef DEBUG_LED + #define ON 1 + #define OFF 0 + + #define D_LED(x) do {digitalWrite(DEBUG_LED, x);} while(0) +#else + #define D_LED(x) +#endif + void setup(){ #ifdef GROUND_PIN pinMode(GROUND_PIN, OUTPUT); @@ -143,10 +154,7 @@ void adalight(){ if(chk == (hi ^ lo ^ 0x55)) { // Checksum looks valid. Get 16-bit LED count, add 1 // (# LEDs is always > 0) and multiply by 3 for R,G,B. - #ifdef DEBUG_LED - digitalWrite(DEBUG_LED, HIGH); - #endif - + D_LED(ON); bytesRemaining = 3L * (256L * (long)hi + (long)lo + 1L); outPos = 0; memset(leds, 0, Num_Leds * sizeof(struct CRGB)); @@ -179,10 +187,7 @@ void adalight(){ // End of data -- issue latch: mode = MODE_HEADER; // Begin next header search FastLED.show(); - - #ifdef DEBUG_LED - digitalWrite(DEBUG_LED, LOW); - #endif + D_LED(OFF); } break; } // end switch