diff --git a/AnalogBasicSetup.ino b/AnalogBasicSetup.ino index 127a73d..04aaef8 100644 --- a/AnalogBasicSetup.ino +++ b/AnalogBasicSetup.ino @@ -28,54 +28,62 @@ uint8_t hue; //--------------------------------------------------------------- void setup() { - delay(1500); - pinMode(REDPIN, OUTPUT); //setup pins for controlling analog RGB LED - pinMode(GREENPIN, OUTPUT); - pinMode(BLUEPIN, OUTPUT); - colorBars(); //display R,G,B color check during startup to confirm wiring + delay(1500); + pinMode(REDPIN, OUTPUT); //setup pins for controlling analog RGB LED + pinMode(GREENPIN, OUTPUT); + pinMode(BLUEPIN, OUTPUT); + colorBars(); //display R,G,B color check during startup to confirm wiring } //--------------------------------------------------------------- //Function to update the analog LED display -void showAnalogRGB( const CRGB& rgb) { - //Note: scale8 is used to adjust values based on BRIGHTNESS +void showAnalogRGB( const CRGB &rgb) { + //Note: scale8 is used to adjust values based on BRIGHTNESS - //Also note, I needed to update this to use 255 minus the rgb - //value since the LED I am using is common anode. If your - //analog RGB LED is common cathode you don't need the "255-" part. - analogWrite(REDPIN, 255-scale8(rgb.r, BRIGHTNESS) ); //for common anode - analogWrite(GREENPIN, 255-scale8(rgb.g, BRIGHTNESS) ); - analogWrite(BLUEPIN, 255-scale8(rgb.b, BRIGHTNESS) ); - //analogWrite(REDPIN, scale8(rgb.r, BRIGHTNESS) ); //for common cathode - //analogWrite(GREENPIN, scale8(rgb.g, BRIGHTNESS) ); - //analogWrite(BLUEPIN, scale8(rgb.b, BRIGHTNESS) ); + //Also note, I needed to update this to use 255 minus the rgb + //value since the LED I am using is common anode. If your + //analog RGB LED is common cathode you don't need the "255-" part. + analogWrite(REDPIN, 255 - scale8(rgb.r, BRIGHTNESS) ); //for common anode + analogWrite(GREENPIN, 255 - scale8(rgb.g, BRIGHTNESS) ); + analogWrite(BLUEPIN, 255 - scale8(rgb.b, BRIGHTNESS) ); + //analogWrite(REDPIN, scale8(rgb.r, BRIGHTNESS) ); //for common cathode + //analogWrite(GREENPIN, scale8(rgb.g, BRIGHTNESS) ); + //analogWrite(BLUEPIN, scale8(rgb.b, BRIGHTNESS) ); } //--------------------------------------------------------------- void loop() { - EVERY_N_MILLISECONDS(250) { //cycle through the rainbow - fill_rainbow( leds, 1, hue); - hue = hue + 5; - } + EVERY_N_MILLISECONDS(250) { //cycle through the rainbow + fill_rainbow( leds, 1, hue); + hue = hue + 5; + } - EVERY_N_MILLISECONDS(5) { //change the master brightness - static uint8_t delta = 1; - BRIGHTNESS = BRIGHTNESS - delta; - } - - showAnalogRGB( leds[0]); //update the LED display + EVERY_N_MILLISECONDS(5) { //change the master brightness + static uint8_t delta = 1; + BRIGHTNESS = BRIGHTNESS - delta; + } + + showAnalogRGB( leds[0]); //update the LED display }//end_main_loop //--------------------------------------------------------------- void colorBars() { - //This function is called once during startup to confirm the R,G,B wiring - fill_solid(leds,1,CRGB::Red); showAnalogRGB( leds[0] ); delay(1500); - fill_solid(leds,1,CRGB::Green); showAnalogRGB( leds[0] ); delay(1500); - fill_solid(leds,1,CRGB::Blue); showAnalogRGB( leds[0] ); delay(1500); - fill_solid(leds,1,CRGB::Black); showAnalogRGB( leds[0] ); delay(500); + //This function is called once during startup to confirm the R,G,B wiring + fill_solid(leds, 1, CRGB::Red); + showAnalogRGB( leds[0] ); + delay(1500); + fill_solid(leds, 1, CRGB::Green); + showAnalogRGB( leds[0] ); + delay(1500); + fill_solid(leds, 1, CRGB::Blue); + showAnalogRGB( leds[0] ); + delay(1500); + fill_solid(leds, 1, CRGB::Black); + showAnalogRGB( leds[0] ); + delay(500); } diff --git a/Blynk_Teensy32_USB_test.ino b/Blynk_Teensy32_USB_test.ino index 5bb0b5b..4d003b5 100644 --- a/Blynk_Teensy32_USB_test.ino +++ b/Blynk_Teensy32_USB_test.ino @@ -26,8 +26,14 @@ //--------------------------------------------------------------- -#include "FastLED.h" //include FastLED library -#define NUM_LEDS 32 // Number of pixels in strip +#include "FastLED.h" +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; void solid(); @@ -51,78 +57,76 @@ uint8_t zeRGBa[3]; //output: V2, zeRGBa data (set to "merge") boolean buttonA; //output: V3, button (set as "switch") uint8_t pattern; //output: V4, current pattern number -BLYNK_WRITE(V1) //slider value 0-255 -{ - sliderBrightness = param.asInt(); // assigning incoming value from pin V1 to a variable +BLYNK_WRITE(V1) { //slider value 0-255 + sliderBrightness = param.asInt(); // assigning incoming value from pin V1 to a variable } -BLYNK_WRITE(V2) //set as "merge" in zeRGBa widget -{ - zeRGBa[0] = param[0].asInt(); //red - zeRGBa[1] = param[1].asInt(); //green - zeRGBa[2] = param[2].asInt(); //blue +BLYNK_WRITE(V2) { //set as "merge" in zeRGBa widget + zeRGBa[0] = param[0].asInt(); //red + zeRGBa[1] = param[1].asInt(); //green + zeRGBa[2] = param[2].asInt(); //blue } -BLYNK_WRITE(V3) //toggles pixel display On/Off, set as "switch" -{ - buttonA = param.asInt(); //value is either 0 or 1 +BLYNK_WRITE(V3) { //toggles pixel display On/Off, set as "switch" + buttonA = param.asInt(); //value is either 0 or 1 } BLYNK_WRITE(V4) { - switch (param.asInt()) { + switch (param.asInt()) { case 1: { - pattern = 1; //rainbow - break; + pattern = 1; //rainbow + break; } case 2: { - pattern = 2; //juggle - break; + pattern = 2; //juggle + break; } case 3: { - pattern = 3; //sinelon (color selected by zeRGBa picker) - break; + pattern = 3; //sinelon (color selected by zeRGBa picker) + break; } case 4: { - pattern = 0; //solid (color selected by zeRGBa picker) - break; + pattern = 0; //solid (color selected by zeRGBa picker) + break; } default: - pattern = 0; //run if no pattern selected - } + pattern = 0; //run if no pattern selected + } } //--------------------------------------------------------------- -void setup() -{ - // Blynk will work through Serial - // Do not read or write this serial manually in your sketch - Serial.begin(9600); - Blynk.begin(Serial, auth); - - FastLED.addLeds(leds, NUM_LEDS); +void setup() { + // Blynk will work through Serial + // Do not read or write this serial manually in your sketch + Serial.begin(9600); + Blynk.begin(Serial, auth); + + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); } //--------------------------------------------------------------- -void loop() -{ - Blynk.run(); +void loop() { + Blynk.run(); - EVERY_N_MILLISECONDS(10) { - if (buttonA == 1) { //strip is ON. - gPatterns[pattern](); + EVERY_N_MILLISECONDS(10) { + if (buttonA == 1) { //strip is ON. + gPatterns[pattern](); - } else { //strip is OFF - FastLED.clear(); //blank out all pixel data - - } - - FastLED.setBrightness(sliderBrightness); - FastLED.show(); + } else { //strip is OFF + FastLED.clear(); //blank out all pixel data + + } - }//end_EVERY_N + FastLED.setBrightness(sliderBrightness); + FastLED.show(); - EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow + }//end_EVERY_N + + EVERY_N_MILLISECONDS( 20 ) { + gHue++; // slowly cycle the "base color" through the rainbow + } }//end_main_loop @@ -130,32 +134,29 @@ void loop() //--------------------------------------------------------------- // Patterns //--------------------------------------------------------------- -void rainbow() -{ - // FastLED's built-in rainbow generator - fill_rainbow( leds, NUM_LEDS, gHue, NUM_LEDS/8); +void rainbow() { + // FastLED's built-in rainbow generator + fill_rainbow( leds, NUM_LEDS, gHue, NUM_LEDS / 8); } void juggle() { - // four colored dots, weaving in and out of sync with each other - fadeToBlackBy( leds, NUM_LEDS, 20); - byte dothue = 0; - for( int i = 0; i < 4; i++) { - leds[beatsin16( i+5, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255); - dothue += 32; - } + // four colored dots, weaving in and out of sync with each other + fadeToBlackBy( leds, NUM_LEDS, 20); + byte dothue = 0; + for( int i = 0; i < 4; i++) { + leds[beatsin16( i + 5, 0, NUM_LEDS - 1 )] |= CHSV(dothue, 200, 255); + dothue += 32; + } } -void sinelon() -{ - // a colored dot sweeping back and forth, with fading trails - fadeToBlackBy( leds, NUM_LEDS, 12); - int pos = beatsin16( 13, 0, NUM_LEDS-1 ); - leds[pos] += CRGB(zeRGBa[0],zeRGBa[1],zeRGBa[2]); +void sinelon() { + // a colored dot sweeping back and forth, with fading trails + fadeToBlackBy( leds, NUM_LEDS, 12); + int pos = beatsin16( 13, 0, NUM_LEDS - 1 ); + leds[pos] += CRGB(zeRGBa[0], zeRGBa[1], zeRGBa[2]); } -void solid() -{ - // fill entire strip with a solid color - fill_solid(leds, NUM_LEDS, CRGB(zeRGBa[0],zeRGBa[1],zeRGBa[2]) ); +void solid() { + // fill entire strip with a solid color + fill_solid(leds, NUM_LEDS, CRGB(zeRGBa[0], zeRGBa[1], zeRGBa[2]) ); } diff --git a/CRGBSet_7segment_2digits.ino b/CRGBSet_7segment_2digits.ino index 993a6da..d2afa3c 100644 --- a/CRGBSet_7segment_2digits.ino +++ b/CRGBSet_7segment_2digits.ino @@ -16,113 +16,134 @@ //*************************************************************** #include "FastLED.h" +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 70 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + +/* CRGB leds[NUM_LEDS]; <--not using this. Using CRGBArray instead. */ +CRGBArray leds; -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE APA102 -#define COLOR_ORDER BGR -#define NUM_LEDS 70 -#define BRIGHTNESS 40 #define FRAMES_PER_SECOND 120 uint8_t pps = 5; // number of Pixels Per Segment -CHSV segON10(142,200,255); // color of 10s digit segments -CHSV segON(42,255,255); // color of 1s digit segments - -/* CRGB leds[NUM_LEDS]; <--not using this. Using CRGBArray instead. */ -CRGBArray leds; +CHSV segON10(142, 200, 255); // color of 10s digit segments +CHSV segON(42, 255, 255); // color of 1s digit segments // Name segments (based on layout in link above) and define pixel ranges. -CRGBSet segA( leds(pps*0, pps-1+(pps*0) )); -CRGBSet segB( leds(pps*1, pps-1+(pps*1) )); -CRGBSet segC( leds(pps*2, pps-1+(pps*2) )); -CRGBSet segD( leds(pps*3, pps-1+(pps*3) )); -CRGBSet segE( leds(pps*4, pps-1+(pps*4) )); -CRGBSet segF( leds(pps*5, pps-1+(pps*5) )); -CRGBSet segG( leds(pps*6, pps-1+(pps*6) )); +CRGBSet segA( leds(pps * 0, pps - 1 + (pps * 0) )); +CRGBSet segB( leds(pps * 1, pps - 1 + (pps * 1) )); +CRGBSet segC( leds(pps * 2, pps - 1 + (pps * 2) )); +CRGBSet segD( leds(pps * 3, pps - 1 + (pps * 3) )); +CRGBSet segE( leds(pps * 4, pps - 1 + (pps * 4) )); +CRGBSet segF( leds(pps * 5, pps - 1 + (pps * 5) )); +CRGBSet segG( leds(pps * 6, pps - 1 + (pps * 6) )); uint8_t count = 0; // keeps track of what number to display //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // 3 second delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); // Initially clear all pixels + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); // Initially clear all pixels } //--------------------------------------------------------------- -void loop() -{ - EVERY_N_MILLISECONDS(1000){ - setSegments(count); // Determine which segments are ON or OFF - count++; // Advance the count by one - if (count > 25) { count = 0; } // Reset count back to zero - } - FastLED.delay(1000/FRAMES_PER_SECOND); +void loop() { + EVERY_N_MILLISECONDS(1000) { + setSegments(count); // Determine which segments are ON or OFF + count++; // Advance the count by one + if (count > 25) { + count = 0; // Reset count back to zero + } + } + FastLED.delay(1000 / FRAMES_PER_SECOND); } //--------------------------------------------------------------- -void setSegments(uint8_t count){ - // Based on the current count set number segments on or off - uint8_t c1 = 0; // Variable to store 1s digit - uint8_t c10 = 0; // Variable to store 10s digit - uint8_t c; - CHSV segCOLOR(0,0,0); - - if (count > 9) { // Split out 1s and 10s digits if count is greater then 9 - c1 = count % 10; - c10 = count / 10; - } else { - c1 = count; - c10 = 0; - } - - //Serial.print("count = "); Serial.print(count); // Print to serial monitor current count - //Serial.print("\t 10s: "); Serial.print(c10); // Print 10s digit - //Serial.print(" 1s: "); Serial.println(c1); // Print 1s digit - - // Operate on 1s digit segments first, shift them over, and then do the 10s digit segments - for (uint8_t i=0; i < 2; i++) { - if (i == 0) { - c = c1; - segCOLOR = segON; +void setSegments(uint8_t count) { + // Based on the current count set number segments on or off + uint8_t c1 = 0; // Variable to store 1s digit + uint8_t c10 = 0; // Variable to store 10s digit + uint8_t c; + CHSV segCOLOR(0, 0, 0); + + if (count > 9) { // Split out 1s and 10s digits if count is greater then 9 + c1 = count % 10; + c10 = count / 10; } else { - c = c10; - segCOLOR = segON10; + c1 = count; + c10 = 0; } - segA = segB = segC = segD = segE = segF = segG = CRGB::Black; // Initially set segments off - - if (c == 0) { segB = segC = segD = segE = segF = segG = segCOLOR; } - if (c == 1) { segB = segG = segCOLOR; } - if (c == 2) { segA = segB = segC = segE = segF = segCOLOR; } - if (c == 3) { segA = segB = segC = segF = segG = segCOLOR; } - if (c == 4) { segA = segB = segD = segG = segCOLOR; } - if (c == 5) { segA = segC = segD = segF = segG = segCOLOR; } - if (c == 6) { segA = segC = segD = segE = segF = segG = segCOLOR; } - if (c == 7) { segB = segC = segG = segCOLOR; } - if (c == 8) { segA = segB = segC = segD = segE = segF = segG = segCOLOR; } - if (c == 9) { segA = segB = segC = segD = segF = segG = segCOLOR; } - - if (i == 0) { // Shift segments over to 1s digit display area - for (uint8_t p=0; p < (7*pps); p++) { - leds[p+(7*pps)] = leds[p]; - } - } + //Serial.print("count = "); Serial.print(count); // Print to serial monitor current count + //Serial.print("\t 10s: "); Serial.print(c10); // Print 10s digit + //Serial.print(" 1s: "); Serial.println(c1); // Print 1s digit + + // Operate on 1s digit segments first, shift them over, and then do the 10s digit segments + for (uint8_t i = 0; i < 2; i++) { + if (i == 0) { + c = c1; + segCOLOR = segON; + } else { + c = c10; + segCOLOR = segON10; + } + + segA = segB = segC = segD = segE = segF = segG = CRGB::Black; // Initially set segments off + + if (c == 0) { + segB = segC = segD = segE = segF = segG = segCOLOR; + } + if (c == 1) { + segB = segG = segCOLOR; + } + if (c == 2) { + segA = segB = segC = segE = segF = segCOLOR; + } + if (c == 3) { + segA = segB = segC = segF = segG = segCOLOR; + } + if (c == 4) { + segA = segB = segD = segG = segCOLOR; + } + if (c == 5) { + segA = segC = segD = segF = segG = segCOLOR; + } + if (c == 6) { + segA = segC = segD = segE = segF = segG = segCOLOR; + } + if (c == 7) { + segB = segC = segG = segCOLOR; + } + if (c == 8) { + segA = segB = segC = segD = segE = segF = segG = segCOLOR; + } + if (c == 9) { + segA = segB = segC = segD = segF = segG = segCOLOR; + } + + if (i == 0) { // Shift segments over to 1s digit display area + for (uint8_t p = 0; p < (7 * pps); p++) { + leds[p + (7 * pps)] = leds[p]; + } + } + + //----Comment this out if you want the 10s digit to display zeros---- + if (c10 == 0 && i == 1) { // If count is less then 10 set all 10s digit segments off + segA = segB = segC = segD = segE = segF = segG = CRGB::Black; + } + //------------------------------------------------------------------- - //----Comment this out if you want the 10s digit to display zeros---- - if (c10 == 0 && i == 1) { // If count is less then 10 set all 10s digit segments off - segA = segB = segC = segD = segE = segF = segG = CRGB::Black; } - //------------------------------------------------------------------- - - } }//end setSegments diff --git a/CRGBSet_7segment_3digits.ino b/CRGBSet_7segment_3digits.ino index a29eb79..d227550 100644 --- a/CRGBSet_7segment_3digits.ino +++ b/CRGBSet_7segment_3digits.ino @@ -16,126 +16,147 @@ //*************************************************************** #include "FastLED.h" +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 105 //35 per digit in this example (35 x 3 digits = 105) +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + +/* CRGB leds[NUM_LEDS]; <--not using this. Using CRGBArray instead. */ +CRGBArray leds; -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE APA102 -#define COLOR_ORDER BGR -#define NUM_LEDS 105 //35 per digit in this example (35 x 3 digits = 105) -#define BRIGHTNESS 40 #define FRAMES_PER_SECOND 120 uint8_t pps = 5; // number of Pixels Per Segment -CHSV segON100(96,200,255); // color of 100s digit segments -CHSV segON10(142,200,255); // color of 10s digit segments -CHSV segON(42,255,255); // color of 1s digit segments - -/* CRGB leds[NUM_LEDS]; <--not using this. Using CRGBArray instead. */ -CRGBArray leds; +CHSV segON100(96, 200, 255); // color of 100s digit segments +CHSV segON10(142, 200, 255); // color of 10s digit segments +CHSV segON(42, 255, 255); // color of 1s digit segments // Name segments (based on layout in link above) and define pixel ranges. -CRGBSet segA( leds(pps*0, pps-1+(pps*0) )); -CRGBSet segB( leds(pps*1, pps-1+(pps*1) )); -CRGBSet segC( leds(pps*2, pps-1+(pps*2) )); -CRGBSet segD( leds(pps*3, pps-1+(pps*3) )); -CRGBSet segE( leds(pps*4, pps-1+(pps*4) )); -CRGBSet segF( leds(pps*5, pps-1+(pps*5) )); -CRGBSet segG( leds(pps*6, pps-1+(pps*6) )); +CRGBSet segA( leds(pps * 0, pps - 1 + (pps * 0) )); +CRGBSet segB( leds(pps * 1, pps - 1 + (pps * 1) )); +CRGBSet segC( leds(pps * 2, pps - 1 + (pps * 2) )); +CRGBSet segD( leds(pps * 3, pps - 1 + (pps * 3) )); +CRGBSet segE( leds(pps * 4, pps - 1 + (pps * 4) )); +CRGBSet segF( leds(pps * 5, pps - 1 + (pps * 5) )); +CRGBSet segG( leds(pps * 6, pps - 1 + (pps * 6) )); uint8_t count = 0; // keeps track of what number to display //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // 3 second delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); // Initially clear all pixels + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); // Initially clear all pixels } //--------------------------------------------------------------- -void loop() -{ - EVERY_N_MILLISECONDS(250){ - setSegments(count); // Determine which segments are ON or OFF - count++; // Advance the count by one - if (count > 225) { count = 0; } // Reset count back to zero - } - FastLED.delay(1000/FRAMES_PER_SECOND); +void loop() { + EVERY_N_MILLISECONDS(250) { + setSegments(count); // Determine which segments are ON or OFF + count++; // Advance the count by one + if (count > 225) { + count = 0; // Reset count back to zero + } + } + FastLED.delay(1000 / FRAMES_PER_SECOND); } //--------------------------------------------------------------- -void setSegments(uint8_t count){ - // Based on the current count set number segments on or off - uint8_t c1 = 0; // Variable to store 1s digit - uint8_t c10 = 0; // Variable to store 10s digit - uint8_t c100 = 0; // Variable to store 100s digit - uint8_t c; - CHSV segCOLOR(0,0,0); - - c1 = count % 10; - c10 = (count / 10) % 10; - c100 = (count / 100) % 10; - - //Serial.print("count = "); Serial.print(count); // Print to serial monitor current count - //Serial.print("\t 100s: "); Serial.print(c100); // Print 100s digit - //Serial.print(" 10s: "); Serial.print(c10); // Print 10s digit - //Serial.print(" 1s: "); Serial.println(c1); // Print 1s digit - - // Operate on 1s digit segments first, shift them over, - // then 10's digit, and then do the 100s digit segments. - for (uint8_t i=0; i < 3; i++) { - if (i == 0) { - c = c1; - segCOLOR = segON; - } - if (i == 1) { - c = c10; - segCOLOR = segON10; - } - if (i == 2) { - c = c100; - segCOLOR = segON100; - } - - segA = segB = segC = segD = segE = segF = segG = CRGB::Black; // Initially set segments off - - if (c == 0) { segB = segC = segD = segE = segF = segG = segCOLOR; } - if (c == 1) { segB = segG = segCOLOR; } - if (c == 2) { segA = segB = segC = segE = segF = segCOLOR; } - if (c == 3) { segA = segB = segC = segF = segG = segCOLOR; } - if (c == 4) { segA = segB = segD = segG = segCOLOR; } - if (c == 5) { segA = segC = segD = segF = segG = segCOLOR; } - if (c == 6) { segA = segC = segD = segE = segF = segG = segCOLOR; } - if (c == 7) { segB = segC = segG = segCOLOR; } - if (c == 8) { segA = segB = segC = segD = segE = segF = segG = segCOLOR; } - if (c == 9) { segA = segB = segC = segD = segF = segG = segCOLOR; } - - if (i == 0) { // Shift segments over to 1s digit display area - for (uint8_t p=0; p < (7*pps); p++) { - leds[p+(2*7*pps)] = leds[p]; - } - } +void setSegments(uint8_t count) { + // Based on the current count set number segments on or off + uint8_t c1 = 0; // Variable to store 1s digit + uint8_t c10 = 0; // Variable to store 10s digit + uint8_t c100 = 0; // Variable to store 100s digit + uint8_t c; + CHSV segCOLOR(0, 0, 0); + + c1 = count % 10; + c10 = (count / 10) % 10; + c100 = (count / 100) % 10; + + //Serial.print("count = "); Serial.print(count); // Print to serial monitor current count + //Serial.print("\t 100s: "); Serial.print(c100); // Print 100s digit + //Serial.print(" 10s: "); Serial.print(c10); // Print 10s digit + //Serial.print(" 1s: "); Serial.println(c1); // Print 1s digit + + // Operate on 1s digit segments first, shift them over, + // then 10's digit, and then do the 100s digit segments. + for (uint8_t i = 0; i < 3; i++) { + if (i == 0) { + c = c1; + segCOLOR = segON; + } + if (i == 1) { + c = c10; + segCOLOR = segON10; + } + if (i == 2) { + c = c100; + segCOLOR = segON100; + } + + segA = segB = segC = segD = segE = segF = segG = CRGB::Black; // Initially set segments off + + if (c == 0) { + segB = segC = segD = segE = segF = segG = segCOLOR; + } + if (c == 1) { + segB = segG = segCOLOR; + } + if (c == 2) { + segA = segB = segC = segE = segF = segCOLOR; + } + if (c == 3) { + segA = segB = segC = segF = segG = segCOLOR; + } + if (c == 4) { + segA = segB = segD = segG = segCOLOR; + } + if (c == 5) { + segA = segC = segD = segF = segG = segCOLOR; + } + if (c == 6) { + segA = segC = segD = segE = segF = segG = segCOLOR; + } + if (c == 7) { + segB = segC = segG = segCOLOR; + } + if (c == 8) { + segA = segB = segC = segD = segE = segF = segG = segCOLOR; + } + if (c == 9) { + segA = segB = segC = segD = segF = segG = segCOLOR; + } + + if (i == 0) { // Shift segments over to 1s digit display area + for (uint8_t p = 0; p < (7 * pps); p++) { + leds[p + (2 * 7 * pps)] = leds[p]; + } + } + + if (i == 1) { // Shift segments over to 10s digit display area + for (uint8_t p = 0; p < (7 * pps); p++) { + leds[p + (7 * pps)] = leds[p + (7 * pps)]; + } + } + + //----Comment this out if you want the 100s and 10s digits to display zeros instead of being off---- + if (c10 == 0 && i == 1) { // If count is less then 10 set all 10s digit segments off + segA = segB = segC = segD = segE = segF = segG = CRGB::Black; + } + if (c100 == 0 && i == 2) { // If count is less then 100 set all 100s digit segments off + segA = segB = segC = segD = segE = segF = segG = CRGB::Black; + } + //------------------------------------------------------------------- - if (i == 1) { // Shift segments over to 10s digit display area - for (uint8_t p=0; p < (7*pps); p++) { - leds[p+(7*pps)] = leds[p+(7*pps)]; - } } - - //----Comment this out if you want the 100s and 10s digits to display zeros instead of being off---- - if (c10 == 0 && i == 1) { // If count is less then 10 set all 10s digit segments off - segA = segB = segC = segD = segE = segF = segG = CRGB::Black; - } - if (c100 == 0 && i == 2) { // If count is less then 100 set all 100s digit segments off - segA = segB = segC = segD = segE = segF = segG = CRGB::Black; - } - //------------------------------------------------------------------- - - } }//end setSegments diff --git a/CRGBSet_example.ino b/CRGBSet_example.ino index 176ab0c..baa814d 100644 --- a/CRGBSet_example.ino +++ b/CRGBSet_example.ino @@ -1,36 +1,41 @@ // Marc Miller, Jan 2016 #include "FastLED.h" -#define NUM_LEDS 32 - -//CRGB leds[NUM_LEDS]; // Not using this. Using CRGBArray instead. +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + +/* CRGB leds[NUM_LEDS]; <--not using this. Using CRGBArray instead. */ CRGBArray leds; -CRGBSet partA(leds(6,9)); // Define custom pixel range with a name. -CRGBSet partB(leds(22,25)); // Define custom pixel range with a name. +CRGBSet partA(leds(6, 9)); // Define custom pixel range with a name. +CRGBSet partB(leds(22, 25)); // Define custom pixel range with a name. -CHSV colorOne(0,222,255); // Define a custom color. -CHSV colorTwo(82,222,255); // Define a custom color. +CHSV colorOne(0, 222, 255); // Define a custom color. +CHSV colorTwo(82, 222, 255); // Define a custom color. //--------------------------------------------------------------- -void setup() { - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(255); +void setup() { + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- -void loop() -{ - fill_rainbow(leds, NUM_LEDS, millis()/10); // fill strip with moving rainbow. - leds.fadeToBlackBy(230); // fade the whole strip down some. - partA = colorOne; // set partA pixel color. - partB = colorTwo; // set partB pixel color. - FastLED.show(); - - EVERY_N_SECONDS(4){ // Swaps the two custom colors every four seconds. - CHSV temp = colorOne; - colorOne = colorTwo; - colorTwo = temp; - } +void loop() { + fill_rainbow(leds, NUM_LEDS, millis() / 10); // fill strip with moving rainbow. + leds.fadeToBlackBy(230); // fade the whole strip down some. + partA = colorOne; // set partA pixel color. + partB = colorTwo; // set partB pixel color. + FastLED.show(); + + EVERY_N_SECONDS(4) { // Swaps the two custom colors every four seconds. + CHSV temp = colorOne; + colorOne = colorTwo; + colorTwo = temp; + } } diff --git a/CRGBSet_example2.ino b/CRGBSet_example2.ino index bb8b003..87665c9 100644 --- a/CRGBSet_example2.ino +++ b/CRGBSet_example2.ino @@ -1,39 +1,44 @@ // Marc Miller, Oct 2017 #include "FastLED.h" -#define NUM_LEDS 32 - -//CRGB leds[NUM_LEDS]; // Not using this. Using CRGBArray instead. +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + +/* CRGB leds[NUM_LEDS]; <--not using this. Using CRGBArray instead. */ CRGBArray leds; -CRGBSet partA(leds(0,NUM_LEDS/2-1)); // First half of strip. -CRGBSet partB(leds(NUM_LEDS/2,NUM_LEDS-1)); // Second half of strip. +CRGBSet partA(leds(0, NUM_LEDS / 2 - 1)); // First half of strip. +CRGBSet partB(leds(NUM_LEDS / 2, NUM_LEDS - 1)); // Second half of strip. //--------------------------------------------------------------- -void setup() { - delay(500); - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(255); +void setup() { + delay(500); + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- -void loop() -{ - //Fill first half of strip with moving rainbow - fill_rainbow( partA, NUM_LEDS/2, millis()/20); - - - /*Three different ways to copy the data. - * The second two mirror the data. - * Uncomment one at a time to test out. */ - - //partB = partA; //creates dupicate copy in second half of strip - leds(NUM_LEDS-1,NUM_LEDS/2) = partA; //creates mirrored copy in second half of strip - //partB = leds(NUM_LEDS/2-1,0); //creates mirrored copy in second half of strip - - - FastLED.show(); - delay(2); +void loop() { + //Fill first half of strip with moving rainbow + fill_rainbow( partA, NUM_LEDS / 2, millis() / 20); + + + /*Three different ways to copy the data. + * The second two mirror the data. + * Uncomment one at a time to test out. */ + + //partB = partA; //creates dupicate copy in second half of strip + leds(NUM_LEDS - 1, NUM_LEDS / 2) = partA; //creates mirrored copy in second half of strip + //partB = leds(NUM_LEDS/2-1,0); //creates mirrored copy in second half of strip + + + FastLED.show(); + delay(2); } diff --git a/DemoReel100_ChristmasSparkles.ino b/DemoReel100_ChristmasSparkles.ino index 9b7097c..e205682 100644 --- a/DemoReel100_ChristmasSparkles.ino +++ b/DemoReel100_ChristmasSparkles.ino @@ -9,18 +9,16 @@ //*************************************************************** #include "FastLED.h" -FASTLED_USING_NAMESPACE +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 -#define DATA_PIN 11 -#define CLK_PIN 13 - -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 +CRGB leds[NUM_LEDS]; -#define BRIGHTNESS 255 #define FRAMES_PER_SECOND 120 -CRGB leds[NUM_LEDS]; uint16_t ledsData[NUM_LEDS][4]; // array to store color data and an extra value uint16_t pick; // stores a temporary pixel number @@ -28,11 +26,11 @@ uint16_t pick; // stores a temporary pixel number //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // 3 second delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- @@ -46,23 +44,24 @@ uint8_t gHue = 0; // rotating "base color" used by many of the patterns //--------------------------------------------------------------- void loop() { - // Call the current pattern function once, updating the 'leds' array - gPatterns[gCurrentPatternNumber](); + // Call the current pattern function once, updating the 'leds' array + gPatterns[gCurrentPatternNumber](); - //FastLED.show(); - FastLED.delay(1000/FRAMES_PER_SECOND); // slows the framerate to a modest value + //FastLED.show(); + FastLED.delay(1000 / FRAMES_PER_SECOND); // slows the framerate to a modest value - // do some periodic updates - EVERY_N_SECONDS( 20 ) { nextPattern(); } // change patterns periodically + // do some periodic updates + EVERY_N_SECONDS( 20 ) { + nextPattern(); // change patterns periodically + } } //--------------------------------------------------------------- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) -void nextPattern() -{ - // add one to the current pattern number, and wrap around at the end - gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns); +void nextPattern() { + // add one to the current pattern number, and wrap around at the end + gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns); } @@ -72,140 +71,146 @@ void nextPattern() //=============================================================== //--------------------------------------------------------------- void christmasSparkles() { - //"Background" color for non-sparkling pixels. - CRGB sparkleBgColor = CHSV(50, 30, 40); // dim white - //CRGB sparkleBgColor = CHSV(96, 200, 30); // dim green - - EVERY_N_MILLISECONDS(40){ - if( random8() < 60 ) { // How much to sparkle! Higher number is more. - pick = random16(NUM_LEDS); - if (ledsData[pick][3] == 0 ) { - ledsData[pick][3] = 35; // Used to tag pixel as sparkling - uint8_t randomPick = random8(5); - if (randomPick == 0) { - ledsData[pick][0] = 178; // sparkle hue (blue) - ledsData[pick][1] = 244; // sparkle saturation - ledsData[pick][2] = 210; // sparkle value - } - if (randomPick == 1) { - ledsData[pick][0] = 10; // sparkle hue (red) - ledsData[pick][1] = 255; // sparkle saturation - ledsData[pick][2] = 240; // sparkle value - } - if (randomPick == 2) { - ledsData[pick][0] = 0; // sparkle hue (white-ish) - ledsData[pick][1] = 25; // sparkle saturation - ledsData[pick][2] = 255; // sparkle value + //"Background" color for non-sparkling pixels. + CRGB sparkleBgColor = CHSV(50, 30, 40); // dim white + //CRGB sparkleBgColor = CHSV(96, 200, 30); // dim green + + EVERY_N_MILLISECONDS(40) { + if( random8() < 60 ) { // How much to sparkle! Higher number is more. + pick = random16(NUM_LEDS); + if (ledsData[pick][3] == 0 ) { + ledsData[pick][3] = 35; // Used to tag pixel as sparkling + uint8_t randomPick = random8(5); + if (randomPick == 0) { + ledsData[pick][0] = 178; // sparkle hue (blue) + ledsData[pick][1] = 244; // sparkle saturation + ledsData[pick][2] = 210; // sparkle value + } + if (randomPick == 1) { + ledsData[pick][0] = 10; // sparkle hue (red) + ledsData[pick][1] = 255; // sparkle saturation + ledsData[pick][2] = 240; // sparkle value + } + if (randomPick == 2) { + ledsData[pick][0] = 0; // sparkle hue (white-ish) + ledsData[pick][1] = 25; // sparkle saturation + ledsData[pick][2] = 255; // sparkle value + } + if (randomPick == 3) { + ledsData[pick][0] = 35; // sparkle hue (orange) + ledsData[pick][1] = 235; // sparkle saturation + ledsData[pick][2] = 245; // sparkle value + } + if (randomPick == 4) { + ledsData[pick][0] = 190; // sparkle hue (purple) + ledsData[pick][1] = 255; // sparkle saturation + ledsData[pick][2] = 238; // sparkle value + } + leds[pick] = CHSV(ledsData[pick][0], ledsData[pick][1], ledsData[pick][2]); + } } - if (randomPick == 3) { - ledsData[pick][0] = 35; // sparkle hue (orange) - ledsData[pick][1] = 235; // sparkle saturation - ledsData[pick][2] = 245; // sparkle value + for (uint16_t i = 0; i < NUM_LEDS; i++) { + if (ledsData[i][3] == 0) { // if not sparkling, set to "back ground" color + leds[i] = sparkleBgColor; + } else { + CHSV hsv = rgb2hsv_approximate(leds[i]); // Used to get approximate Hue + EVERY_N_MILLISECONDS(38) { + ledsData[i][0] = hsv.hue - 1; // slightly shift hue + } + ledsData[i][2] = scale8(ledsData[i][2], 245); // slowly darken + leds[i] = CHSV(ledsData[i][0], ledsData[i][1], ledsData[i][2]); + ledsData[i][3] = ledsData[i][3] - 1; // countdown sparkle tag + } } - if (randomPick == 4) { - ledsData[pick][0] = 190; // sparkle hue (purple) - ledsData[pick][1] = 255; // sparkle saturation - ledsData[pick][2] = 238; // sparkle value - } - leds[pick] = CHSV(ledsData[pick][0], ledsData[pick][1], ledsData[pick][2]); - } - } - for (uint16_t i=0; i < NUM_LEDS; i++) { - if (ledsData[i][3] == 0) { // if not sparkling, set to "back ground" color - leds[i] = sparkleBgColor; - } else { - CHSV hsv = rgb2hsv_approximate(leds[i]); // Used to get approximate Hue - EVERY_N_MILLISECONDS(38) { ledsData[i][0] = hsv.hue - 1; } // slightly shift hue - ledsData[i][2] = scale8(ledsData[i][2], 245); // slowly darken - leds[i] = CHSV(ledsData[i][0], ledsData[i][1], ledsData[i][2]); - ledsData[i][3] = ledsData[i][3] - 1; // countdown sparkle tag - } } - } }//end christmasSparkles //--------------------------------------------------------------- void christmasSparklesRG() { // Red and Green only - //"Background" color for non-sparkling pixels. Can be set to black for no bg color. - CRGB sparkleBgColor = CHSV(0, 0, 0); // black - //CRGB sparkleBgColor = CHSV(50, 30, 30); // dim white - - EVERY_N_MILLISECONDS(40){ - if( random8() < 110 ) { // How much to sparkle! Higher number is more. - pick = random16(NUM_LEDS); - if (ledsData[pick][3] == 0 ) { - ledsData[pick][3] = 65; // Used to tag pixel as sparkling - uint8_t randomPick = random8(2); - if (randomPick == 0) { - ledsData[pick][0] = 16; // sparkle hue (red) - ledsData[pick][1] = 253; // sparkle saturation - ledsData[pick][2] = 242; // sparkle value + //"Background" color for non-sparkling pixels. Can be set to black for no bg color. + CRGB sparkleBgColor = CHSV(0, 0, 0); // black + //CRGB sparkleBgColor = CHSV(50, 30, 30); // dim white + + EVERY_N_MILLISECONDS(40) { + if( random8() < 110 ) { // How much to sparkle! Higher number is more. + pick = random16(NUM_LEDS); + if (ledsData[pick][3] == 0 ) { + ledsData[pick][3] = 65; // Used to tag pixel as sparkling + uint8_t randomPick = random8(2); + if (randomPick == 0) { + ledsData[pick][0] = 16; // sparkle hue (red) + ledsData[pick][1] = 253; // sparkle saturation + ledsData[pick][2] = 242; // sparkle value + } + if (randomPick == 1) { + ledsData[pick][0] = 96; // sparkle hue (green) + ledsData[pick][1] = 230; // sparkle saturation + ledsData[pick][2] = 255; // sparkle value + } + leds[pick] = CHSV(ledsData[pick][0], ledsData[pick][1], ledsData[pick][2]); + } } - if (randomPick == 1) { - ledsData[pick][0] = 96; // sparkle hue (green) - ledsData[pick][1] = 230; // sparkle saturation - ledsData[pick][2] = 255; // sparkle value + for (uint16_t i = 0; i < NUM_LEDS; i++) { + if (ledsData[i][3] == 0) { // if not sparkling, set to "back ground" color + leds[i] = sparkleBgColor; + } else { + CHSV hsv = rgb2hsv_approximate(leds[i]); // Used to get approximate Hue + EVERY_N_MILLISECONDS(50) { + ledsData[i][0] = hsv.hue - 1; // slightly shift hue + } + ledsData[i][2] = scale8(ledsData[i][2], 253); // slowly darken + leds[i] = CHSV(ledsData[i][0], ledsData[i][1], ledsData[i][2]); + ledsData[i][3] = ledsData[i][3] - 1; // countdown sparkle tag + } } - leds[pick] = CHSV(ledsData[pick][0], ledsData[pick][1], ledsData[pick][2]); - } - } - for (uint16_t i=0; i < NUM_LEDS; i++) { - if (ledsData[i][3] == 0) { // if not sparkling, set to "back ground" color - leds[i] = sparkleBgColor; - } else { - CHSV hsv = rgb2hsv_approximate(leds[i]); // Used to get approximate Hue - EVERY_N_MILLISECONDS(50) { ledsData[i][0] = hsv.hue - 1; } // slightly shift hue - ledsData[i][2] = scale8(ledsData[i][2], 253); // slowly darken - leds[i] = CHSV(ledsData[i][0], ledsData[i][1], ledsData[i][2]); - ledsData[i][3] = ledsData[i][3] - 1; // countdown sparkle tag - } } - } }//end christmasSparklesRG //--------------------------------------------------------------- void christmasSparklesBP() { // Blues and Purple only - //"Background" color for non-sparkling pixels. - CRGB sparkleBgColor = CHSV(96, 185, 30); // green - - EVERY_N_MILLISECONDS(40){ - if( random8() < 170 ) { // How much to sparkle! Higher number is more. - pick = random16(NUM_LEDS); - if (ledsData[pick][3] == 0 ) { - ledsData[pick][3] = 20; // Used to tag pixel as sparkling - uint8_t randomPick = random8(3); - if (randomPick == 0) { - ledsData[pick][0] = 165; // sparkle hue (blue) - ledsData[pick][1] = 180; // sparkle saturation - ledsData[pick][2] = 230; // sparkle value + //"Background" color for non-sparkling pixels. + CRGB sparkleBgColor = CHSV(96, 185, 30); // green + + EVERY_N_MILLISECONDS(40) { + if( random8() < 170 ) { // How much to sparkle! Higher number is more. + pick = random16(NUM_LEDS); + if (ledsData[pick][3] == 0 ) { + ledsData[pick][3] = 20; // Used to tag pixel as sparkling + uint8_t randomPick = random8(3); + if (randomPick == 0) { + ledsData[pick][0] = 165; // sparkle hue (blue) + ledsData[pick][1] = 180; // sparkle saturation + ledsData[pick][2] = 230; // sparkle value + } + if (randomPick == 1) { + ledsData[pick][0] = 200; // sparkle hue (pink-light-purple) + ledsData[pick][1] = 170; // sparkle saturation + ledsData[pick][2] = 240; // sparkle value + } + if (randomPick == 2) { + ledsData[pick][0] = 130; // sparkle hue (light blue) + ledsData[pick][1] = 200; // sparkle saturation + ledsData[pick][2] = 255; // sparkle value + } + leds[pick] = CHSV(ledsData[pick][0], ledsData[pick][1], ledsData[pick][2]); + } } - if (randomPick == 1) { - ledsData[pick][0] = 200; // sparkle hue (pink-light-purple) - ledsData[pick][1] = 170; // sparkle saturation - ledsData[pick][2] = 240; // sparkle value + for (uint16_t i = 0; i < NUM_LEDS; i++) { + if (ledsData[i][3] == 0) { // if not sparkling, set to "back ground" color + leds[i] = sparkleBgColor; + } else { + CHSV hsv = rgb2hsv_approximate(leds[i]); // Used to get approximate Hue + EVERY_N_MILLISECONDS(20) { + ledsData[i][0] = hsv.hue - 1; // slightly shift hue + } + ledsData[i][2] = scale8(ledsData[i][2], 242); // slowly darken + leds[i] = CHSV(ledsData[i][0], ledsData[i][1], ledsData[i][2]); + ledsData[i][3] = ledsData[i][3] - 1; // countdown sparkle tag + } } - if (randomPick == 2) { - ledsData[pick][0] = 130; // sparkle hue (light blue) - ledsData[pick][1] = 200; // sparkle saturation - ledsData[pick][2] = 255; // sparkle value - } - leds[pick] = CHSV(ledsData[pick][0], ledsData[pick][1], ledsData[pick][2]); - } - } - for (uint16_t i=0; i < NUM_LEDS; i++) { - if (ledsData[i][3] == 0) { // if not sparkling, set to "back ground" color - leds[i] = sparkleBgColor; - } else { - CHSV hsv = rgb2hsv_approximate(leds[i]); // Used to get approximate Hue - EVERY_N_MILLISECONDS(20) { ledsData[i][0] = hsv.hue - 1; } // slightly shift hue - ledsData[i][2] = scale8(ledsData[i][2], 242); // slowly darken - leds[i] = CHSV(ledsData[i][0], ledsData[i][1], ledsData[i][2]); - ledsData[i][3] = ledsData[i][3] - 1; // countdown sparkle tag - } } - } }//end christmasSparklesBP diff --git a/DemoReel100_RandomShiftedGlitter.ino b/DemoReel100_RandomShiftedGlitter.ino index 121deb0..d9fdf70 100644 --- a/DemoReel100_RandomShiftedGlitter.ino +++ b/DemoReel100_RandomShiftedGlitter.ino @@ -12,27 +12,28 @@ #include "FastLED.h" FASTLED_USING_NAMESPACE +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE APA102 -#define COLOR_ORDER BGR -#define NUM_LEDS 38 -#define BRIGHTNESS 96 -#define FRAMES_PER_SECOND 120 CRGB leds[NUM_LEDS]; +#define FRAMES_PER_SECOND 120 + uint16_t ledsData[NUM_LEDS][4]; // array to store RGB data and an extra value uint16_t pick; // stores a temporary pixel number //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // 3 second delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- @@ -47,24 +48,27 @@ uint8_t gHue = 0; // rotating "base color" used by many of the patterns //--------------------------------------------------------------- void loop() { - // Call the current pattern function once, updating the 'leds' array - gPatterns[gCurrentPatternNumber](); + // Call the current pattern function once, updating the 'leds' array + gPatterns[gCurrentPatternNumber](); - FastLED.show(); - FastLED.delay(1000/FRAMES_PER_SECOND); // slows the framerate to a modest value + FastLED.show(); + FastLED.delay(1000 / FRAMES_PER_SECOND); // slows the framerate to a modest value - // do some periodic updates - EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow - EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically + // do some periodic updates + EVERY_N_MILLISECONDS( 20 ) { + gHue++; // slowly cycle the "base color" through the rainbow + } + EVERY_N_SECONDS( 10 ) { + nextPattern(); // change patterns periodically + } } //--------------------------------------------------------------- #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) -void nextPattern() -{ - // add one to the current pattern number, and wrap around at the end - gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns); +void nextPattern() { + // add one to the current pattern number, and wrap around at the end + gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns); } @@ -74,58 +78,58 @@ void nextPattern() //=============================================================== //--------------------------------------------------------------- void rainbowRandomGlitter() { - fill_rainbow( leds, NUM_LEDS, gHue, 7); - if( random8() < 45 ) { // How often to glitter things up! Higher number is more often. - pick = random16(NUM_LEDS); - if (ledsData[pick][3] == 0 ) { - ledsData[pick][3] = 40; // Used to tag pixel and determine glitter time - ledsData[pick][0] = random8(); // Pick random rgb values - ledsData[pick][1] = random8(); - ledsData[pick][2] = random8(); + fill_rainbow( leds, NUM_LEDS, gHue, 7); + if( random8() < 45 ) { // How often to glitter things up! Higher number is more often. + pick = random16(NUM_LEDS); + if (ledsData[pick][3] == 0 ) { + ledsData[pick][3] = 40; // Used to tag pixel and determine glitter time + ledsData[pick][0] = random8(); // Pick random rgb values + ledsData[pick][1] = random8(); + ledsData[pick][2] = random8(); + } } - } - for (uint16_t i=0; i < NUM_LEDS; i++) { - if (ledsData[i][3] == 0) { - leds[i].fadeToBlackBy(180); // Fade down non-glittering pixels so glitter will show up more - } else { - //leds[i] = CRGB(ledsData[i][0], ledsData[i][1], ledsData[i][2]); // Plug in rgb values - leds[i].fadeToBlackBy(8); // Slowly fade down - ledsData[i][0] = leds[i].r; // Store the rgb values back in ledsData array - ledsData[i][1] = leds[i].g; - ledsData[i][2] = leds[i].b; - ledsData[i][3] = ledsData[i][3] - 1; + for (uint16_t i = 0; i < NUM_LEDS; i++) { + if (ledsData[i][3] == 0) { + leds[i].fadeToBlackBy(180); // Fade down non-glittering pixels so glitter will show up more + } else { + //leds[i] = CRGB(ledsData[i][0], ledsData[i][1], ledsData[i][2]); // Plug in rgb values + leds[i].fadeToBlackBy(8); // Slowly fade down + ledsData[i][0] = leds[i].r; // Store the rgb values back in ledsData array + ledsData[i][1] = leds[i].g; + ledsData[i][2] = leds[i].b; + ledsData[i][3] = ledsData[i][3] - 1; + } } - } }//end rainbowRandomGlitter //--------------------------------------------------------------- void rainbowShiftedGlitter() { - fill_rainbow( leds, NUM_LEDS, gHue, 3); - if( random8() < 30 ) { // How often to glitter things up! Higher number is more often. - pick = random16(NUM_LEDS); - if (ledsData[pick][3] == 0 ) { - ledsData[pick][3] = 35; // Used to tag pixel and determine glitter time - CRGB rgb(leds[pick].r, leds[pick].g, leds[pick].b); - CHSV hsv = rgb2hsv_approximate(rgb); // Used to get approx Hue - leds[pick] = CHSV(hsv.hue-50, 255, 255); // Color shift Hue on glitter pixel - ledsData[pick][0] = leds[pick].r; // Store rgb values back in ledsData array - ledsData[pick][1] = leds[pick].g; - ledsData[pick][2] = leds[pick].b; + fill_rainbow( leds, NUM_LEDS, gHue, 3); + if( random8() < 30 ) { // How often to glitter things up! Higher number is more often. + pick = random16(NUM_LEDS); + if (ledsData[pick][3] == 0 ) { + ledsData[pick][3] = 35; // Used to tag pixel and determine glitter time + CRGB rgb(leds[pick].r, leds[pick].g, leds[pick].b); + CHSV hsv = rgb2hsv_approximate(rgb); // Used to get approx Hue + leds[pick] = CHSV(hsv.hue - 50, 255, 255); // Color shift Hue on glitter pixel + ledsData[pick][0] = leds[pick].r; // Store rgb values back in ledsData array + ledsData[pick][1] = leds[pick].g; + ledsData[pick][2] = leds[pick].b; + } } - } - for (uint16_t i=0; i < NUM_LEDS; i++) { - if (ledsData[i][3] == 0) { - leds[i].fadeToBlackBy(180); // Fade down non-glittering pixels so glitter will show up more - } else { - leds[i] = CRGB(ledsData[i][0], ledsData[i][1], ledsData[i][2]); // Plug in rgb values - leds[i].fadeToBlackBy(7); // Slowly fade down - ledsData[i][0] = leds[i].r; // Store the rgb values back in ledsData array - ledsData[i][1] = leds[i].g; - ledsData[i][2] = leds[i].b; - ledsData[i][3] = ledsData[i][3] - 1; + for (uint16_t i = 0; i < NUM_LEDS; i++) { + if (ledsData[i][3] == 0) { + leds[i].fadeToBlackBy(180); // Fade down non-glittering pixels so glitter will show up more + } else { + leds[i] = CRGB(ledsData[i][0], ledsData[i][1], ledsData[i][2]); // Plug in rgb values + leds[i].fadeToBlackBy(7); // Slowly fade down + ledsData[i][0] = leds[i].r; // Store the rgb values back in ledsData array + ledsData[i][1] = leds[i].g; + ledsData[i][2] = leds[i].b; + ledsData[i][3] = ledsData[i][3] - 1; + } } - } }//end rainbowShiftedGlitter diff --git a/DemoReel100_with_button.ino b/DemoReel100_with_button.ino index 415f58a..e3eec9f 100644 --- a/DemoReel100_with_button.ino +++ b/DemoReel100_with_button.ino @@ -11,13 +11,15 @@ //*************************************************************** #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; -#define BRIGHTNESS 128 + #define FRAMES_PER_SECOND 120 @@ -32,11 +34,11 @@ Button myButton(buttonPin, true, true, 50); // Declare the button //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // 3 second delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } @@ -49,24 +51,25 @@ uint8_t gHue = 0; // rotating "base color" used by many of the patterns //--------------------------------------------------------------- -void loop() -{ - // Call the current pattern function once, updating the 'leds' array - gPatterns[gCurrentPatternNumber](); - - // send the 'leds' array out to the actual LED strip - FastLED.show(); - // insert a delay to keep the framerate modest - FastLED.delay(1000/FRAMES_PER_SECOND); - - // do some periodic updates - EVERY_N_MILLISECONDS( 20 ) { gHue++; } // slowly cycle the "base color" through the rainbow - - // BUTTON STUFF - // Not using this timer to change patterns any more. Instead check the button. - // EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically - // - readbutton(); // check for button press +void loop() { + // Call the current pattern function once, updating the 'leds' array + gPatterns[gCurrentPatternNumber](); + + // send the 'leds' array out to the actual LED strip + FastLED.show(); + // insert a delay to keep the framerate modest + FastLED.delay(1000 / FRAMES_PER_SECOND); + + // do some periodic updates + EVERY_N_MILLISECONDS( 20 ) { + gHue++; // slowly cycle the "base color" through the rainbow + } + + // BUTTON STUFF + // Not using this timer to change patterns any more. Instead check the button. + // EVERY_N_SECONDS( 10 ) { nextPattern(); } // change patterns periodically + // + readbutton(); // check for button press }//end_main_loop @@ -74,61 +77,57 @@ void loop() //--------------------------------------------------------------- -void nextPattern() -{ - // add one to the current pattern number, and wrap around at the end - gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns); +void nextPattern() { + // add one to the current pattern number, and wrap around at the end + gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns); } -void rainbow() -{ - // FastLED's built-in rainbow generator - fill_rainbow( leds, NUM_LEDS, gHue, 12); +void rainbow() { + // FastLED's built-in rainbow generator + fill_rainbow( leds, NUM_LEDS, gHue, 12); } -void confetti() -{ - // random colored speckles that blink in and fade smoothly - fadeToBlackBy( leds, NUM_LEDS, 20); - int pos = random16(NUM_LEDS); - leds[pos] += CHSV( gHue + random8(64), random8(128,200), random8(48,255)); +void confetti() { + // random colored speckles that blink in and fade smoothly + fadeToBlackBy( leds, NUM_LEDS, 20); + int pos = random16(NUM_LEDS); + leds[pos] += CHSV( gHue + random8(64), random8(128, 200), random8(48, 255)); } -void sinelon() -{ - // a colored dot sweeping back and forth, with fading trails - fadeToBlackBy( leds, NUM_LEDS, 12); - int pos = beatsin16( 13, 0, NUM_LEDS-1 ); - leds[pos] += CHSV( gHue, 255, 192); +void sinelon() { + // a colored dot sweeping back and forth, with fading trails + fadeToBlackBy( leds, NUM_LEDS, 12); + int pos = beatsin16( 13, 0, NUM_LEDS - 1 ); + leds[pos] += CHSV( gHue, 255, 192); } void juggle() { - // four colored dots, weaving in and out of sync with each other - fadeToBlackBy( leds, NUM_LEDS, 20); - byte dothue = 0; - for( int i = 0; i < 4; i++) { - leds[beatsin16( i+5, 0, NUM_LEDS-1 )] |= CHSV(dothue, 200, 255); - dothue += 32; - } + // four colored dots, weaving in and out of sync with each other + fadeToBlackBy( leds, NUM_LEDS, 20); + byte dothue = 0; + for( int i = 0; i < 4; i++) { + leds[beatsin16( i + 5, 0, NUM_LEDS - 1 )] |= CHSV(dothue, 200, 255); + dothue += 32; + } } //BUTTON STUFF //---------Function to read the button and do something---------- void readbutton() { - myButton.read(); - if(myButton.wasPressed()) { - Serial.println("Button pressed! Next pattern... "); - nextPattern(); // Change to the next pattern - - //Flash pixel zero white as a visual that button was pressed. - leds[0] = CHSV(0,0,255); //Set first pixel color white - FastLED.show(); //Update display - delay(100); //Short pause so we can see leds[0] flash - leds[0] = CRGB::Black; //Set first pixel off - FastLED.show(); //Update display - delay(100); //Short pause so we can see leds[0] flash - } + myButton.read(); + if(myButton.wasPressed()) { + Serial.println("Button pressed! Next pattern... "); + nextPattern(); // Change to the next pattern + + //Flash pixel zero white as a visual that button was pressed. + leds[0] = CHSV(0, 0, 255); //Set first pixel color white + FastLED.show(); //Update display + delay(100); //Short pause so we can see leds[0] flash + leds[0] = CRGB::Black; //Set first pixel off + FastLED.show(); //Update display + delay(100); //Short pause so we can see leds[0] flash + } }//end_readbutton diff --git a/Glediator_test1.ino b/Glediator_test1.ino index 0adcd18..671c866 100644 --- a/Glediator_test1.ino +++ b/Glediator_test1.ino @@ -11,7 +11,7 @@ // Pixel Order: HL_BL (for a single strip, or one of the the others per your setup) // Color Order: RGB // -// Baud-Rate: 1,000,000 was suggested, but you can use +// Baud-Rate: 1,000,000 was suggested, but you can use // whatever as long as they are both set the // same here and in Glediator. // @@ -23,12 +23,13 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB -#define BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; #define BAUD_RATE 115200 //1000000 //250000 // Set the same in Glediator @@ -37,45 +38,45 @@ CRGB leds[NUM_LEDS]; //--------------------------------------------------------------- void setup() { - Serial.begin(BAUD_RATE); - delay(1500); // startup delay - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - startupLEDsTest(); // run quick RGB color test - Serial.println("Setup done. \n"); + Serial.begin(BAUD_RATE); + delay(1500); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + startupLEDsTest(); // run quick RGB color test + Serial.println("Setup done. \n"); } //--------------------------------------------------------------- int serialGlediator () { - while ( !Serial.available() ) {} - return Serial.read(); + while ( !Serial.available() ) {} + return Serial.read(); } //--------------------------------------------------------------- void loop() { - while (serialGlediator () != CMD_NEW_DATA) {} - Serial.readBytes((char*)leds, NUM_LEDS * 3); - FastLED.show(); + while (serialGlediator () != CMD_NEW_DATA) {} + Serial.readBytes((char *)leds, NUM_LEDS * 3); + FastLED.show(); } //--------------------------------------------------------------- void startupLEDsTest() { - // startup blink test to confirm LEDs are working. - FastLED.setBrightness(32); - fill_solid(leds, NUM_LEDS, CRGB(255,0,0)); // fill red - FastLED.show(); - delay(1000); - fill_solid(leds, NUM_LEDS, CRGB(0,255,0)); // fill green - FastLED.show(); - delay(1000); - fill_solid(leds, NUM_LEDS, CRGB(0,0,255)); // fill blue - FastLED.show(); - delay(1000); - FastLED.clear(); - FastLED.show(); - FastLED.setBrightness(BRIGHTNESS); + // startup blink test to confirm LEDs are working. + FastLED.setBrightness(32); + fill_solid(leds, NUM_LEDS, CRGB(255, 0, 0)); // fill red + FastLED.show(); + delay(1000); + fill_solid(leds, NUM_LEDS, CRGB(0, 255, 0)); // fill green + FastLED.show(); + delay(1000); + fill_solid(leds, NUM_LEDS, CRGB(0, 0, 255)); // fill blue + FastLED.show(); + delay(1000); + FastLED.clear(); + FastLED.show(); + FastLED.setBrightness(BRIGHTNESS); } diff --git a/Hex_colors_to_function.ino b/Hex_colors_to_function.ino index 473b70f..81a355f 100644 --- a/Hex_colors_to_function.ino +++ b/Hex_colors_to_function.ino @@ -6,12 +6,13 @@ //*************************************************************** #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 -#define BRIGHTNESS 50 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; #define MGPu CRGB(0x8010ff) // Mardi Gras Purple @@ -21,42 +22,42 @@ CRGB leds[NUM_LEDS]; //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // 3 second delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - cylon(MGPu); // Purple. (Call cylon function with this color.) - cylon(MGGr); // Green - cylon(MGGo); // Gold + cylon(MGPu); // Purple. (Call cylon function with this color.) + cylon(MGGr); // Green + cylon(MGGo); // Gold } //--------------------------------------------------------------- -void fadeall() { - for (int i = 0; i < NUM_LEDS; i++) { - leds[i].nscale8(250); - } +void fadeall() { + for (int i = 0; i < NUM_LEDS; i++) { + leds[i].nscale8(250); + } } void cylon(CRGB streakcolor) { - for (int i = 0; i < NUM_LEDS; i++) { - leds[i] = streakcolor; - FastLED.show(); - fadeall(); - delay(10); - } - for (int i = (NUM_LEDS) - 1; i >= 0; i--) { - leds[i] = streakcolor; - FastLED.show(); - fadeall(); - delay(10); - } + for (int i = 0; i < NUM_LEDS; i++) { + leds[i] = streakcolor; + FastLED.show(); + fadeall(); + delay(10); + } + for (int i = (NUM_LEDS) - 1; i >= 0; i--) { + leds[i] = streakcolor; + FastLED.show(); + fadeall(); + delay(10); + } } diff --git a/README.md b/README.md index 33c2b8f..bbd5448 100644 --- a/README.md +++ b/README.md @@ -13,3 +13,46 @@ Download the current FastLED library from: [github.com/FastLED/FastLED](https:// -Marc Miller, Febuary 2015 + + + + +## How to use these examples + +1. Install the FastLED library: + - Open the Arduino editor + - Choose Tools, Manage Libraries + - In the search box, enter `fastled` (capitalization doesn't matter) + - Click Install +2. [Wire up and connect your pixel strip](https://github.com/FastLED/FastLED/wiki/Wiring-leds) to your Arduino, taking note of the data pin (and clock pin, if appropriate for your strip) that you used. +3. Determining the [color order of your pixels](https://github.com/FastLED/FastLED/wiki/Rgb-calibration): + - In the Arduino editor, choose File, Examples, FastLED, RGBCalibrate + - Define DATA_PIN to the pin that data is connected to. + - If you're using a 4-wire pixel strip (e.g. an APA102), define the CLOCK_PIN + - Uncomment the line in setup that corresponds to the LED chipset that you are using. (Note that they all explicitly specify the RGB order as RGB) + - Compile/upload/run the sketch + - You should see six leds on. If the RGB ordering is correct, you should see 1 red led, 2 green leds, and 3 blue leds. If you see different colors, the count of each color tells you what the position for that color in the rgb orering should be. So, for example, if you see 1 Blue, and 2 Red, and 3 Green leds then the rgb ordering should be BRG (Blue, Red, Green). +4. Now you're ready to try these examples. Open an ino file. The Arduino editor will prompt you that it has to be in a folder. Click OK and it will move the file for you. +5. Edit the defines at the top to match your configuration (pixel type, data pin, clock pin, etc.) + + ```c + #include "FastLED.h" + #define LED_TYPE APA102 + #define DATA_PIN 11 + #define CLK_PIN 13 + #define NUM_LEDS 32 + #define COLOR_ORDER BGR + #define BRIGHTNESS 128 + + CRGB leds[NUM_LEDS]; + + ``` +6. In the `setup` function, if you're using a 3-pin pixel strip (e.g. a WS2811) you'll need to uncomment the first `FastLED.addLeds` statement, and comment out the other. For 4-pin pixels, leave as-is. + + ```c + // FOR 3-PIN LED STRIPS, EDIT THE CODE TO LOOK LIKE THIS: + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + + ``` +7. Compile/upload/run the sketch \ No newline at end of file diff --git a/RGB2HSV_example.ino b/RGB2HSV_example.ino index 57d3675..e36f42a 100644 --- a/RGB2HSV_example.ino +++ b/RGB2HSV_example.ino @@ -8,52 +8,62 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; CRGB rgb; CHSV hsv; //------------------------------------------------------------------ -void setup(){ - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1500); // Power-up delay - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(255); - Serial.println("Setup done."); +void setup() { + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // Power-up delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + Serial.println("Setup done."); } //------------------------------------------------------------------ -void loop(){ - - EVERY_N_SECONDS(3) { - rgb = CRGB( random8(),random8(),random8() ); //pick random r,g,b values - hsv = rgb2hsv_approximate( rgb ); //convert rgb to hsv - - for(uint8_t i=0; i(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); } //--------------------------------------------------------------- void loop() { - EVERY_N_SECONDS( 3 ) { - //CHSV hsv( random8(), 255, 255 ); //pick random Hue - CHSV hsv( random8(), random8(), random8() ); //pick random HSV - CRGB rgb; - hsv2rgb_rainbow( hsv, rgb); //convert HSV to RGB - - //set first two pixels with HSV and RGB values to confirm they are the same. - leds[0] = hsv; - leds[1] = rgb; - - //print out HSV and RGB values - Serial.print(" HSV: "); - Serial.print(hsv.h); - Serial.print(", "); Serial.print(hsv.s); - Serial.print(", "); Serial.println(hsv.v); - - Serial.print(" RGB: "); - Serial.print(rgb.r); - Serial.print(", "); Serial.print(rgb.g); - Serial.print(", "); Serial.println(rgb.b); - - - //Now try converting RGB back to HSV using rgb2hsv_approximate. - //rgb2hsv_approximate works best with fully saturated or nearly - //saturated colors, otherwise it's not always super accurate. - - hsv = rgb2hsv_approximate( rgb ); - - //set third pixels with HSV approximate values to show how close it is. - leds[2] = hsv; - - //print out approximated HSV values - Serial.print("HSV(approx.): "); - Serial.print(hsv.h); - Serial.print(", "); Serial.print(hsv.s); - Serial.print(", "); Serial.println(hsv.v); - - Serial.println(" "); - - FastLED.show(); //display the pixels - - }//end_EVERY_N + EVERY_N_SECONDS( 3 ) { + //CHSV hsv( random8(), 255, 255 ); //pick random Hue + CHSV hsv( random8(), random8(), random8() ); //pick random HSV + CRGB rgb; + hsv2rgb_rainbow( hsv, rgb); //convert HSV to RGB + + //set first two pixels with HSV and RGB values to confirm they are the same. + leds[0] = hsv; + leds[1] = rgb; + + //print out HSV and RGB values + Serial.print(" HSV: "); + Serial.print(hsv.h); + Serial.print(", "); + Serial.print(hsv.s); + Serial.print(", "); + Serial.println(hsv.v); + + Serial.print(" RGB: "); + Serial.print(rgb.r); + Serial.print(", "); + Serial.print(rgb.g); + Serial.print(", "); + Serial.println(rgb.b); + + + //Now try converting RGB back to HSV using rgb2hsv_approximate. + //rgb2hsv_approximate works best with fully saturated or nearly + //saturated colors, otherwise it's not always super accurate. + + hsv = rgb2hsv_approximate( rgb ); + + //set third pixels with HSV approximate values to show how close it is. + leds[2] = hsv; + + //print out approximated HSV values + Serial.print("HSV(approx.): "); + Serial.print(hsv.h); + Serial.print(", "); + Serial.print(hsv.s); + Serial.print(", "); + Serial.println(hsv.v); + + Serial.println(" "); + + FastLED.show(); //display the pixels + + }//end_EVERY_N }//end_main_loop diff --git a/base_with_overlay.ino b/base_with_overlay.ino index f754455..0c5e60c 100644 --- a/base_with_overlay.ino +++ b/base_with_overlay.ino @@ -1,6 +1,6 @@ //*************************************************************** // Example of combining an "overlay" pattern with a "base" pattern. -// +// // The overlay is toggled On/Off with a push button, but this could // be modified to triggered by anything else as needed. // @@ -11,12 +11,12 @@ //*************************************************************** #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 -#define BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 CRGB base[NUM_LEDS]; //base pattern that's always running CRGB overlay[NUM_LEDS]; //this is added to base @@ -35,68 +35,69 @@ Button myButton(buttonPin, true, true, 50); //declare the button //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1500); // startup delay - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); - Serial.println("Setup done.\n"); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); + Serial.println("Setup done.\n"); } //--------------------------------------------------------------- -void loop() -{ - triggerCheck(); //check the overlay trigger (a push button in this example) +void loop() { + triggerCheck(); //check the overlay trigger (a push button in this example) - basePattern(); //update the base display - overlayPattern(); //update the overlay display (as needed) - combinePatterns(); //combine the base and overlay before displaying + basePattern(); //update the base display + overlayPattern(); //update the overlay display (as needed) + combinePatterns(); //combine the base and overlay before displaying - FastLED.show(); //show the pixels + FastLED.show(); //show the pixels }//end_main_loop //--------------------------------------------------------------- void basePattern() { //NOTE: we are drawing to the "base" CRGB here - static uint8_t gHue = 0; //slowly rotating hue color - EVERY_N_MILLISECONDS( 30 ) { gHue++; } //slowly cycle through the rainbow - fill_rainbow( base, NUM_LEDS, gHue, 255/NUM_LEDS/2); - fadeToBlackBy( base, NUM_LEDS, 220); //dim the rainbow down + static uint8_t gHue = 0; //slowly rotating hue color + EVERY_N_MILLISECONDS( 30 ) { + gHue++; //slowly cycle through the rainbow + } + fill_rainbow( base, NUM_LEDS, gHue, 255 / NUM_LEDS / 2); + fadeToBlackBy( base, NUM_LEDS, 220); //dim the rainbow down }//end_basePattern //--------------------------------------------------------------- void overlayPattern() { //NOTE: we are drawing to the "overlay" CRGB here - if (toggleButton) { //overlay is currently "On" - EVERY_N_MILLISECONDS(60) { - static uint8_t pos = 0; - overlay[pos] = overlay[NUM_LEDS-1-pos] = CRGB::White; - fadeToBlackBy( overlay, NUM_LEDS, 120); //creates fading tail effect - pos++; - if (pos == NUM_LEDS/2) { //check against desired range - pos = 0; //reset for next round - //toggleButton = !toggleButton; //uncomment to have the overlay pattern only run a single time - } + if (toggleButton) { //overlay is currently "On" + EVERY_N_MILLISECONDS(60) { + static uint8_t pos = 0; + overlay[pos] = overlay[NUM_LEDS - 1 - pos] = CRGB::White; + fadeToBlackBy( overlay, NUM_LEDS, 120); //creates fading tail effect + pos++; + if (pos == NUM_LEDS / 2) { //check against desired range + pos = 0; //reset for next round + //toggleButton = !toggleButton; //uncomment to have the overlay pattern only run a single time + } + } + + } else { //overlay is currently "Off" + EVERY_N_MILLISECONDS(30) { + fadeToBlackBy( overlay, NUM_LEDS, 50); //fadeout overlay pattern + } } - } else { //overlay is currently "Off" - EVERY_N_MILLISECONDS(30) { - fadeToBlackBy( overlay, NUM_LEDS, 50); //fadeout overlay pattern - } - } - }//end_overlayPattern //--------------------------------------------------------------- void combinePatterns() { - for (uint8_t i=0; i(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); +void setup() { + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- -void loop() -{ - EVERY_N_MILLISECONDS( 50 ) { gHue++; } // Slowly cycle through the rainbow +void loop() { + EVERY_N_MILLISECONDS( 50 ) { + gHue++; // Slowly cycle through the rainbow + } + + beat8_tail(); // Subroutine to move the pixel! - beat8_tail(); // Subroutine to move the pixel! - - FastLED.show(); // Display the pixels. + FastLED.show(); // Display the pixels. }//end main loop //=============================================================== -void beat8_tail() -{ - EVERY_N_MILLISECONDS( 5 ) { - fadeToBlackBy( leds, NUM_LEDS, fadeRate); // Fade out pixels. - } - uint16_t pos = beat8(moveSpeed) % NUM_LEDS; // modulo the position to be within NUM_LEDS - leds[pos] = CHSV( gHue, 200, 255); - //Serial.print("pos: "); Serial.println(pos); +void beat8_tail() { + EVERY_N_MILLISECONDS( 5 ) { + fadeToBlackBy( leds, NUM_LEDS, fadeRate); // Fade out pixels. + } + uint16_t pos = beat8(moveSpeed) % NUM_LEDS; // modulo the position to be within NUM_LEDS + leds[pos] = CHSV( gHue, 200, 255); + //Serial.print("pos: "); Serial.println(pos); } diff --git a/blend_into_rainbow.ino b/blend_into_rainbow.ino index 0cf0487..1cd9992 100644 --- a/blend_into_rainbow.ino +++ b/blend_into_rainbow.ino @@ -6,12 +6,13 @@ //*************************************************************** #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 -#define BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint8_t pos; //stores a position for color being blended in @@ -20,52 +21,54 @@ uint8_t hue, hue2; //stores a color //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(2500); // startup delay - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - Serial.println("Setup done. \n"); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(2500); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + Serial.println("Setup done. \n"); } //--------------------------------------------------------------- void loop() { - EVERY_N_MILLISECONDS(60){ - hue++; //used to cycle through the rainbow - } - - fill_rainbow(leds, NUM_LEDS, hue, 255/NUM_LEDS/4); //draw part of the rainbow into the strip - fadeToBlackBy(leds, NUM_LEDS, 70); //fade the whole strip down some - - EVERY_N_MILLISECONDS(150) { - pos++; - if (pos == NUM_LEDS) { pos = 0; } //reset to begining - } - - EVERY_N_MILLISECONDS(5){ - hue2 = hue2 - 1; //used to change the moving color - } - CRGB blendThisIn = CHSV(hue2, 140, 255); //color to blend into the background - CRGB blendThisIn2 = CHSV(hue2, 170, 255); //color to blend into the background - CRGB blendThisIn3 = CHSV(hue2, 210, 255); //color to blend into the background - CRGB blendThisIn4 = CHSV(hue2, 255, 255); //color to blend into the background - - static uint8_t blendAmount = 240; //amount of blend [range: 0-255] - - leds[pos] = nblend(leds[pos], blendThisIn4, blendAmount/3); - leds[mod8(pos+1,NUM_LEDS)] = nblend(leds[mod8(pos+1,NUM_LEDS)], blendThisIn3, blendAmount/2); - leds[mod8(pos+2,NUM_LEDS)] = nblend(leds[mod8(pos+2,NUM_LEDS)], blendThisIn2, blendAmount); - leds[mod8(pos+3,NUM_LEDS)] = nblend(leds[mod8(pos+3,NUM_LEDS)], blendThisIn, blendAmount); - leds[mod8(pos+4,NUM_LEDS)] = nblend(leds[mod8(pos+4,NUM_LEDS)], blendThisIn2, blendAmount); - leds[mod8(pos+5,NUM_LEDS)] = nblend(leds[mod8(pos+5,NUM_LEDS)], blendThisIn3, blendAmount/2); - leds[mod8(pos+6,NUM_LEDS)] = nblend(leds[mod8(pos+6,NUM_LEDS)], blendThisIn4, blendAmount/3); - - FastLED.show(); //update the display - - EVERY_N_SECONDS(random8(5,21)) { - delay(3000); //randomly stop the animation to observe the blending - } + EVERY_N_MILLISECONDS(60) { + hue++; //used to cycle through the rainbow + } + + fill_rainbow(leds, NUM_LEDS, hue, 255 / NUM_LEDS / 4); //draw part of the rainbow into the strip + fadeToBlackBy(leds, NUM_LEDS, 70); //fade the whole strip down some + + EVERY_N_MILLISECONDS(150) { + pos++; + if (pos == NUM_LEDS) { + pos = 0; //reset to begining + } + } + + EVERY_N_MILLISECONDS(5) { + hue2 = hue2 - 1; //used to change the moving color + } + CRGB blendThisIn = CHSV(hue2, 140, 255); //color to blend into the background + CRGB blendThisIn2 = CHSV(hue2, 170, 255); //color to blend into the background + CRGB blendThisIn3 = CHSV(hue2, 210, 255); //color to blend into the background + CRGB blendThisIn4 = CHSV(hue2, 255, 255); //color to blend into the background + + static uint8_t blendAmount = 240; //amount of blend [range: 0-255] + + leds[pos] = nblend(leds[pos], blendThisIn4, blendAmount / 3); + leds[mod8(pos + 1, NUM_LEDS)] = nblend(leds[mod8(pos + 1, NUM_LEDS)], blendThisIn3, blendAmount / 2); + leds[mod8(pos + 2, NUM_LEDS)] = nblend(leds[mod8(pos + 2, NUM_LEDS)], blendThisIn2, blendAmount); + leds[mod8(pos + 3, NUM_LEDS)] = nblend(leds[mod8(pos + 3, NUM_LEDS)], blendThisIn, blendAmount); + leds[mod8(pos + 4, NUM_LEDS)] = nblend(leds[mod8(pos + 4, NUM_LEDS)], blendThisIn2, blendAmount); + leds[mod8(pos + 5, NUM_LEDS)] = nblend(leds[mod8(pos + 5, NUM_LEDS)], blendThisIn3, blendAmount / 2); + leds[mod8(pos + 6, NUM_LEDS)] = nblend(leds[mod8(pos + 6, NUM_LEDS)], blendThisIn4, blendAmount / 3); + + FastLED.show(); //update the display + + EVERY_N_SECONDS(random8(5, 21)) { + delay(3000); //randomly stop the animation to observe the blending + } }//end_main_loop diff --git a/blend_to_target_color.ino b/blend_to_target_color.ino index 0ac1431..8d07de8 100644 --- a/blend_to_target_color.ino +++ b/blend_to_target_color.ino @@ -9,54 +9,59 @@ //*************************************************************** #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 -#define BRIGHTNESS 100 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint8_t blendRate = 50; // How fast to blend. Higher is slower. [milliseconds] -CHSV colorStart = CHSV(96,255,255); // starting color -CHSV colorTarget = CHSV(192,255,255); // target color +CHSV colorStart = CHSV(96, 255, 255); // starting color +CHSV colorTarget = CHSV(192, 255, 255); // target color CHSV colorCurrent = colorStart; //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // 3 second delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - Serial.println("Setup done. \n"); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + Serial.println("Setup done. \n"); } //--------------------------------------------------------------- -void loop() -{ - EVERY_N_MILLISECONDS(blendRate){ - static uint8_t k; - if ( colorCurrent.h == colorTarget.h ) { // Check if target has been reached - colorStart = colorCurrent; - colorTarget = CHSV(random8(),255,255); // new target to transition toward - k = 0; // reset k value - Serial.print("New colorTarget:\t\t\t"); Serial.println(colorTarget.h); - } +void loop() { + EVERY_N_MILLISECONDS(blendRate) { + static uint8_t k; + if ( colorCurrent.h == colorTarget.h ) { // Check if target has been reached + colorStart = colorCurrent; + colorTarget = CHSV(random8(), 255, 255); // new target to transition toward + k = 0; // reset k value + Serial.print("New colorTarget:\t\t\t"); + Serial.println(colorTarget.h); + } - colorCurrent = blend(colorStart, colorTarget, k, SHORTEST_HUES); - fill_solid( leds, NUM_LEDS, colorCurrent ); - leds[0] = colorTarget; // set first pixel to always show target color - Serial.print("colorCurrent:\t"); Serial.print(colorCurrent.h); Serial.print("\t"); - Serial.print("colorTarget:\t"); Serial.print(colorTarget.h); - Serial.print("\tk: "); Serial.println(k); - k++; - } + colorCurrent = blend(colorStart, colorTarget, k, SHORTEST_HUES); + fill_solid( leds, NUM_LEDS, colorCurrent ); + leds[0] = colorTarget; // set first pixel to always show target color + Serial.print("colorCurrent:\t"); + Serial.print(colorCurrent.h); + Serial.print("\t"); + Serial.print("colorTarget:\t"); + Serial.print(colorTarget.h); + Serial.print("\tk: "); + Serial.println(k); + k++; + } - FastLED.show(); // update the display + FastLED.show(); // update the display } //--------------------------------------------------------------- diff --git a/brakeLights_with_button.ino b/brakeLights_with_button.ino index c2c0e20..0493f82 100644 --- a/brakeLights_with_button.ino +++ b/brakeLights_with_button.ino @@ -26,48 +26,55 @@ Button brakeButton(brakeButtonPin, true, true, 50); //--------------------------------------------------------------- #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 8 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 8 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; -#define BRIGHTNESS 255 + uint8_t BrakeStatus = 0; // Status of brake lights. [0=Off, 1=Activated, 2=On] -CHSV black (0,0,0); // black -CHSV brakeRed (0,255,255); // red full brightness -CHSV brakeDimRed (0,255,32); // dim red -CHSV accent (185,120,70); // alternate accent color +CHSV black (0, 0, 0); // black +CHSV brakeRed (0, 255, 255); // red full brightness +CHSV brakeDimRed (0, 255, 32); // dim red +CHSV accent (185, 120, 70); // alternate accent color // setup pixel groups -byte center[] = {3,4}; // center ring -byte first[] = {2,3,4,5}; // first ring -byte second[] = {1,2,5,6}; // second ring -byte third[] = {0,1,6,7}; // third ring +byte center[] = {3, 4}; // center ring +byte first[] = {2, 3, 4, 5}; // first ring +byte second[] = {1, 2, 5, 6}; // second ring +byte third[] = {0, 1, 6, 7}; // third ring //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1500); // short delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // short delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); } //--------------------------------------------------------------- -void loop() -{ - readbutton(); // check the button +void loop() { + readbutton(); // check the button - if (BrakeStatus == 0) { brakeOff(); } - if (BrakeStatus == 1) { brakeActivated(); } - if (BrakeStatus == 2) { brakeOn(); } - FastLED.show(); + if (BrakeStatus == 0) { + brakeOff(); + } + if (BrakeStatus == 1) { + brakeActivated(); + } + if (BrakeStatus == 2) { + brakeOn(); + } + FastLED.show(); }//end_main_loop @@ -80,90 +87,93 @@ void loop() //--------------------------------------------------------------- //Check the button and set the appropriate flag void readbutton() { - brakeButton.read(); // check the state of the brake button - - if(brakeButton.isPressed()) { - BrakeStatus = 2; - EVERY_N_MILLISECONDS(250){ - Serial.print(BrakeStatus); Serial.println(" Brake is On..."); - } - } else { - BrakeStatus = 0; - EVERY_N_MILLISECONDS(500){ - Serial.print(BrakeStatus); Serial.println(" Brake Off"); + brakeButton.read(); // check the state of the brake button + + if(brakeButton.isPressed()) { + BrakeStatus = 2; + EVERY_N_MILLISECONDS(250) { + Serial.print(BrakeStatus); + Serial.println(" Brake is On..."); + } + } else { + BrakeStatus = 0; + EVERY_N_MILLISECONDS(500) { + Serial.print(BrakeStatus); + Serial.println(" Brake Off"); + } } - } - if(brakeButton.wasPressed()) { - BrakeStatus = 1; - Serial.print(BrakeStatus); Serial.println(" Running brake activated sequence."); - } + if(brakeButton.wasPressed()) { + BrakeStatus = 1; + Serial.print(BrakeStatus); + Serial.println(" Running brake activated sequence."); + } }//end_readbutton //--------------------------------------------------------------- // Brake lights activated sequence -void brakeActivated(){ - - for (uint8_t i=0; i<(sizeof(third)/sizeof((third)[0])); i++) { - leds[third[i]] = black; - } - for (uint8_t i=0; i<(sizeof(center)/sizeof((center)[0])); i++) { - leds[center[i]] = brakeRed; - } - FastLED.show(); - delay(200); - - - for (uint8_t i=0; i<(sizeof(first)/sizeof((first)[0])); i++) { - leds[first[i]] = brakeRed; - } - FastLED.show(); - delay(200); - - - for (uint8_t i=0; i<(sizeof(first)/sizeof((first)[0])); i++) { - leds[first[i]] = accent; - } - for (uint8_t i=0; i<(sizeof(second)/sizeof((second)[0])); i++) { - leds[second[i]] = brakeRed; - } - FastLED.show(); - delay(200); - - - for (uint8_t i=0; i<(sizeof(first)/sizeof((first)[0])); i++) { - leds[first[i]] = black; - } - for (uint8_t i=0; i<(sizeof(second)/sizeof((second)[0])); i++) { - leds[second[i]] = accent; - } - for (uint8_t i=0; i<(sizeof(third)/sizeof((third)[0])); i++) { - leds[third[i]] = brakeRed; - } - FastLED.show(); - delay(200); +void brakeActivated() { + + for (uint8_t i = 0; i < (sizeof(third) / sizeof((third)[0])); i++) { + leds[third[i]] = black; + } + for (uint8_t i = 0; i < (sizeof(center) / sizeof((center)[0])); i++) { + leds[center[i]] = brakeRed; + } + FastLED.show(); + delay(200); + + + for (uint8_t i = 0; i < (sizeof(first) / sizeof((first)[0])); i++) { + leds[first[i]] = brakeRed; + } + FastLED.show(); + delay(200); + + + for (uint8_t i = 0; i < (sizeof(first) / sizeof((first)[0])); i++) { + leds[first[i]] = accent; + } + for (uint8_t i = 0; i < (sizeof(second) / sizeof((second)[0])); i++) { + leds[second[i]] = brakeRed; + } + FastLED.show(); + delay(200); + + + for (uint8_t i = 0; i < (sizeof(first) / sizeof((first)[0])); i++) { + leds[first[i]] = black; + } + for (uint8_t i = 0; i < (sizeof(second) / sizeof((second)[0])); i++) { + leds[second[i]] = accent; + } + for (uint8_t i = 0; i < (sizeof(third) / sizeof((third)[0])); i++) { + leds[third[i]] = brakeRed; + } + FastLED.show(); + delay(200); }//end_brakeLightsOn //--------------------------------------------------------------- // Brake lights On -void brakeOn(){ - fill_solid(leds,NUM_LEDS,CRGB::Black); - for (uint8_t i=0; i<(sizeof(third)/sizeof((third)[0])); i++) { - leds[third[i]] = brakeRed; - } +void brakeOn() { + fill_solid(leds, NUM_LEDS, CRGB::Black); + for (uint8_t i = 0; i < (sizeof(third) / sizeof((third)[0])); i++) { + leds[third[i]] = brakeRed; + } } //--------------------------------------------------------------- // Brake lights Off -void brakeOff(){ - fill_solid(leds,NUM_LEDS,CRGB::Black); - for (uint8_t i=0; i<(sizeof(third)/sizeof((third)[0])); i++) { - leds[third[i]] = brakeDimRed; // use dim red - } +void brakeOff() { + fill_solid(leds, NUM_LEDS, CRGB::Black); + for (uint8_t i = 0; i < (sizeof(third) / sizeof((third)[0])); i++) { + leds[third[i]] = brakeDimRed; // use dim red + } } diff --git a/breath_effect_v2.ino b/breath_effect_v2.ino index 8f66b38..da84c66 100644 --- a/breath_effect_v2.ino +++ b/breath_effect_v2.ino @@ -2,10 +2,15 @@ // Breath effect (pulse from hueA to hueB) // Marc Miller, 2015 //*************************************************************** + #include "FastLED.h" -#define LED_TYPE NEOPIXEL -#define DATA_PIN 6 -#define NUM_LEDS 12 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; static float pulseSpeed = 0.4; // Larger value gives faster pulse. @@ -26,25 +31,26 @@ static float delta = (valueMax - valueMin) / 2.35040238; // Do Not Edit //--------------------------------------------------------------- -void setup(){ - delay(1000); // Power-up delay - //Serial.begin(57600); // Allows serial monitor output (check baud rate) - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); +void setup() { + delay(1000); // Power-up delay + //Serial.begin(57600); // Allows serial monitor output (check baud rate) + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); } //--------------------------------------------------------------- -void loop(){ - float dV = ((exp(sin(pulseSpeed * millis()/2000.0*PI)) -0.36787944) * delta); - val = valueMin + dV; - hue = map(val, valueMin, valueMax, hueA, hueB); // Map hue based on current val - sat = map(val, valueMin, valueMax, satA, satB); // Map sat based on current val - - for (int i = 0; i < NUM_LEDS; i++) { - leds[i] = CHSV(hue, sat, val); - } - //FastLED.show(); - FastLED.delay(20); - - //Serial.print("FPS: "); Serial.println(LEDS.getFPS()); // Display FPS in serial monitor +void loop() { + float dV = ((exp(sin(pulseSpeed * millis() / 2000.0 * PI)) - 0.36787944) * delta); + val = valueMin + dV; + hue = map(val, valueMin, valueMax, hueA, hueB); // Map hue based on current val + sat = map(val, valueMin, valueMax, satA, satB); // Map sat based on current val + + for (int i = 0; i < NUM_LEDS; i++) { + leds[i] = CHSV(hue, sat, val); + } + //FastLED.show(); + FastLED.delay(20); + + //Serial.print("FPS: "); Serial.println(LEDS.getFPS()); // Display FPS in serial monitor } // ----End main loop---- diff --git a/candy_cane_stripes.ino b/candy_cane_stripes.ino index 9413d3f..0c2334e 100644 --- a/candy_cane_stripes.ino +++ b/candy_cane_stripes.ino @@ -11,26 +11,28 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; -#define BRIGHTNESS 70 + //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1500); // Startup delay - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- -void loop() -{ - candyCane(); +void loop() { + candyCane(); }//end_main_loop @@ -38,55 +40,54 @@ void loop() //--------------------------------------------------------------- //Draw alternating bands of color, 2 or 3 colors. //When using three colors, color1 is used between the other two colors. -void candyCane(){ - CRGB color1 = CRGB::White; // color used between color 2 (and 3 if used) - CRGB color2 = CRGB::Red; - //CRGB color3 = CHSV(0,170,255); //optional 3rd color - CRGB color3 = CRGB(0,255,0); //optional 3rd color - const uint16_t travelSpeed = 150; - int shiftBy = 1; //shiftBy can be positive or negative (to change direction) - static uint8_t numColors = 3; // Can be either 2 or 3 - static uint8_t stripeLength = 5; //number of pixels per color - static int offset; +void candyCane() { + CRGB color1 = CRGB::White; // color used between color 2 (and 3 if used) + CRGB color2 = CRGB::Red; + //CRGB color3 = CHSV(0,170,255); //optional 3rd color + CRGB color3 = CRGB(0, 255, 0); //optional 3rd color + const uint16_t travelSpeed = 150; + int shiftBy = 1; //shiftBy can be positive or negative (to change direction) + static uint8_t numColors = 3; // Can be either 2 or 3 + static uint8_t stripeLength = 5; //number of pixels per color + static int offset; - EVERY_N_SECONDS(5) { - numColors = random8(2,4); //picks either 2 or 3 - stripeLength = random8(3,6); //picks random length - } - - EVERY_N_MILLISECONDS(travelSpeed) { - if (numColors==2) { - for (uint8_t i=0; i0) { //for positive shiftBy - if (offset>=NUM_LEDS) offset = 0; - } else { //for negitive shiftBy - if (offset<0) offset = NUM_LEDS; - } + offset = offset + shiftBy; + if (shiftBy > 0) { //for positive shiftBy + if (offset >= NUM_LEDS) offset = 0; + } else { //for negitive shiftBy + if (offset < 0) offset = NUM_LEDS; + } - }//end EVERY_N + }//end EVERY_N }//end candyCane diff --git a/change_color_with_button.ino b/change_color_with_button.ino index a9f9580..d1e6705 100644 --- a/change_color_with_button.ino +++ b/change_color_with_button.ino @@ -23,36 +23,36 @@ Button Push_Button(ButtonPin, true, true, 100); //--------------------------------------------------------------- #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; -#define BRIGHTNESS 128 uint8_t hue; //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1500); // Startup delay - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); } //--------------------------------------------------------------- -void loop() -{ - readbutton(); // check the button to see if it's pressed +void loop() { + readbutton(); // check the button to see if it's pressed - fill_solid( leds, NUM_LEDS, CHSV(hue,255,255) ); //set color of pixels + fill_solid( leds, NUM_LEDS, CHSV(hue, 255, 255) ); //set color of pixels - FastLED.show(); // display the pixels + FastLED.show(); // display the pixels }//end_main_loop @@ -60,19 +60,19 @@ void loop() //--------------------------------------------------------------- //Check the button and set the appropriate flag void readbutton() { - Push_Button.read(); // check the state of the button - - if(Push_Button.isPressed()) { - // To make the color change faster when the button is - // held down, you can either reduce the value of - // EVERY_N_MILLISECONDS, or you can add a larger value - // to hue so it increments faster. - // You can also subtract a value from hue to cycle - // through the color wheel in the oposite direction. - - EVERY_N_MILLISECONDS(20) { - hue = hue + 1; //can be either + or - some value + Push_Button.read(); // check the state of the button + + if(Push_Button.isPressed()) { + // To make the color change faster when the button is + // held down, you can either reduce the value of + // EVERY_N_MILLISECONDS, or you can add a larger value + // to hue so it increments faster. + // You can also subtract a value from hue to cycle + // through the color wheel in the oposite direction. + + EVERY_N_MILLISECONDS(20) { + hue = hue + 1; //can be either + or - some value + } } - } }//end_readbutton diff --git a/chase_target_values_verA.ino b/chase_target_values_verA.ino index 576e137..8503bc0 100644 --- a/chase_target_values_verA.ino +++ b/chase_target_values_verA.ino @@ -9,11 +9,12 @@ //--------------------------------------------------------------- #include "FastLED.h" -#define LED_TYPE NEOPIXEL // *Update to your strip type. NEOPIXEL, APA102, LPD8806, etc.. -#define DATA_PIN 6 // *Set this to your data pin. -#define NUM_LEDS 12 // *Update to the number of pixels in your strip. -//#define COLOR_ORDER BGR -#define MASTER_BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 CRGB leds[NUM_LEDS]; @@ -25,66 +26,76 @@ int lowCutoff = 50; //--------------------------------------------------------------- -void setup() { - delay(1500); - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(MASTER_BRIGHTNESS); - Serial.begin(115200); // Allows serial output (check baud rate) +void setup() { + delay(1500); + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial output (check baud rate) } //--------------------------------------------------------------- -void loop() { - // Assign random target values whenever count is zero. - if (count == 0){ - for (int i=0; i < NUM_LEDS; i++){ - target[random8(NUM_LEDS)] = random8(); // Pick random pixels, assign random values. - if (target[i] < lowCutoff){ - target[i] = 0; // Force low values to clamp to zero. - } - } - count = random8(35,70); // Pick a new count value. - Serial.println("*New targets assigned!*"); - } - - - for (int i=0; i < NUM_LEDS; i++){ - // Check current values against target values. - if (leds[i].r < target[i]){ // less then the target, so fade up. - delta = (target[i] - leds[i].r) / 5; - if (leds[i].r + delta >= target[i]){ - leds[i].r = target[i]; // limit to target. - } - else { leds[i].r += delta; } +void loop() { + // Assign random target values whenever count is zero. + if (count == 0) { + for (int i = 0; i < NUM_LEDS; i++) { + target[random8(NUM_LEDS)] = random8(); // Pick random pixels, assign random values. + if (target[i] < lowCutoff) { + target[i] = 0; // Force low values to clamp to zero. + } + } + count = random8(35, 70); // Pick a new count value. + Serial.println("*New targets assigned!*"); } - else { // greater then the target, so fade down. - delta = ((leds[i].r - target[i])/8) + 1; // +1 so delta is always at least 1. - if (leds[i].r - delta <= target[i]){ - leds[i].r = target[i]; // limit to target. - } - else { leds[i].r -= delta; } - } - if (i == 0){ temp = delta; } // Save first pixel's delta number to print below. + for (int i = 0; i < NUM_LEDS; i++) { + // Check current values against target values. + if (leds[i].r < target[i]) { // less then the target, so fade up. + delta = (target[i] - leds[i].r) / 5; + if (leds[i].r + delta >= target[i]) { + leds[i].r = target[i]; // limit to target. + } else { + leds[i].r += delta; + } + } + + else { // greater then the target, so fade down. + delta = ((leds[i].r - target[i]) / 8) + 1; // +1 so delta is always at least 1. + if (leds[i].r - delta <= target[i]) { + leds[i].r = target[i]; // limit to target. + } else { + leds[i].r -= delta; + } + } + if (i == 0) { + temp = delta; // Save first pixel's delta number to print below. + } + + + // Continously fade target to zero. + if (target[i] > lowCutoff) { + target[i] -= 2; // Fade by this ammount. + } else { + target[i] = 0; // If target is less then lowCutoff, clamp to zero. + } + + + }//end of looping over pixels. + + FastLED.show(); // Display the leds[] array. + + // Print out info for led[0] to follow the numbers. + Serial.print("c: "); + Serial.print(count); + Serial.print("\t target: "); + Serial.print(target[0]); + Serial.print("\t led[0].r: "); + Serial.print(leds[0].r); + Serial.print("\t delta: "); + Serial.println(temp); + + count--; // reduce count by one. + delay(10); - // Continously fade target to zero. - if (target[i] > lowCutoff){ - target[i] -= 2; // Fade by this ammount. - } - else { target[i] = 0; } // If target is less then lowCutoff, clamp to zero. - - - }//end of looping over pixels. - - FastLED.show(); // Display the leds[] array. - - // Print out info for led[0] to follow the numbers. - Serial.print("c: "); Serial.print(count); - Serial.print("\t target: "); Serial.print(target[0]); - Serial.print("\t led[0].r: "); Serial.print(leds[0].r); - Serial.print("\t delta: "); Serial.println(temp); - - count--; // reduce count by one. - delay(10); - }//end main loop diff --git a/chase_target_values_verB.ino b/chase_target_values_verB.ino index 6f37b92..03eabf6 100644 --- a/chase_target_values_verB.ino +++ b/chase_target_values_verB.ino @@ -11,13 +11,15 @@ //--------------------------------------------------------------- #include "FastLED.h" -#define LED_TYPE NEOPIXEL // *Update to your strip type. NEOPIXEL, APA102, LPD8806, etc.. -#define DATA_PIN 6 // *Set this to your data pin. -#define NUM_LEDS 12 // *Update to the number of pixels in your strip. -//#define COLOR_ORDER BGR -#define MASTER_BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 CRGB leds[NUM_LEDS]; + CHSV leds_vu[NUM_LEDS]; // FastLED array using HSV. int target[NUM_LEDS]; // Array to store target brightness values. @@ -30,93 +32,98 @@ int lowCutoff = 30; // ***** A few color combinations to try out: ***** int hue_high = 0; // red for high values with, int hue_low = 96; // green for low values. - // or +// or //int hue_high = 96; // green for high values with, //int hue_low = 192; // purple for low values. - // or +// or //int hue_high = 84; // yellow-green for high values. //int hue_low = 56; // orange for low values. //--------------------------------------------------------------- -void setup() { - delay(1500); - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(MASTER_BRIGHTNESS); - Serial.begin(115200); // Allows serial output (check baud rate) +void setup() { + delay(1500); + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial output (check baud rate) } //--------------------------------------------------------------- -void loop() { - // Assign random target values whenever count is zero. - if (count == 0){ - for (int i=0; i < NUM_LEDS; i++){ - target[random8(NUM_LEDS)] = random8(); // Pick random pixels, assign random values. - if (target[i] < lowCutoff){ - target[i] = 0; // Force low values to clamp to zero. - } - } - count = random8(35,70); // Pick a new count value. - Serial.println("*New targets assigned!*"); - } - - - for (int i=0; i < NUM_LEDS; i++){ - // Check current values against target values. - if (leds_vu[i].value < target[i]){ // less then the target, so fade up. - delta = (leds_vu[i].value - target[i]) / 5; - if (leds_vu[i].value + delta >= target[i]){ - leds_vu[i].value = target[i]; // limit to target. - } - else { - leds_vu[i].value += delta; - } - } - - else { // greater then the target, so fade down. - delta = ((leds_vu[i].value - target[i])/8) + 1; // +1 so delta is always at least 1. - if (leds_vu[i].value - delta <= target[i]){ - leds_vu[i].value = target[i]; // limit to target. - } - else { - leds_vu[i].value -= delta; - } +void loop() { + // Assign random target values whenever count is zero. + if (count == 0) { + for (int i = 0; i < NUM_LEDS; i++) { + target[random8(NUM_LEDS)] = random8(); // Pick random pixels, assign random values. + if (target[i] < lowCutoff) { + target[i] = 0; // Force low values to clamp to zero. + } + } + count = random8(35, 70); // Pick a new count value. + Serial.println("*New targets assigned!*"); } - if (i == 0){ temp = delta; } // Save first pixel's delta number to print below. - // Tweak hue color based on brightness. - int c_hue = constrain(leds_vu[i].value,lowCutoff,highCutoff); - leds_vu[i].hue = map(c_hue, lowCutoff, highCutoff, hue_low, hue_high); - // map(valueIn, fromLow, fromHigh, toLow, toHigh) - leds_vu[i].saturation = 255; // Set saturation to full. - - // Copy the HSV leds_vu[] data to the leds[] array. - leds[i] = leds_vu[i]; - // FastLED will automatically convert HSV to RGB data. Converting from HSV - // to RGB is very fast and also accurate. It is possible to convert from - // RGB to HSV, but it is not automatic, not totally acurate, and not as fast. - - // Continously fade target to zero. - if (target[i] > lowCutoff){ - target[i] -= 2; // Fade by this ammount. - } - else { - target[i] = 0; // If target less then lowCutoff, clamp to zero. - } + for (int i = 0; i < NUM_LEDS; i++) { + // Check current values against target values. + if (leds_vu[i].value < target[i]) { // less then the target, so fade up. + delta = (leds_vu[i].value - target[i]) / 5; + if (leds_vu[i].value + delta >= target[i]) { + leds_vu[i].value = target[i]; // limit to target. + } else { + leds_vu[i].value += delta; + } + } + + else { // greater then the target, so fade down. + delta = ((leds_vu[i].value - target[i]) / 8) + 1; // +1 so delta is always at least 1. + if (leds_vu[i].value - delta <= target[i]) { + leds_vu[i].value = target[i]; // limit to target. + } else { + leds_vu[i].value -= delta; + } + } + if (i == 0) { + temp = delta; // Save first pixel's delta number to print below. + } + + // Tweak hue color based on brightness. + int c_hue = constrain(leds_vu[i].value, lowCutoff, highCutoff); + leds_vu[i].hue = map(c_hue, lowCutoff, highCutoff, hue_low, hue_high); + // map(valueIn, fromLow, fromHigh, toLow, toHigh) + + leds_vu[i].saturation = 255; // Set saturation to full. + + // Copy the HSV leds_vu[] data to the leds[] array. + leds[i] = leds_vu[i]; + // FastLED will automatically convert HSV to RGB data. Converting from HSV + // to RGB is very fast and also accurate. It is possible to convert from + // RGB to HSV, but it is not automatic, not totally acurate, and not as fast. + + // Continously fade target to zero. + if (target[i] > lowCutoff) { + target[i] -= 2; // Fade by this ammount. + } else { + target[i] = 0; // If target less then lowCutoff, clamp to zero. + } + + }//end of looping over pixels. + + FastLED.show(); // Display the leds[] array. + + // Print out info for led[0] to understand how the numbers are changing. + Serial.print("c: "); + Serial.print(count); + Serial.print("\t target: "); + Serial.print(target[0]); + Serial.print("\t leds_vu[0].hue: "); + Serial.print(leds_vu[0].hue); + Serial.print("\t leds_vu[0].value: "); + Serial.print(leds_vu[0].value); + Serial.print("\t delta: "); + Serial.println(temp); + + count--; // reduce count by one. + delay(10); - }//end of looping over pixels. - - FastLED.show(); // Display the leds[] array. - - // Print out info for led[0] to understand how the numbers are changing. - Serial.print("c: "); Serial.print(count); - Serial.print("\t target: "); Serial.print(target[0]); - Serial.print("\t leds_vu[0].hue: "); Serial.print(leds_vu[0].hue); - Serial.print("\t leds_vu[0].value: "); Serial.print(leds_vu[0].value); - Serial.print("\t delta: "); Serial.println(temp); - - count--; // reduce count by one. - delay(10); - }//end main loop diff --git a/color_temperature_demo.ino b/color_temperature_demo.ino index 7e52210..620da77 100644 --- a/color_temperature_demo.ino +++ b/color_temperature_demo.ino @@ -6,12 +6,13 @@ //*************************************************************** #include "FastLED.h" -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 -#define BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; #define DISPLAYTIME 4 //number of SECONDS to show each color temperature @@ -20,11 +21,12 @@ uint8_t temp; //current tempature_# being displayed //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay( 1500 ); // power-up safety delay - FastLED.addLeds(leds, NUM_LEDS).setCorrection( TypicalSMD5050 ); - FastLED.setBrightness( BRIGHTNESS ); - FastLED.clear(); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay( 1500 ); // power-up safety delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness( BRIGHTNESS ); + FastLED.clear(); } //--------------------------------------------------------------- @@ -52,62 +54,89 @@ void setup() { //--------------------------------------------------------------- void loop() { - switch (temp) { + switch (temp) { case 0: - FastLED.setTemperature( TEMPERATURE_0 ); break; + FastLED.setTemperature( TEMPERATURE_0 ); + break; case 1: - FastLED.setTemperature( TEMPERATURE_1 ); break; + FastLED.setTemperature( TEMPERATURE_1 ); + break; case 2: - FastLED.setTemperature( TEMPERATURE_2 ); break; + FastLED.setTemperature( TEMPERATURE_2 ); + break; case 3: - FastLED.setTemperature( TEMPERATURE_3 ); break; + FastLED.setTemperature( TEMPERATURE_3 ); + break; case 4: - FastLED.setTemperature( TEMPERATURE_4 ); break; + FastLED.setTemperature( TEMPERATURE_4 ); + break; case 5: - FastLED.setTemperature( TEMPERATURE_5 ); break; + FastLED.setTemperature( TEMPERATURE_5 ); + break; case 6: - FastLED.setTemperature( TEMPERATURE_6 ); break; + FastLED.setTemperature( TEMPERATURE_6 ); + break; case 7: - FastLED.setTemperature( TEMPERATURE_7 ); break; + FastLED.setTemperature( TEMPERATURE_7 ); + break; case 8: - FastLED.setTemperature( TEMPERATURE_8 ); break; + FastLED.setTemperature( TEMPERATURE_8 ); + break; case 9: - FastLED.setTemperature( TEMPERATURE_9 ); break; + FastLED.setTemperature( TEMPERATURE_9 ); + break; case 10: - FastLED.setTemperature( TEMPERATURE_10 ); break; + FastLED.setTemperature( TEMPERATURE_10 ); + break; case 11: - FastLED.setTemperature( TEMPERATURE_11 ); break; + FastLED.setTemperature( TEMPERATURE_11 ); + break; case 12: - FastLED.setTemperature( TEMPERATURE_12 ); break; + FastLED.setTemperature( TEMPERATURE_12 ); + break; case 13: - FastLED.setTemperature( TEMPERATURE_13 ); break; + FastLED.setTemperature( TEMPERATURE_13 ); + break; case 14: - FastLED.setTemperature( TEMPERATURE_14 ); break; + FastLED.setTemperature( TEMPERATURE_14 ); + break; case 15: - FastLED.setTemperature( TEMPERATURE_15 ); break; + FastLED.setTemperature( TEMPERATURE_15 ); + break; case 16: - FastLED.setTemperature( TEMPERATURE_16 ); break; + FastLED.setTemperature( TEMPERATURE_16 ); + break; case 17: - FastLED.setTemperature( TEMPERATURE_17 ); break; + FastLED.setTemperature( TEMPERATURE_17 ); + break; case 18: - FastLED.setTemperature( TEMPERATURE_18 ); break; + FastLED.setTemperature( TEMPERATURE_18 ); + break; case 19: - FastLED.setTemperature( TEMPERATURE_19 ); break; - } + FastLED.setTemperature( TEMPERATURE_19 ); + break; + } - fill_solid(leds, NUM_LEDS, CRGB(255,255,255) ); //fill with white - if (temp==0) { leds[0]=CRGB::Red; leds[1]=CRGB::Green; leds[2]=CRGB::Blue; } + fill_solid(leds, NUM_LEDS, CRGB(255, 255, 255) ); //fill with white + if (temp == 0) { + leds[0] = CRGB::Red; + leds[1] = CRGB::Green; + leds[2] = CRGB::Blue; + } - FastLED.show(); //display pixels + FastLED.show(); //display pixels - EVERY_N_SECONDS(DISPLAYTIME) { - FastLED.clear(); - FastLED.show(); - delay(BLACKOUTTIME); - temp++; - if (temp == 20) { temp = 0; } //reset - Serial.print("Current temperature: "); Serial.println(temp); //print temp # to serial monitor - } + EVERY_N_SECONDS(DISPLAYTIME) { + FastLED.clear(); + FastLED.show(); + delay(BLACKOUTTIME); + temp++; + if (temp == 20) { + temp = 0; //reset + } + Serial.print("Current temperature: "); + Serial.println(temp); //print temp # to serial monitor + } }//end_main_loop diff --git a/custom_color_array.ino b/custom_color_array.ino index 6f77ea0..6c4e184 100644 --- a/custom_color_array.ino +++ b/custom_color_array.ino @@ -5,49 +5,50 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB -#define BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint8_t colorPick; // Custom color array CRGB colorArray[] = { - CRGB::Red, - CRGB::Grey, - CRGB::Blue, - CRGB(0,255,0), - CHSV(195,255,255), + CRGB::Red, + CRGB::Grey, + CRGB::Blue, + CRGB(0, 255, 0), + CHSV(195, 255, 255), }; //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check your baud rate) - delay(2000); // Startup delay - FastLED.addLeds(leds, NUM_LEDS); // ***For strips using Clock. - //FastLED.addLeds(leds, NUM_LEDS); // ***For Clock-less strips. - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check your baud rate) + delay(2000); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - //pick a random color from the custom color array - colorPick = random8( sizeof(colorArray) / sizeof(colorArray[0]) ); - - for (uint8_t i = 0; i < NUM_LEDS; i++) { - leds[i] = colorArray[colorPick]; - FastLED.show(); - delay(50); - fadeToBlackBy(leds, NUM_LEDS, 220); - } - + //pick a random color from the custom color array + colorPick = random8( sizeof(colorArray) / sizeof(colorArray[0]) ); + + for (uint8_t i = 0; i < NUM_LEDS; i++) { + leds[i] = colorArray[colorPick]; + FastLED.show(); + delay(50); + fadeToBlackBy(leds, NUM_LEDS, 220); + } + }//end_main_loop diff --git a/cylon_color_changing.ino b/cylon_color_changing.ino index c94dd8f..be7999c 100644 --- a/cylon_color_changing.ino +++ b/cylon_color_changing.ino @@ -14,21 +14,21 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB -#define BRIGHTNESS 255 -CRGB leds[NUM_LEDS]; +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 +CRGB leds[NUM_LEDS]; // Custom colors to choose from CRGB colorArray[] = { - CRGB(0,255,0), //green - CRGB(180,180,180), //a dim white - CHSV(0,255,255), //red - CRGB::Grey, + CRGB(0, 255, 0), //green + CRGB(180, 180, 180), //a dim white + CHSV(0, 255, 255), //red + CRGB::Grey, }; uint8_t numberOfColors = sizeof(colorArray) / sizeof(colorArray[0]); @@ -38,86 +38,92 @@ uint8_t pos; //dot position //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check your baud rate) - delay(2000); // Startup delay - FastLED.addLeds(leds, NUM_LEDS); // ***For strips using Clock. - //FastLED.addLeds(leds, NUM_LEDS); // ***For Clock-less strips. - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check your baud rate) + delay(2000); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - //Comment or un-comment one of these examples to try each out. - cylon_cc1(); - //cylon_cc2(); - - FastLED.show(); - + //Comment or un-comment one of these examples to try each out. + cylon_cc1(); + //cylon_cc2(); + + FastLED.show(); + }//end_main_loop //--------------------------------------------------------------- void colorChange(boolean r) { - // Change the color. - // If r = 0, the next color in the array is picked and then - // it cycles back around to the first color in the array. - // If r = 1 then a random color is picked from the array. - - if (r == 0) { - colorChoice = colorChoice + 1; - if (colorChoice >= numberOfColors) { colorChoice = 0; } - //Serial.print("cycling: "); Serial.println(colorChoice); - } else { - colorChoice = random8(numberOfColors); - //Serial.print("random: "); Serial.println(colorChoice); - } - + // Change the color. + // If r = 0, the next color in the array is picked and then + // it cycles back around to the first color in the array. + // If r = 1 then a random color is picked from the array. + + if (r == 0) { + colorChoice = colorChoice + 1; + if (colorChoice >= numberOfColors) { + colorChoice = 0; + } + //Serial.print("cycling: "); Serial.println(colorChoice); + } else { + colorChoice = random8(numberOfColors); + //Serial.print("random: "); Serial.println(colorChoice); + } + } //--------------------------------------------------------------- void cylon_cc1() { - //cylon effect with color change based on time - - static uint8_t delta = 1; //direction of travel - - EVERY_N_MILLISECONDS(200) { - colorChange(0); //set next color - } - - EVERY_N_MILLISECONDS(60) { - fadeToBlackBy(leds, NUM_LEDS, 5); - leds[pos] = colorArray[colorChoice]; - pos = pos + delta; - if (pos == NUM_LEDS-1) { delta = -1; } //change direction - if (pos == 0) { delta = 1; } //change direction - } + //cylon effect with color change based on time + + static uint8_t delta = 1; //direction of travel + + EVERY_N_MILLISECONDS(200) { + colorChange(0); //set next color + } + + EVERY_N_MILLISECONDS(60) { + fadeToBlackBy(leds, NUM_LEDS, 5); + leds[pos] = colorArray[colorChoice]; + pos = pos + delta; + if (pos == NUM_LEDS - 1) { + delta = -1; //change direction + } + if (pos == 0) { + delta = 1; //change direction + } + } }//end_cylon_cc1 //--------------------------------------------------------------- void cylon_cc2() { - //cylon effect with color change when end of strip is reached - - static uint8_t delta = 1; //direction of travel - - EVERY_N_MILLISECONDS(60) { - fadeToBlackBy(leds, NUM_LEDS, 200); - leds[pos] = colorArray[colorChoice]; - pos = pos + delta; - if (pos == NUM_LEDS-1) { - delta = -1; //change direction - colorChange(1); //random next color - } - if (pos == 0) { - delta = 1; //change direction - colorChange(1); //random next color + //cylon effect with color change when end of strip is reached + + static uint8_t delta = 1; //direction of travel + + EVERY_N_MILLISECONDS(60) { + fadeToBlackBy(leds, NUM_LEDS, 200); + leds[pos] = colorArray[colorChoice]; + pos = pos + delta; + if (pos == NUM_LEDS - 1) { + delta = -1; //change direction + colorChange(1); //random next color + } + if (pos == 0) { + delta = 1; //change direction + colorChange(1); //random next color + } } - } }//end_cylon_cc2 diff --git a/double_up_pixels_example.ino b/double_up_pixels_example.ino index 428df17..91416cd 100644 --- a/double_up_pixels_example.ino +++ b/double_up_pixels_example.ino @@ -4,17 +4,22 @@ // // Marc Miller, 2015 //*************************************************************** + #include "FastLED.h" -#define LED_TYPE NEOPIXEL -#define DATA_PIN 6 // Update for your pin number -#define NUM_LEDS 12 // Update to number of pixels in your LED strip +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; // For DMX, the R,G,B for each pixel will be assigned a channel number, thus: -uint16_t DMXchan = 3*NUM_LEDS; // Number of DMX channels. - // Actually, the above would only need to be half of 3*NUM_LEDS since we are - // doubling pixels up for this test, but I'm not worrying about that. - +uint16_t DMXchan = 3 * NUM_LEDS; // Number of DMX channels. +// Actually, the above would only need to be half of 3*NUM_LEDS since we are +// doubling pixels up for this test, but I'm not worrying about that. + uint16_t pixel = 0; // for storing a pixel number uint16_t chanR = 0; // for storing the Red channel value uint16_t chanG = 0; // for storing the Green channel value @@ -22,88 +27,105 @@ uint16_t chanB = 0; // for storing the Blue channel value //--------------------------------------------------------------- -void setup(){ - delay(1000); // Power-up delay - Serial.begin(57600); // Allows serial monitor output (check baud rate) - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); +void setup() { + delay(1000); // Power-up delay + Serial.begin(57600); // Allows serial monitor output (check baud rate) + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); } //--------------------------------------------------------------- -void loop(){ - Serial.println("..........................................................."); - for (pixel = 0; pixel < NUM_LEDS; pixel++){ - if ((pixel & 0x01) == 0){ // Checks least significant bit to determine if even or odd - // pixel number is an even - Serial.print(" pixel "); Serial.print(pixel); Serial.print(" assigned: "); - for (uint8_t c = 0; c < 3; c++){ - DMXchan = 3*((pixel+2)/2)-2+c; - Serial.print(" chan="); Serial.print(DMXchan); - } - delay(50); - } else { - // pixel number is odd number - Serial.print(" pixel "); Serial.print(pixel); Serial.print(" assigned: "); - for (uint8_t c = 0; c < 3; c++){ - DMXchan = 3*((pixel+1)/2)-2+c; - Serial.print(" chan="); Serial.print(DMXchan); - } - delay(50); - Serial.println(" "); - } - Serial.println(" "); - } - delay(200); - - - //================================================================ - // Read incoming serial DMX data. - // Figure out pixel number based on incomming DMX channel number. - //================================================================ - - Serial.println("******[SIMULATING RECEIVING CHANNELS, EACH WITH VALUE 255]******"); - int count = 0; // Using count to switch between R,G, and B LEDs in each pixel. - - // Starting chan at 1, and adding +1 to DMXchan since DMX protocol has channels start at 1. - for (uint16_t chan = 1; chan < DMXchan+1; chan++){ - pixel = ((chan+2)/3*2)-2; // Calculate what pixel the incoming channel belongs to. - - Serial.print(" DMXChan "); Serial.print(chan); - Serial.print(" goes to pixel "); Serial.print(pixel); - - if (count == 0){ - Serial.print(" Adding R value, and duplicating to pixel "); Serial.print(pixel+1); Serial.println(" "); - chanR = 255; - chanG = 0; - chanB = 0; +void loop() { + Serial.println("..........................................................."); + for (pixel = 0; pixel < NUM_LEDS; pixel++) { + if ((pixel & 0x01) == 0) { // Checks least significant bit to determine if even or odd + // pixel number is an even + Serial.print(" pixel "); + Serial.print(pixel); + Serial.print(" assigned: "); + for (uint8_t c = 0; c < 3; c++) { + DMXchan = 3 * ((pixel + 2) / 2) - 2 + c; + Serial.print(" chan="); + Serial.print(DMXchan); + } + delay(50); + } else { + // pixel number is odd number + Serial.print(" pixel "); + Serial.print(pixel); + Serial.print(" assigned: "); + for (uint8_t c = 0; c < 3; c++) { + DMXchan = 3 * ((pixel + 1) / 2) - 2 + c; + Serial.print(" chan="); + Serial.print(DMXchan); + } + delay(50); + Serial.println(" "); + } + Serial.println(" "); } - if (count == 1){ - Serial.print(" Adding G value, and duplicating to pixel "); Serial.print(pixel+1); Serial.println(" "); - chanG = 255; - } - if (count == 2){ - Serial.print(" Adding B value, and duplicating to pixel "); Serial.print(pixel+1); Serial.println(" "); - chanB = 255; - } - count++; - - leds[pixel] = CRGB(chanR,chanG,chanB); - FastLED.show(); delay(200); - leds[pixel+1] = CRGB(chanR,chanG,chanB); // Dublicate color to next pixel - FastLED.show(); - delay(700); - - if (count == 3){ - leds[pixel] = CRGB::Black; - leds[pixel+1] = CRGB::Black; - FastLED.show(); + + + //================================================================ + // Read incoming serial DMX data. + // Figure out pixel number based on incomming DMX channel number. + //================================================================ + + Serial.println("******[SIMULATING RECEIVING CHANNELS, EACH WITH VALUE 255]******"); + int count = 0; // Using count to switch between R,G, and B LEDs in each pixel. + + // Starting chan at 1, and adding +1 to DMXchan since DMX protocol has channels start at 1. + for (uint16_t chan = 1; chan < DMXchan + 1; chan++) { + pixel = ((chan + 2) / 3 * 2) - 2; // Calculate what pixel the incoming channel belongs to. + + Serial.print(" DMXChan "); + Serial.print(chan); + Serial.print(" goes to pixel "); + Serial.print(pixel); + + if (count == 0) { + Serial.print(" Adding R value, and duplicating to pixel "); + Serial.print(pixel + 1); + Serial.println(" "); + chanR = 255; + chanG = 0; + chanB = 0; + } + if (count == 1) { + Serial.print(" Adding G value, and duplicating to pixel "); + Serial.print(pixel + 1); + Serial.println(" "); + chanG = 255; + } + if (count == 2) { + Serial.print(" Adding B value, and duplicating to pixel "); + Serial.print(pixel + 1); + Serial.println(" "); + chanB = 255; + } + count++; + + leds[pixel] = CRGB(chanR, chanG, chanB); + FastLED.show(); + delay(200); + leds[pixel + 1] = CRGB(chanR, chanG, chanB); // Dublicate color to next pixel + FastLED.show(); + delay(700); + + if (count == 3) { + leds[pixel] = CRGB::Black; + leds[pixel + 1] = CRGB::Black; + FastLED.show(); + } + if (count > 2) { + count = 0; + } + } - if (count > 2){count = 0;} - - } - delay(500); - Serial.println(" "); + delay(500); + Serial.println(" "); } // ----End main loop---- diff --git a/ease_in_out.ino b/ease_in_out.ino index ce8260e..93417ac 100644 --- a/ease_in_out.ino +++ b/ease_in_out.ino @@ -4,13 +4,15 @@ //Marc Miller, 2015 /*********************************************************************/ #include + #include "FastLED.h" -#define LED_TYPE LPD8806 -#define NUM_LEDS 32 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define COLOR_ORDER GRB -#define MASTER_BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint16_t pos; // pixel postion. @@ -21,10 +23,11 @@ uint8_t timeDelay = 100; // time in ms. Lower number is faster travel. /*********************************************************************/ //PROGRAM SETUP void setup() { - Serial.begin(115200); // Allow for output to serial monitor - delay(3000); // power up safety delay - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(MASTER_BRIGHTNESS); + Serial.begin(115200); // Allow for output to serial monitor + delay(3000); // power up safety delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); }//END SETUP @@ -32,42 +35,42 @@ void setup() { //MAIN LOOP void loop() { - /* - // Uncomment this section to show re-mapped - // values for ease8InOutCubic from 0 to 256. - for (uint16_t i = 0; i < 256; i++) { - uint8_t result = ease8InOutCubic(i); - Serial.print(" i: "); - Serial.print(i); - Serial.print(" "); - Serial.print("result: "); - Serial.println(result); - delay(20); - if (i == 255) { Serial.println("Loop complete."); } - } - Serial.println("Delay for a bit..."); // So you don't hang your serial monitor output. - delay(10000); - */ + /* + // Uncomment this section to show re-mapped + // values for ease8InOutCubic from 0 to 256. + for (uint16_t i = 0; i < 256; i++) { + uint8_t result = ease8InOutCubic(i); + Serial.print(" i: "); + Serial.print(i); + Serial.print(" "); + Serial.print("result: "); + Serial.println(result); + delay(20); + if (i == 255) { Serial.println("Loop complete."); } + } + Serial.println("Delay for a bit..."); // So you don't hang your serial monitor output. + delay(10000); + */ + + // Loop through pixels. + for (uint16_t i = 0; i < NUM_LEDS; i++) { + + // Map pixel position to range of 0-255 that the ease function needs. + mappedValue = map(i, 0, NUM_LEDS - 1, 0, 255); // map(inputValue, fromLow, fromHigh, toLow, toHigh) - // Loop through pixels. - for (uint16_t i = 0; i < NUM_LEDS; i++) { + // Run mappedValue through ease funtion. + mappedValue = ease8InOutCubic(mappedValue); - // Map pixel position to range of 0-255 that the ease function needs. - mappedValue = map(i, 0, NUM_LEDS-1, 0, 255); // map(inputValue, fromLow, fromHigh, toLow, toHigh) + // Map ease value (0-255 range) back to pixel position in range of 0 to NUM_LEDS. + pos = map(mappedValue, 0, 255, 0, NUM_LEDS - 1); // map(inputValue, fromLow, fromHigh, toLow, toHigh) - // Run mappedValue through ease funtion. - mappedValue = ease8InOutCubic(mappedValue); + // Display pixels + leds[pos] = CRGB::Red; + FastLED.show(); + delay(timeDelay); + leds[pos] = CRGB::Black; + FastLED.show(); + } - // Map ease value (0-255 range) back to pixel position in range of 0 to NUM_LEDS. - pos = map(mappedValue, 0, 255, 0, NUM_LEDS-1); // map(inputValue, fromLow, fromHigh, toLow, toHigh) - - // Display pixels - leds[pos] = CRGB::Red; - FastLED.show(); - delay(timeDelay); - leds[pos] = CRGB::Black; - FastLED.show(); - } - - delay(1000); + delay(1000); }//END MAIN LOOP diff --git a/every_n_timer_variable.ino b/every_n_timer_variable.ino index 6a463de..eb751e2 100644 --- a/every_n_timer_variable.ino +++ b/every_n_timer_variable.ino @@ -9,12 +9,13 @@ //--------------------------------------------------------------- #include "FastLED.h" -#define LED_TYPE APA102 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 39 -#define COLOR_ORDER BGR -#define BRIGHTNESS 32 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint16_t timerA = 3000; // How often to run Event A [milliseconds] @@ -23,54 +24,55 @@ boolean counterTriggered = 0; // Event triggered? [1=true, 0=false] //--------------------------------------------------------------- -void setup() { - Serial.begin(115200); // Allows serial output (check baud rate) - delay(3000); // 3 second startup delay - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(BRIGHTNESS); +void setup() { + Serial.begin(115200); // Allows serial output (check baud rate) + delay(3000); // 3 second startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - - // Setting the amount of time for "triggerTimer". - // You can name "triggerTimer" whatever you want. - static CEveryNMilliseconds triggerTimer(timerB); - - EVERY_N_MILLISECONDS(timerA){ - // do Event A stuff - fill_solid(leds, NUM_LEDS, CHSV(random8(),255,128)); - counterTriggered = 1; // Set to True - triggerTimer.reset(); // Start trigger timer - } - - if (counterTriggered == 1) { // Will only be True if Event A has started - if (triggerTimer) { // Check if triggerTimer time reached - // do Event B stuff - for (uint8_t i=0; i(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(128); - Serial.println("Setup done."); +void setup() { + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(2500); // Power-up delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + Serial.println("Setup done."); } //------------------------------------------------------------------ -void loop(){ - static CEveryNSeconds triggerTimer(tTime); - static CEveryNSeconds countTimer(cTime); - static CEveryNSeconds resetTimer(rTime); - - if (firstRun == 1){ - EVERY_N_MILLISECONDS(300){ - fill_solid(leds, NUM_LEDS, CHSV(160,200,70)); // Blue - FastLED.show(); - } - EVERY_N_MILLISECONDS(600){ - FastLED.clear(); - FastLED.show(); - } - EVERY_N_SECONDS(4){ - firstRun = 0; // Set firstRun to false so it won't run again. - resetTriggered = 1; - resetTimer.reset(); // Start reset timer - } - } - - - if (timerTriggered == 1) { - if (triggerTimer) { // check if time reached - Serial.println("Event has been triggered!"); - triggerTimer.setPeriod( random8(8,17) ); // Set a new random trigger time - tTime = triggerTimer.getPeriod(); - timerTriggered = 0; - counterTriggered = 1; - countTimer.reset(); // Start count timer - } else { - EVERY_N_MILLISECONDS(70){ - leds[pos] = CHSV(96,200,190); - pos = (pos+1) % NUM_LEDS; - fadeToBlackBy(leds, NUM_LEDS,80); - leds[0] = CHSV(96,255,255); - FastLED.show(); - } - EVERY_N_SECONDS(1){ - Serial.print(" Next trigger in "); - Serial.print(triggerTimer.getRemaining()); - Serial.println("..."); - } +void loop() { + static CEveryNSeconds triggerTimer(tTime); + static CEveryNSeconds countTimer(cTime); + static CEveryNSeconds resetTimer(rTime); + + if (firstRun == 1) { + EVERY_N_MILLISECONDS(300) { + fill_solid(leds, NUM_LEDS, CHSV(160, 200, 70)); // Blue + FastLED.show(); + } + EVERY_N_MILLISECONDS(600) { + FastLED.clear(); + FastLED.show(); + } + EVERY_N_SECONDS(4) { + firstRun = 0; // Set firstRun to false so it won't run again. + resetTriggered = 1; + resetTimer.reset(); // Start reset timer + } } - } - if (counterTriggered == 1) { - EVERY_N_MILLISECONDS(250){ - FastLED.clear(); - for (uint8_t i=0; i>> Count reached! <<< "); - fill_solid(leds, NUM_LEDS, CRGB::Red); - FastLED.show(); - counterTriggered = 0; - resetTriggered = 1; - resetTimer.reset(); // Start reset timer - } else { - EVERY_N_SECONDS(1){ - Serial.print(" Counting: "); - uint16_t count = countTimer.getElapsed(); - Serial.println(count); - } + + if (counterTriggered == 1) { + EVERY_N_MILLISECONDS(250) { + FastLED.clear(); + for (uint8_t i = 0; i < NUM_LEDS; i = i + 2) { + leds[i] = CHSV(10, 255, 160); + FastLED.show(); + } + } + EVERY_N_MILLISECONDS(500) { + FastLED.clear(); + for (uint8_t i = 1; i < NUM_LEDS; i = i + 2) { + leds[i] = CHSV(32, 255, 100); + FastLED.show(); + } + } + + if (countTimer) { // check if time reached + Serial.println(">>> Count reached! <<< "); + fill_solid(leds, NUM_LEDS, CRGB::Red); + FastLED.show(); + counterTriggered = 0; + resetTriggered = 1; + resetTimer.reset(); // Start reset timer + } else { + EVERY_N_SECONDS(1) { + Serial.print(" Counting: "); + uint16_t count = countTimer.getElapsed(); + Serial.println(count); + } + } } - } - - - if (resetTriggered == 1) { - if (resetTimer) { // check if time reached - Serial.println(" Strip reset. "); - FastLED.clear(); - FastLED.show(); - resetTriggered = 0; // Strip has been reset - timerTriggered = 1; // Look for next event trigger - countTimer.reset(); // Start count timer - triggerTimer.reset(); // Start trigger timer + + + if (resetTriggered == 1) { + if (resetTimer) { // check if time reached + Serial.println(" Strip reset. "); + FastLED.clear(); + FastLED.show(); + resetTriggered = 0; // Strip has been reset + timerTriggered = 1; // Look for next event trigger + countTimer.reset(); // Start count timer + triggerTimer.reset(); // Start trigger timer + } } - } }//----End main loop---- diff --git a/fade_up_down_example.ino b/fade_up_down_example.ino index 6a19781..1a51b82 100644 --- a/fade_up_down_example.ino +++ b/fade_up_down_example.ino @@ -21,13 +21,14 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; -#define BRIGHTNESS 255 uint8_t hue = 0; uint8_t sat = 255; @@ -37,45 +38,48 @@ boolean fadeDirection = 1; // [1=fade up, 0=fade down] //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(2000); // Startup delay - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(2000); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - if (fadeDirection == 1) { //fade up - EVERY_N_MILLISECONDS(3){ - fill_solid( leds, NUM_LEDS, CHSV(hue,sat,val) ); - val = val + 1; - if (val == 255) { - fadeDirection = !fadeDirection; //reverse direction - Serial.print("---fade up done---"); - Serial.print(" fadeDirection: "); Serial.println(fadeDirection); - } + if (fadeDirection == 1) { //fade up + EVERY_N_MILLISECONDS(3) { + fill_solid( leds, NUM_LEDS, CHSV(hue, sat, val) ); + val = val + 1; + if (val == 255) { + fadeDirection = !fadeDirection; //reverse direction + Serial.print("---fade up done---"); + Serial.print(" fadeDirection: "); + Serial.println(fadeDirection); + } + } + } + + if (fadeDirection == 0) { //fade down + EVERY_N_MILLISECONDS(9) { + fill_solid( leds, NUM_LEDS, CHSV(hue, sat, val) ); + val = val - 1; + if (val == 0) { + fadeDirection = !fadeDirection; //reverse direction + Serial.print("--fade down done--"); + Serial.print(" fadeDirection: "); + Serial.println(fadeDirection); + } + } } - } - if (fadeDirection == 0) { //fade down - EVERY_N_MILLISECONDS(9){ - fill_solid( leds, NUM_LEDS, CHSV(hue,sat,val) ); - val = val - 1; - if (val == 0) { - fadeDirection = !fadeDirection; //reverse direction - Serial.print("--fade down done--"); - Serial.print(" fadeDirection: "); Serial.println(fadeDirection); - } + FastLED.show(); + + EVERY_N_MILLISECONDS(90) { //cycle around the color wheel over time + hue++; } - } - - FastLED.show(); - EVERY_N_MILLISECONDS(90){ //cycle around the color wheel over time - hue++; - } - }//end_main_loop diff --git a/fill_gradient_examples.ino b/fill_gradient_examples.ino index a7b61f4..ee061d7 100644 --- a/fill_gradient_examples.ino +++ b/fill_gradient_examples.ino @@ -15,88 +15,90 @@ //--------------------------------------------------------------- #include "FastLED.h" -#define LED_TYPE WS2812B -#define DATA_PIN 11 -//#define CLOCK_PIN 13 -#define NUM_LEDS 12 -#define COLOR_ORDER GRB -#define MASTER_BRIGHTNESS 180 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; -CHSV gsHSV(0,255,255); // grad start color in HSV format -CHSV geHSV(128,255,255); // grad end color in HSV format +CHSV gsHSV(0, 255, 255); // grad start color in HSV format +CHSV geHSV(128, 255, 255); // grad end color in HSV format -CRGB gsRGB(255,0,0); // grad start color in RGB format -CRGB geRGB(0,255,0); // grad end color in RGB format +CRGB gsRGB(255, 0, 0); // grad start color in RGB format +CRGB geRGB(0, 255, 0); // grad end color in RGB format uint8_t num = 0; // stores a number when animating grad - + //--------------------------------------------------------------- -void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // startup delay - FastLED.addLeds(leds, NUM_LEDS); - //FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(MASTER_BRIGHTNESS); +void setup() { + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - EVERY_N_MILLISECONDS(250) { - num = num + 4; - Serial.print(" num = "); Serial.println(num); - - /* ---------------Fill gradient using HSV format--------------- - * All three of these display the same output. - * The first inputs the color directly in HSV values. - * The second uses the HSV colors defined up above. - * The third uses the HSV colors defined up above and shows how to break out the h,s,v parts. - * These gradients are static. - */ - - fill_gradient(leds, 0, CHSV(0,255,255), NUM_LEDS-1, CHSV(128,255,255), SHORTEST_HUES); - //fill_gradient(leds, 0, gsHSV, NUM_LEDS-1, geHSV, SHORTEST_HUES); - //fill_gradient(leds, 0, CHSV(gsHSV.h,gsHSV.s,gsHSV.v), NUM_LEDS-1, CHSV(geHSV.h,geHSV.s,geHSV.v), SHORTEST_HUES); - - - - /*----------- - * This shows how you could operate on the r,g,b parts of a previously defined - * HSV color, or only use some combination of the h, s, or v components. - * This gradient is animated. - */ - - //fill_gradient(leds, 0, CHSV(gsHSV.h+num, random8(100,256), gsHSV.v), NUM_LEDS-1, CHSV(geHSV.h+num, geHSV.s, random8(180,256)), SHORTEST_HUES); - - - - - /* ---------------Fill gradient using RGB format--------------- - * All three of these display the same output. - * The first inputs the color directly in RGB values. - * The second uses the RGB colors defined up above. - * The third uses the RGB colors defined up above and shows how to break out the h,s,v parts. - * These gradients are static. - * *Note* Do NOT use SHORTEST_HUES on the end. - */ - - //fill_gradient_RGB(leds, 0, CRGB(255,0,0), NUM_LEDS-1, CRGB(0,255,0)); - //fill_gradient_RGB(leds, 0, gsRGB, NUM_LEDS-1, geRGB); - //fill_gradient_RGB(leds, 0, CRGB(gsRGB.r, gsRGB.g, gsRGB.b), NUM_LEDS-1, CRGB(geRGB.r, geRGB.g, geRGB.b)); - - - /*---------- - * This shows how you could operate on the r,g,b parts of a previously defined - * RGB color, or only use some combination of the r, g, or b components. - * This gradient is animated. - */ - - //fill_gradient_RGB( leds, 0, CRGB(gsRGB.r+num, gsRGB.g, 255), NUM_LEDS-1, CRGB(0, geRGB.g+num, random8(0,64)) ); - - - - FastLED.show(); //display the pixels - } - + EVERY_N_MILLISECONDS(250) { + num = num + 4; + Serial.print(" num = "); + Serial.println(num); + + /* ---------------Fill gradient using HSV format--------------- + * All three of these display the same output. + * The first inputs the color directly in HSV values. + * The second uses the HSV colors defined up above. + * The third uses the HSV colors defined up above and shows how to break out the h,s,v parts. + * These gradients are static. + */ + + fill_gradient(leds, 0, CHSV(0, 255, 255), NUM_LEDS - 1, CHSV(128, 255, 255), SHORTEST_HUES); + //fill_gradient(leds, 0, gsHSV, NUM_LEDS-1, geHSV, SHORTEST_HUES); + //fill_gradient(leds, 0, CHSV(gsHSV.h,gsHSV.s,gsHSV.v), NUM_LEDS-1, CHSV(geHSV.h,geHSV.s,geHSV.v), SHORTEST_HUES); + + + + /*----------- + * This shows how you could operate on the r,g,b parts of a previously defined + * HSV color, or only use some combination of the h, s, or v components. + * This gradient is animated. + */ + + //fill_gradient(leds, 0, CHSV(gsHSV.h+num, random8(100,256), gsHSV.v), NUM_LEDS-1, CHSV(geHSV.h+num, geHSV.s, random8(180,256)), SHORTEST_HUES); + + + + + /* ---------------Fill gradient using RGB format--------------- + * All three of these display the same output. + * The first inputs the color directly in RGB values. + * The second uses the RGB colors defined up above. + * The third uses the RGB colors defined up above and shows how to break out the h,s,v parts. + * These gradients are static. + * *Note* Do NOT use SHORTEST_HUES on the end. + */ + + //fill_gradient_RGB(leds, 0, CRGB(255,0,0), NUM_LEDS-1, CRGB(0,255,0)); + //fill_gradient_RGB(leds, 0, gsRGB, NUM_LEDS-1, geRGB); + //fill_gradient_RGB(leds, 0, CRGB(gsRGB.r, gsRGB.g, gsRGB.b), NUM_LEDS-1, CRGB(geRGB.r, geRGB.g, geRGB.b)); + + + /*---------- + * This shows how you could operate on the r,g,b parts of a previously defined + * RGB color, or only use some combination of the r, g, or b components. + * This gradient is animated. + */ + + //fill_gradient_RGB( leds, 0, CRGB(gsRGB.r+num, gsRGB.g, 255), NUM_LEDS-1, CRGB(0, geRGB.g+num, random8(0,64)) ); + + + + FastLED.show(); //display the pixels + } + }//end main loop diff --git a/fill_up_strip.ino b/fill_up_strip.ino index 432a0d0..78d7c4a 100644 --- a/fill_up_strip.ino +++ b/fill_up_strip.ino @@ -7,17 +7,19 @@ //--------------------------------------------------------------- #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB -#define MASTER_BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; + float delta; uint8_t count = 0; uint8_t hue = random8(); // Pick a random color. -uint8_t sat = random8(160,255); // Pick a random saturation in range. +uint8_t sat = random8(160, 255); // Pick a random saturation in range. // Mess with these values for fill speed and slowing effect. @@ -30,47 +32,48 @@ float delay_multiplier = 2.15; // Used to add a delay as strip fills up. These values looked good to me with a 32 pixel strip. Small changes can make a large difference so try small increments. */ - + //--------------------------------------------------------------- -void setup() { - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(MASTER_BRIGHTNESS); - Serial.begin(115200); // Allows serial monitor output (check baud rate) +void setup() { + Serial.begin(115200); // Allows serial monitor output (check baud rate) + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- -void loop() { - // Draw the moving pixels. - for (int i=0; i < (NUM_LEDS - count); i++){ - leds[i] = CHSV(hue,sat,255); - FastLED.show(); - delay(fill_delay); // Slow things down just a bit. - leds[i] = CRGB::Black; - } +void loop() { + // Draw the moving pixels. + for (int i = 0; i < (NUM_LEDS - count); i++) { + leds[i] = CHSV(hue, sat, 255); + FastLED.show(); + delay(fill_delay); // Slow things down just a bit. + leds[i] = CRGB::Black; + } - // Add the new filled pixels. - leds[NUM_LEDS - 1 - count] = CHSV(hue,sat,255); - FastLED.show(); - count++; + // Add the new filled pixels. + leds[NUM_LEDS - 1 - count] = CHSV(hue, sat, 255); + FastLED.show(); + count++; - // Delay the filling effect to slow near end. - delta = (pow(delay_base, count) * delay_multiplier); // Delta increases as strip fills up. - delay(delta); // Delay can increase as strip fills up. - // Uncomment to help visualize the increasing delay. - //Serial.print(" count:"); Serial.print(count); Serial.print(" delta: "); Serial.println(delta); + // Delay the filling effect to slow near end. + delta = (pow(delay_base, count) * delay_multiplier); // Delta increases as strip fills up. + delay(delta); // Delay can increase as strip fills up. + // Uncomment to help visualize the increasing delay. + //Serial.print(" count:"); Serial.print(count); Serial.print(" delta: "); Serial.println(delta); - // Clear the strip when full. - if (count == NUM_LEDS){ - Serial.println(" -------- Reset! --------"); - delay(1400); // Hold filled strip for a moment. - FastLED.clear(); // Blank out the strip data. - FastLED.show(); - count = 0; // Reset count. - hue = random8(); // Pick a new random fill color. - sat = random8(160,255); // Pick a random saturation in range. - delay(700); // Breif pause before filling again. - } + // Clear the strip when full. + if (count == NUM_LEDS) { + Serial.println(" -------- Reset! --------"); + delay(1400); // Hold filled strip for a moment. + FastLED.clear(); // Blank out the strip data. + FastLED.show(); + count = 0; // Reset count. + hue = random8(); // Pick a new random fill color. + sat = random8(160, 255); // Pick a random saturation in range. + delay(700); // Breif pause before filling again. + } } //end main loop diff --git a/gradient_palette_full_range.ino b/gradient_palette_full_range.ino index bf778e8..5624f91 100644 --- a/gradient_palette_full_range.ino +++ b/gradient_palette_full_range.ino @@ -23,48 +23,49 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB -CRGB leds[NUM_LEDS]; -#define BRIGHTNESS 128 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 +CRGB leds[NUM_LEDS]; //--------------------------------------------------------------- void setup() { - Serial.begin(115200); - delay(500); // startup delay - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); + delay(500); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } // Create custom gradient palette DEFINE_GRADIENT_PALETTE( example_gp ) { - 0, 0,0,255, - 5, 0,0,255, - 80, 0,255,0, -130, 0,0,255, -135, 0,0,255, -205, 255,0,255, -238, 255,0,0, // I'm making this my last color choice -255, 255,0,0 }; // And then just duplicating it here + 0, 0, 0, 255, + 5, 0, 0, 255, + 80, 0, 255, 0, + 130, 0, 0, 255, + 135, 0, 0, 255, + 205, 255, 0, 255, + 238, 255, 0, 0, // I'm making this my last color choice + 255, 255, 0, 0 +}; // And then just duplicating it here -CRGBPalette16 myPal = example_gp; +CRGBPalette16 myPal = example_gp; //--------------------------------------------------------------- void loop () { - for (uint8_t i=0; i(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); + delay(3000); // 3 second delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - heartBeat(); // Heart beat function - FastLED.show(); + heartBeat(); // Heart beat function + FastLED.show(); } @@ -45,29 +46,29 @@ void loop() { // HSV and provided all the variables to play with up above. // -Marc -void heartBeat(){ - for (int i = 0; i < NUM_LEDS ; i++) { - uint8_t bloodVal = sumPulse( (5/NUM_LEDS/2) + (NUM_LEDS/2) * i * flowDirection ); - leds[i] = CHSV( bloodHue, bloodSat, bloodVal ); - } +void heartBeat() { + for (int i = 0; i < NUM_LEDS ; i++) { + uint8_t bloodVal = sumPulse( (5 / NUM_LEDS / 2) + (NUM_LEDS / 2) * i * flowDirection ); + leds[i] = CHSV( bloodHue, bloodSat, bloodVal ); + } } int sumPulse(int time_shift) { - //time_shift = 0; //Uncomment to heart beat/pulse all LEDs together - int pulse1 = pulseWave8( millis() + time_shift, cycleLength, pulseLength ); - int pulse2 = pulseWave8( millis() + time_shift + pulseOffset, cycleLength, pulseLength ); - return qadd8( pulse1, pulse2 ); // Add pulses together without overflow + //time_shift = 0; //Uncomment to heart beat/pulse all LEDs together + int pulse1 = pulseWave8( millis() + time_shift, cycleLength, pulseLength ); + int pulse2 = pulseWave8( millis() + time_shift + pulseOffset, cycleLength, pulseLength ); + return qadd8( pulse1, pulse2 ); // Add pulses together without overflow } uint8_t pulseWave8(uint32_t ms, uint16_t cycleLength, uint16_t pulseLength) { - uint16_t T = ms % cycleLength; - if ( T > pulseLength) return baseBrightness; - uint16_t halfPulse = pulseLength / 2; - if (T <= halfPulse ) { - return (T * 255) / halfPulse; //first half = going up - } else { - return((pulseLength - T) * 255) / halfPulse; //second half = going down - } + uint16_t T = ms % cycleLength; + if ( T > pulseLength) return baseBrightness; + uint16_t halfPulse = pulseLength / 2; + if (T <= halfPulse ) { + return (T * 255) / halfPulse; //first half = going up + } else { + return((pulseLength - T) * 255) / halfPulse; //second half = going down + } } //End_heart_beat_functions //--------------------------------------------------------------- diff --git a/hueAddition.ino b/hueAddition.ino index 7219ea6..9972d1d 100644 --- a/hueAddition.ino +++ b/hueAddition.ino @@ -11,12 +11,13 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define DATA_PIN 11 -#define CLOCK_PIN 13 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 #define NUM_LEDS 32 -#define BRIGHTNESS 255 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint8_t gHue; //variable to store a hue @@ -24,38 +25,39 @@ uint8_t gHue; //variable to store a hue //--------------------------------------------------------------- void setup() { - Serial.begin(115200); - delay(1500); // Startup delay - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); + delay(1500); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - EVERY_N_SECONDS(5) { - uint8_t r = random8(); //pick some random colors - uint8_t g = random8(); - uint8_t b = random8(); - updatePixels(r,g,b); - FastLED.show(); - } + EVERY_N_SECONDS(5) { + uint8_t r = random8(); //pick some random colors + uint8_t g = random8(); + uint8_t b = random8(); + updatePixels(r, g, b); + FastLED.show(); + } }//end_main_loop //--------------------------------------------------------------- void updatePixels(byte red, byte green, byte blue) { - CRGB color = CRGB(red, green, blue); - fill_solid(leds, NUM_LEDS, color); //fill entire strip with color + CRGB color = CRGB(red, green, blue); + fill_solid(leds, NUM_LEDS, color); //fill entire strip with color - //Comment this out if you want hue to continuously increment - gHue = 0; //reset hue to zero. + //Comment this out if you want hue to continuously increment + gHue = 0; //reset hue to zero. - for (uint8_t i=0; i<(NUM_LEDS/2); i++) { - CRGB hueShift = CHSV(gHue,255,255); //color to add each time - leds[(i*2)+1] += hueShift; //add color to existing pixel color - gHue = gHue + 20; //increment hue by set amount - } + for (uint8_t i = 0; i < (NUM_LEDS / 2); i++) { + CRGB hueShift = CHSV(gHue, 255, 255); //color to add each time + leds[(i * 2) + 1] += hueShift; //add color to existing pixel color + gHue = gHue + 20; //increment hue by set amount + } }//end_updatePixels diff --git a/hue_and_brightness_example.ino b/hue_and_brightness_example.ino index c143c00..d6a62a7 100644 --- a/hue_and_brightness_example.ino +++ b/hue_and_brightness_example.ino @@ -12,13 +12,17 @@ //=============================================================== #include "FastLED.h" -#define LED_TYPE NEOPIXEL -#define DATA_PIN 6 -#define NUM_LEDS 12 -#define MASTER_BRIGHTNESS 255 // Set the master brigtness value [should be greater then min_brightness value]. +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 // Set the master brigtness value [should be greater then min_brightness value]. + +CRGB leds[NUM_LEDS]; + uint8_t min_brightness = 30; // Set a minimum brightness level. uint8_t brightness; // Mapped master brightness based on potentiometer reading. -CRGB leds[NUM_LEDS]; int potPinA = A0; // Pin for potentiometer A (for hue) int potPinB = A1; // Pin for potentiometer B (for brightness) @@ -29,41 +33,42 @@ uint8_t hue; // Hue color (0-255) //--------------------------------------------------------------- void setup() { - delay(2000); // Power-up delay - //Serial.begin(115200); // Allows serial monitor output (check baud rate) - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(MASTER_BRIGHTNESS); // Initially set the max brightness. Will continuously update it later. - pinMode(potPinA, INPUT); // Set pin as an input. - pinMode(potPinB, INPUT); // Set pin as an input. + delay(2000); // Power-up delay + //Serial.begin(115200); // Allows serial monitor output (check baud rate) + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + pinMode(potPinA, INPUT); // Set pin as an input. + pinMode(potPinB, INPUT); // Set pin as an input. } //--------------------------------------------------------------- void loop() { - checkKnobs(); // Call function to check knob positions. + checkKnobs(); // Call function to check knob positions. - for (int i = 0; i < NUM_LEDS; i++) { - leds[i] = CHSV(hue, 255, 255); // hue comes from pot A, and brightness value is scaled based on pot B. - } - FastLED.show(); + for (int i = 0; i < NUM_LEDS; i++) { + leds[i] = CHSV(hue, 255, 255); // hue comes from pot A, and brightness value is scaled based on pot B. + } + FastLED.show(); } //=============================================================== -void checkKnobs(){ - potValA = analogRead(potPinA); // Read potentiometer A (for hue). - //potValA = map(potValA, 1023, 0, 0, 1023); // Reverse reading if potentiometer is wired backwards. - hue = map(potValA, 0, 1023, 0, 255); // map(value, fromLow, fromHigh, toLow, toHigh) +void checkKnobs() { + potValA = analogRead(potPinA); // Read potentiometer A (for hue). + //potValA = map(potValA, 1023, 0, 0, 1023); // Reverse reading if potentiometer is wired backwards. + hue = map(potValA, 0, 1023, 0, 255); // map(value, fromLow, fromHigh, toLow, toHigh) - potValB = analogRead(potPinB); // Read potentiometer B (for brightness). - brightness = map(potValB, 0, 1023, min_brightness, MASTER_BRIGHTNESS); - // Map value between min_brightness and MASTER brightness values. - // Note: We are limiting the lowest possible brightness value to the - // min_brightness value assigned up top. - FastLED.setBrightness(brightness); // Set master brightness based on potentiometer position. + potValB = analogRead(potPinB); // Read potentiometer B (for brightness). + brightness = map(potValB, 0, 1023, min_brightness, MASTER_BRIGHTNESS); + // Map value between min_brightness and MASTER brightness values. + // Note: We are limiting the lowest possible brightness value to the + // min_brightness value assigned up top. + FastLED.setBrightness(brightness); // Set master brightness based on potentiometer position. - //Serial.print(" pot A: "); Serial.print(potValA); Serial.print(" hue: "); Serial.print(hue); - //Serial.print(" pot B: "); Serial.print(potValB); Serial.print(" brightness: "); Serial.println(brightness); + //Serial.print(" pot A: "); Serial.print(potValA); Serial.print(" hue: "); Serial.print(hue); + //Serial.print(" pot B: "); Serial.print(potValB); Serial.print(" brightness: "); Serial.println(brightness); } diff --git a/lighthouse_beacon_v2_anti-aliased.ino b/lighthouse_beacon_v2_anti-aliased.ino index f8b56d8..361f993 100644 --- a/lighthouse_beacon_v2_anti-aliased.ino +++ b/lighthouse_beacon_v2_anti-aliased.ino @@ -7,12 +7,13 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE NEOPIXEL -#define DATA_PIN 6 -//#define CLOCK_PIN 13 -#define NUM_LEDS 12 -//#define COLOR_ORDER GRB -#define BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; int8_t hue = 42; // Light color @@ -23,65 +24,64 @@ int delta = -1; // Number of 16ths of a pixel to move. (Use negative value for uint8_t width = 3; // width of light in pixels uint16_t holdTime = 80; // Milliseconds to hold between microsteps. int8_t fadeRate = 40; // Fade ends a bit. - + //--------------------------------------------------------------- void setup() { - //FastLED.addLeds(leds, NUM_LEDS); - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(BRIGHTNESS); - //Serial.begin(115200); + // Serial.begin(115200); + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- // Fractional bar funtion -void drawFractionalBar( uint8_t pos16, uint8_t width, uint8_t hue) -{ - uint8_t i = pos16 / 16; // convert from pos to raw pixel number - uint8_t frac = pos16 & 0x0F; // extract the 'factional' part of the position - uint8_t firstpixelbrightness = 255 - (frac * 16); - uint8_t lastpixelbrightness = 255 - firstpixelbrightness; - uint8_t bright; - for( uint8_t n = 0; n <= width; n++) { - if( n == 0) { - bright = firstpixelbrightness; - leds[i] += CHSV( hue, sat, bright); - //fadeToBlackBy( leds, NUM_LEDS, fadeRate ); // creates outward fade - } - else if (n == width) { - bright = lastpixelbrightness; - leds[i] += CHSV( hue, sat, bright); - fadeToBlackBy( leds, NUM_LEDS, fadeRate ); // creates outward fade - } - else { - bright = 255; // center pixel full bright - leds[i] += CHSV( hue, sat, bright); +void drawFractionalBar( uint8_t pos16, uint8_t width, uint8_t hue) { + uint8_t i = pos16 / 16; // convert from pos to raw pixel number + uint8_t frac = pos16 & 0x0F; // extract the 'factional' part of the position + uint8_t firstpixelbrightness = 255 - (frac * 16); + uint8_t lastpixelbrightness = 255 - firstpixelbrightness; + uint8_t bright; + for( uint8_t n = 0; n <= width; n++) { + if( n == 0) { + bright = firstpixelbrightness; + leds[i] += CHSV( hue, sat, bright); + //fadeToBlackBy( leds, NUM_LEDS, fadeRate ); // creates outward fade + } else if (n == width) { + bright = lastpixelbrightness; + leds[i] += CHSV( hue, sat, bright); + fadeToBlackBy( leds, NUM_LEDS, fadeRate ); // creates outward fade + } else { + bright = 255; // center pixel full bright + leds[i] += CHSV( hue, sat, bright); + } + i++; + if( i == NUM_LEDS) i = 0; // wrap around } - i++; - if( i == NUM_LEDS) i = 0; // wrap around - } } //--------------------------------------------------------------- void loop() { // START MAIN LOOP - if (delta > 0) { - pixelPos += delta; - } else { - pixelPos = (pixelPos + delta + (NUM_LEDS *16)) % (NUM_LEDS * 16); - } + if (delta > 0) { + pixelPos += delta; + } else { + pixelPos = (pixelPos + delta + (NUM_LEDS * 16)) % (NUM_LEDS * 16); + } - if( pixelPos >= (NUM_LEDS * 16)) { - pixelPos -= (NUM_LEDS * 16); - } + if( pixelPos >= (NUM_LEDS * 16)) { + pixelPos -= (NUM_LEDS * 16); + } - static byte countdown = 0; - if( countdown == 0) { countdown = 16; } // reset countdown - countdown -= 1; // decrement once each loop though + static byte countdown = 0; + if( countdown == 0) { + countdown = 16; // reset countdown + } + countdown -= 1; // decrement once each loop though - memset8( leds, 0, NUM_LEDS * sizeof(CRGB)); // Clear the pixel buffer - drawFractionalBar( pixelPos, width, hue); // Draw the pixels - FastLED.show(); // Show the pixels - delay(holdTime); // Delay a bit before micro advancing + memset8( leds, 0, NUM_LEDS * sizeof(CRGB)); // Clear the pixel buffer + drawFractionalBar( pixelPos, width, hue); // Draw the pixels + FastLED.show(); // Show the pixels + delay(holdTime); // Delay a bit before micro advancing } // END MAIN LOOP diff --git a/marquee_v2.ino b/marquee_v2.ino index 6c081d9..87d0bbf 100644 --- a/marquee_v2.ino +++ b/marquee_v2.ino @@ -8,11 +8,13 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint16_t holdTime = 250; // Milliseconds to hold position before advancing. @@ -31,54 +33,65 @@ int8_t advance; // Stores the advance amount. //--------------------------------------------------------------- void setup() { - //Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // Startup delay - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(64); + //Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - EVERY_N_SECONDS(40){ // Change direction every N seconds. - delta = -1*delta; - } - - EVERY_N_SECONDS(10){ // Demo changing the pixel spacing every N seconds. - spacing = spacing + 1; - if (spacing == 9) { spacing = 2; } // Reset spacing to 2 - if (spacing >4) { spacing = 8; } // Jump spacing up to 8 - hue = hue + random8(30,61); // Shift the hue to something new. - } - - EVERY_N_MILLISECONDS(holdTime){ // Advance pixels to next position. - if (DEBUG==1) { // Print out some info if DEBUG is true. - Serial.print("delta: "); Serial.print(delta); - Serial.print(" spacing: "); Serial.print(spacing); Serial.print(" "); + EVERY_N_SECONDS(40) { // Change direction every N seconds. + delta = -1 * delta; } - for (uint8_t i=0; i<(NUM_LEDS/spacing); i++){ - pos = (spacing * (i-1) + spacing + advance) % NUM_LEDS; - leds[pos] = CHSV(hue,255,255); - if (DEBUG==1) { // Print out lit pixels if DEBUG is true. - Serial.print(" "); Serial.print(pos); - } + EVERY_N_SECONDS(10) { // Demo changing the pixel spacing every N seconds. + spacing = spacing + 1; + if (spacing == 9) { + spacing = 2; // Reset spacing to 2 + } + if (spacing > 4) { + spacing = 8; // Jump spacing up to 8 + } + hue = hue + random8(30, 61); // Shift the hue to something new. } - if (DEBUG==1) { Serial.println(" "); } - FastLED.show(); - - // Fade out tail or set back to black for next loop around. - if (fadingTail == 1) { - fadeToBlackBy(leds, NUM_LEDS,fadeRate); - } else { - for (uint8_t i=0; i<(NUM_LEDS/spacing); i++){ - pos = (spacing * (i-1) + spacing + advance) % NUM_LEDS; - leds[pos] = CRGB::Black; - } + + EVERY_N_MILLISECONDS(holdTime) { // Advance pixels to next position. + if (DEBUG == 1) { // Print out some info if DEBUG is true. + Serial.print("delta: "); + Serial.print(delta); + Serial.print(" spacing: "); + Serial.print(spacing); + Serial.print(" "); + } + for (uint8_t i = 0; i < (NUM_LEDS / spacing); i++) { + pos = (spacing * (i - 1) + spacing + advance) % NUM_LEDS; + leds[pos] = CHSV(hue, 255, 255); + + if (DEBUG == 1) { // Print out lit pixels if DEBUG is true. + Serial.print(" "); + Serial.print(pos); + } + } + if (DEBUG == 1) { + Serial.println(" "); + } + FastLED.show(); + + // Fade out tail or set back to black for next loop around. + if (fadingTail == 1) { + fadeToBlackBy(leds, NUM_LEDS, fadeRate); + } else { + for (uint8_t i = 0; i < (NUM_LEDS / spacing); i++) { + pos = (spacing * (i - 1) + spacing + advance) % NUM_LEDS; + leds[pos] = CRGB::Black; + } + } + + // Advance pixel postion down strip, and rollover if needed. + advance = (advance + delta + NUM_LEDS) % NUM_LEDS; } - - // Advance pixel postion down strip, and rollover if needed. - advance = (advance + delta + NUM_LEDS) % NUM_LEDS; - } }//end_main_loop diff --git a/marquee_v3.ino b/marquee_v3.ino index 38b3fa1..05d34fb 100644 --- a/marquee_v3.ino +++ b/marquee_v3.ino @@ -9,18 +9,14 @@ //*************************************************************** #include "FastLED.h" +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 -#define LED_TYPE LPD8806 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB -//#define LED_TYPE APA102 -//#define NUM_LEDS 39 -//#define COLOR_ORDER BGR - -#define DATA_PIN 11 -#define CLOCK_PIN 13 CRGB leds[NUM_LEDS]; -#define BRIGHTNESS 64 uint16_t holdTime = 200; // Milliseconds to hold position before advancing. uint8_t spacing = 5; // Sets pixel spacing. [Use 2 or greater] @@ -34,76 +30,80 @@ uint8_t hue = 180; // Starting color. uint8_t hue2_shift = 20; // Hue shift for secondary color. Use 0 for no shift. [0-255] int16_t pos; // Pixel position. -int8_t advance = -1*width; // Stores the advance amount. +int8_t advance = -1 * width; // Stores the advance amount. uint8_t color; // Stores a hue color. //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1600); // Startup delay - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(BRIGHTNESS); - - Serial.print("NUM_LEDS/spacing: "); Serial.println(NUM_LEDS/spacing); - Serial.println("Setup done. "); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1600); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + + Serial.print("NUM_LEDS/spacing: "); + Serial.println(NUM_LEDS / spacing); + Serial.println("Setup done. "); } //--------------------------------------------------------------- void loop() { - EVERY_N_SECONDS(10){ // Demo: Change direction every N seconds. - delta = -1*delta; - } + EVERY_N_SECONDS(10) { // Demo: Change direction every N seconds. + delta = -1 * delta; + } - //EVERY_N_SECONDS(10){ // Demo: Changing the pixel spacing every N seconds. - // spacing = spacing + 1; - // if (spacing == 9) { spacing = 2; } // Reset spacing to 2 - // if (spacing >4) { spacing = 8; } // Jump spacing up to 8 - //} + //EVERY_N_SECONDS(10){ // Demo: Changing the pixel spacing every N seconds. + // spacing = spacing + 1; + // if (spacing == 9) { spacing = 2; } // Reset spacing to 2 + // if (spacing >4) { spacing = 8; } // Jump spacing up to 8 + //} - EVERY_N_SECONDS(10){ // Demo: Change the hue every N seconds. - hue = hue + random8(30,61); // Shift the hue to something new. - } + EVERY_N_SECONDS(10) { // Demo: Change the hue every N seconds. + hue = hue + random8(30, 61); // Shift the hue to something new. + } - EVERY_N_MILLISECONDS(holdTime){ // Advance pixels to next position. + EVERY_N_MILLISECONDS(holdTime) { // Advance pixels to next position. - // Advance pixel postion down strip, and rollover if needed. - advance = (advance + delta + NUM_LEDS) % NUM_LEDS; + // Advance pixel postion down strip, and rollover if needed. + advance = (advance + delta + NUM_LEDS) % NUM_LEDS; - // Fade out tail or set back to black for next loop around. - if (fadingTail == 1) { - fadeToBlackBy(leds, NUM_LEDS,fadeRate); - } else { - for (uint8_t i=0; i<(NUM_LEDS/spacing); i++){ - for (uint8_t w = 0; w(leds, NUM_LEDS); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); - FastLED.show(); - Serial.println("Setup done. \n"); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(2000); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); + FastLED.show(); + Serial.println("Setup done. \n"); } //--------------------------------------------------------------- void loop() { - // Fill temp with some color data which will be tranfered to leds. - fill_rainbow(temp, NUM_LEDS, millis()/300, 256/NUM_LEDS); + // Fill temp with some color data which will be tranfered to leds. + fill_rainbow(temp, NUM_LEDS, millis() / 300, 256 / NUM_LEDS); - EVERY_N_SECONDS(2) { + EVERY_N_SECONDS(2) { - shuffle = !shuffle; //toggle true or false - Serial.print("shuffle = "); Serial.print(shuffle); + shuffle = !shuffle; //toggle true or false + Serial.print("shuffle = "); + Serial.print(shuffle); - if (shuffle) { - ShufflePixels(); //copy from temp to leds with shuffling - Serial.println(" Pixels shuffled."); - } else { - CopyPixels(); //straight copy of temp to leds, no shuffling - Serial.println(" No change."); - } + if (shuffle) { + ShufflePixels(); //copy from temp to leds with shuffling + Serial.println(" Pixels shuffled."); + } else { + CopyPixels(); //straight copy of temp to leds, no shuffling + Serial.println(" No change."); + } - FastLED.show(); //display leds + FastLED.show(); //display leds - }//end EVERY_N + }//end EVERY_N }//end_main_loop //--------------------------------------------------------------- void CopyPixels() { - // Straight transfer of all temp pixel data to leds. - // This results in leds being exactly the same as temp. - memmove8( &leds, &temp, (NUM_LEDS)*sizeof(CRGB) ); + // Straight transfer of all temp pixel data to leds. + // This results in leds being exactly the same as temp. + memmove8( &leds, &temp, (NUM_LEDS)*sizeof(CRGB) ); }//end_CopyPixels //--------------------------------------------------------------- void ShufflePixels() { - // Move pixel data from temp (specifing start position) to - // destination leds (specifing starting position), moving the - // data for X number of pixels. - // memmove8( &destination[start position], &source[start position], size of pixel data ); + // Move pixel data from temp (specifing start position) to + // destination leds (specifing starting position), moving the + // data for X number of pixels. + // memmove8( &destination[start position], &source[start position], size of pixel data ); - // move pixel data from temp 24-31 to leds 0-7. - memmove8( &leds[0], &temp[NUM_LEDS/4*3], (NUM_LEDS)*sizeof(CRGB)/4 ); + // move pixel data from temp 24-31 to leds 0-7. + memmove8( &leds[0], &temp[NUM_LEDS / 4 * 3], (NUM_LEDS)*sizeof(CRGB) / 4 ); - // move pixel data from temp 16-23 to leds 8-15. - memmove8( &leds[NUM_LEDS/4], &temp[NUM_LEDS/4*2], (NUM_LEDS)*sizeof(CRGB)/4 ); + // move pixel data from temp 16-23 to leds 8-15. + memmove8( &leds[NUM_LEDS / 4], &temp[NUM_LEDS / 4 * 2], (NUM_LEDS)*sizeof(CRGB) / 4 ); - // move pixel data from temp 8-15 to leds 16-23. - memmove8( &leds[NUM_LEDS/4*2], &temp[NUM_LEDS/4], (NUM_LEDS)*sizeof(CRGB)/4 ); + // move pixel data from temp 8-15 to leds 16-23. + memmove8( &leds[NUM_LEDS / 4 * 2], &temp[NUM_LEDS / 4], (NUM_LEDS)*sizeof(CRGB) / 4 ); - // move pixel data from temp 0-7 to leds 24-31. - memmove8( &leds[NUM_LEDS/4*3], &temp[0], (NUM_LEDS)*sizeof(CRGB)/4 ); + // move pixel data from temp 0-7 to leds 24-31. + memmove8( &leds[NUM_LEDS / 4 * 3], &temp[0], (NUM_LEDS)*sizeof(CRGB) / 4 ); }//end_ShufflePixels diff --git a/mirrored_Fire2012.ino b/mirrored_Fire2012.ino index f4e9203..0c4e0a3 100644 --- a/mirrored_Fire2012.ino +++ b/mirrored_Fire2012.ino @@ -1,6 +1,6 @@ //*************************************************************** // Example of running FastLED's Fire2012 example mirrored on -// both halves of a strip. +// both halves of a strip. // // gReverseDirection sets if the fire goes from center out or // from the ends inward. @@ -13,14 +13,15 @@ //*************************************************************** #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 // Total number of pixels in strip -#define BRIGHTNESS 128 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 // for this example, must be an even number +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; -CRGB leds_temp[NUM_LEDS/2]; // half the total number of pixels +CRGB leds_temp[NUM_LEDS / 2]; // half the total number of pixels #define FRAMES_PER_SECOND 60 @@ -29,39 +30,38 @@ bool gReverseDirection = false; //false = center outward, true = from ends inwa //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(2000); // startup delay - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); - FastLED.show(); - Serial.println("Setup done. \n"); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(2000); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); + FastLED.show(); + Serial.println("Setup done. \n"); } //--------------------------------------------------------------- -void loop() -{ - // Add entropy to random number generator; we use a lot of it. - // random16_add_entropy( random()); +void loop() { + // Add entropy to random number generator; we use a lot of it. + // random16_add_entropy( random()); - Fire2012_halfStrip(); // draw fire data to leds_temp + Fire2012_halfStrip(); // draw fire data to leds_temp - mirror2ndHalf(); // copy and mirror data from leds_temp to leds + mirror2ndHalf(); // copy and mirror data from leds_temp to leds - FastLED.show(); // display leds - FastLED.delay(1000 / FRAMES_PER_SECOND); + FastLED.show(); // display leds + FastLED.delay(1000 / FRAMES_PER_SECOND); } //--------------------------------------------------------------- // Fire2012 by Mark Kriegsman, July 2012 // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY -// +// // This basic one-dimensional 'fire' simulation works roughly as follows: // There's a underlying array of 'heat' cells, that model the temperature -// at each point along the line. Every cycle through the simulation, +// at each point along the line. Every cycle through the simulation, // four steps are performed: // 1) All cells cool down a little bit, losing heat to the air // 2) The heat from each cell drifts 'up' and diffuses a little @@ -72,7 +72,7 @@ void loop() // Temperature is in arbitrary units from 0 (cold black) to 255 (white hot). // // This simulation scales it self a bit depending on NUM_LEDS; it should look -// "OK" on anywhere from 20 to 100 LEDs without too much tweaking. +// "OK" on anywhere from 20 to 100 LEDs without too much tweaking. // // I recommend running this simulation at anywhere from 30-100 frames per second, // meaning an interframe delay of about 10-35 milliseconds. @@ -86,7 +86,7 @@ void loop() // // COOLING: How much does the air cool as it rises? // Less cooling = taller flames. More cooling = shorter flames. -// Default 50, suggested range 20-100 +// Default 50, suggested range 20-100 #define COOLING 90 // SPARKING: What chance (out of 255) is there that a new spark will be lit? @@ -107,53 +107,53 @@ void loop() // since the reversing happens in the mirror2ndHalf function. //--------------------------------------------------------------- void Fire2012_halfStrip() { - // Fuction only operates on half the number of pixels (NUM_LEDS/2) - - // Array of temperature readings at each simulation cell - static byte heat[NUM_LEDS/2]; - - // Step 1. Cool down every cell a little - for( int i = 0; i < NUM_LEDS/2; i++) { - heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / (NUM_LEDS/2)) + 2)); - } - - // Step 2. Heat from each cell drifts 'up' and diffuses a little - for( int k= (NUM_LEDS/2) - 1; k >= 2; k--) { - heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3; - } - - // Step 3. Randomly ignite new 'sparks' of heat near the bottom - if( random8() < SPARKING ) { - int y = random8(7); - heat[y] = qadd8( heat[y], random8(160,255) ); - } - - // Step 4. Map from heat cells to LED colors - for( int j = 0; j < NUM_LEDS/2; j++) { - CRGB color = HeatColor( heat[j]); - leds_temp[j] = color; - } + // Fuction only operates on half the number of pixels (NUM_LEDS/2) + + // Array of temperature readings at each simulation cell + static byte heat[NUM_LEDS / 2]; + + // Step 1. Cool down every cell a little + for( int i = 0; i < NUM_LEDS / 2; i++) { + heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / (NUM_LEDS / 2)) + 2)); + } + + // Step 2. Heat from each cell drifts 'up' and diffuses a little + for( int k = (NUM_LEDS / 2) - 1; k >= 2; k--) { + heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3; + } + + // Step 3. Randomly ignite new 'sparks' of heat near the bottom + if( random8() < SPARKING ) { + int y = random8(7); + heat[y] = qadd8( heat[y], random8(160, 255) ); + } + + // Step 4. Map from heat cells to LED colors + for( int j = 0; j < NUM_LEDS / 2; j++) { + CRGB color = HeatColor( heat[j]); + leds_temp[j] = color; + } }//end_Fire2012_halfStrip //--------------------------------------------------------------- void mirror2ndHalf() { - //copy and mirror pixel data from leds_temp to leds array. - - if (gReverseDirection == false) { //false is center outward - for (uint8_t i=0; i(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); - Serial.println("Setup done. \n"); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); + Serial.println("Setup done. \n"); } //--------------------------------------------------------------- -void loop() -{ - // Add entropy to random number generator; we use a lot of it. - // random16_add_entropy( random()); - - Fire2012(); // run simulation frame - - mirror2ndHalf(); // copy and mirror first half of strip to second half - FastLED.show(); // display this frame - FastLED.delay(1000 / FRAMES_PER_SECOND); +void loop() { + // Add entropy to random number generator; we use a lot of it. + // random16_add_entropy( random()); + + Fire2012(); // run simulation frame + + mirror2ndHalf(); // copy and mirror first half of strip to second half + FastLED.show(); // display this frame + FastLED.delay(1000 / FRAMES_PER_SECOND); } @@ -62,10 +62,10 @@ void loop() //--------------------------------------------------------------- // Fire2012 by Mark Kriegsman, July 2012 // as part of "Five Elements" shown here: http://youtu.be/knWiGsmgycY -//// +//// // This basic one-dimensional 'fire' simulation works roughly as follows: // There's a underlying array of 'heat' cells, that model the temperature -// at each point along the line. Every cycle through the simulation, +// at each point along the line. Every cycle through the simulation, // four steps are performed: // 1) All cells cool down a little bit, losing heat to the air // 2) The heat from each cell drifts 'up' and diffuses a little @@ -76,7 +76,7 @@ void loop() // Temperature is in arbitrary units from 0 (cold black) to 255 (white hot). // // This simulation scales it self a bit depending on NUM_LEDS; it should look -// "OK" on anywhere from 20 to 100 LEDs without too much tweaking. +// "OK" on anywhere from 20 to 100 LEDs without too much tweaking. // // I recommend running this simulation at anywhere from 30-100 frames per second, // meaning an interframe delay of about 10-35 milliseconds. @@ -90,7 +90,7 @@ void loop() // // COOLING: How much does the air cool as it rises? // Less cooling = taller flames. More cooling = shorter flames. -// Default 50, suggested range 20-100 +// Default 50, suggested range 20-100 #define COOLING 90 // SPARKING: What chance (out of 255) is there that a new spark will be lit? @@ -103,45 +103,44 @@ void loop() // ***** NOTE: NUM_LEDS was replaced with NUM_LEDS/2 anywhere it was found // below. This makes the fire only run on the first half of the strip. ***** //--------------------------------------------------------------- -void Fire2012() -{ -// Array of temperature readings at each simulation cell - static byte heat[NUM_LEDS/2]; - - // Step 1. Cool down every cell a little - for( int i = 0; i < NUM_LEDS/2; i++) { - heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS/2) + 2)); +void Fire2012() { + // Array of temperature readings at each simulation cell + static byte heat[NUM_LEDS / 2]; + + // Step 1. Cool down every cell a little + for( int i = 0; i < NUM_LEDS / 2; i++) { + heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS / 2) + 2)); } - + // Step 2. Heat from each cell drifts 'up' and diffuses a little - for( int k= NUM_LEDS/2 - 1; k >= 2; k--) { - heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3; + for( int k = NUM_LEDS / 2 - 1; k >= 2; k--) { + heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3; } - + // Step 3. Randomly ignite new 'sparks' of heat near the bottom if( random8() < SPARKING ) { - int y = random8(7); - heat[y] = qadd8( heat[y], random8(160,255) ); + int y = random8(7); + heat[y] = qadd8( heat[y], random8(160, 255) ); } // Step 4. Map from heat cells to LED colors - for( int j = 0; j < NUM_LEDS/2; j++) { - CRGB color = HeatColor( heat[j]); - int pixelnumber; - if( gReverseDirection ) { - pixelnumber = (NUM_LEDS/2-1) - j; - } else { - pixelnumber = j; - } - leds[pixelnumber] = color; + for( int j = 0; j < NUM_LEDS / 2; j++) { + CRGB color = HeatColor( heat[j]); + int pixelnumber; + if( gReverseDirection ) { + pixelnumber = (NUM_LEDS / 2 - 1) - j; + } else { + pixelnumber = j; + } + leds[pixelnumber] = color; } } //--------------------------------------------------------------- void mirror2ndHalf() { - // copy in reverse order first half of strip to second half - for (uint8_t i = 0; i < NUM_LEDS/2; i++) { - leds[NUM_LEDS-1-i] = leds[i]; - } + // copy in reverse order first half of strip to second half + for (uint8_t i = 0; i < NUM_LEDS / 2; i++) { + leds[NUM_LEDS - 1 - i] = leds[i]; + } } diff --git a/moving_colored_bars.ino b/moving_colored_bars.ino index 158aabe..3b138a8 100644 --- a/moving_colored_bars.ino +++ b/moving_colored_bars.ino @@ -10,16 +10,18 @@ // Marc Miller, Dec 2017 //*************************************************************** + #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 -#define BRIGHTNESS 64 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + +/* CRGB leds[NUM_LEDS]; <--not using this. Using CRGBArray instead. */ CRGBArray leds; - #define FRAME_DELAY 80 //How fast to move (milliseconds) @@ -30,13 +32,13 @@ CRGBArray leds; Note: I used Grey instead of White here so it's not as bright compared to the other colors. */ -long colorPallet[] = {CRGB::Green,CRGB::Grey,CRGB::Red,CRGB::Grey,CRGB::Red,CRGB::Grey,CRGB::Red,CRGB::Green,CRGB::Green,CRGB::Green}; +long colorPallet[] = {CRGB::Green, CRGB::Grey, CRGB::Red, CRGB::Grey, CRGB::Red, CRGB::Grey, CRGB::Red, CRGB::Green, CRGB::Green, CRGB::Green}; //long colorPallet[] = {CRGB::Black,CRGB::Green,CRGB::Red}; //long colorPallet[] = {CRGB::Green,CRGB::Red}; //long colorPallet[] = {CRGB::Black,CRGB::Blue,CRGB::Yellow,CRGB::Purple}; //Black can be used too of course. -const int numberofColors = sizeof(colorPallet)/sizeof(int); //Auto calculate your specified number of color bars +const int numberofColors = sizeof(colorPallet) / sizeof(int); //Auto calculate your specified number of color bars /* Play with setting the colorBarLength in different ways for slightly different effects. */ @@ -55,57 +57,51 @@ bool clearLEDS = false; //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1500); // startup delay - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); - FastLED.show(); - Serial.println("Setup done. \n"); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); + FastLED.show(); + Serial.println("Setup done. \n"); } //--------------------------------------------------------------- void loop() { - EVERY_N_MILLISECONDS(FRAME_DELAY) { - - for (int x=0; x colorBarLength) && !clearLEDS) - { - leds[NUM_LEDS-1]=colorPallet[palletPosition]; - palletPosition = 0; - colorBarPosition = 1; - clearLEDS= true; - } - if ((colorBarPosition > colorBarLength) && !clearLEDS) - { - colorBarPosition = 1; - palletPosition = palletPosition+1; - } - //if (clearLEDS && !leds(0,NUM_LEDS-1)) //Not using this for of test any more - if (clearLEDS && leds[0]==(CRGB)(colorPallet[numberofColors-1])) //restarts as soon as last color makes it past the end - { - //Serial.print( leds[0].r ); Serial.print("\t"), Serial.print( leds[0].g ); Serial.print("\t"), Serial.println( leds[0].b ); //Print out RGB colors it's triggering on - clearLEDS = false; - } - - }//end_EVERY_N - - FastLED.show(); + EVERY_N_MILLISECONDS(FRAME_DELAY) { + + for (int x = 0; x < NUM_LEDS - 1; x++) { + leds[x] = leds[x + 1]; + } + if (clearLEDS) { + leds[NUM_LEDS - 1] = colorPallet[palletPosition]; + } + if ((colorBarPosition <= colorBarLength) && !clearLEDS) { + leds[NUM_LEDS - 1] = colorPallet[palletPosition]; + colorBarPosition++; + } + if ((palletPosition == numberofColors - 1) && (colorBarPosition > colorBarLength) && !clearLEDS) { + leds[NUM_LEDS - 1] = colorPallet[palletPosition]; + palletPosition = 0; + colorBarPosition = 1; + clearLEDS = true; + } + if ((colorBarPosition > colorBarLength) && !clearLEDS) { + colorBarPosition = 1; + palletPosition = palletPosition + 1; + } + //if (clearLEDS && !leds(0,NUM_LEDS-1)) //Not using this for of test any more + if (clearLEDS && leds[0] == (CRGB)(colorPallet[numberofColors - 1])) { //restarts as soon as last color makes it past the end + //Serial.print( leds[0].r ); Serial.print("\t"), Serial.print( leds[0].g ); Serial.print("\t"), Serial.println( leds[0].b ); //Print out RGB colors it's triggering on + clearLEDS = false; + } + + }//end_EVERY_N + + FastLED.show(); }//end_main_loop diff --git a/moving_gradient_example.ino b/moving_gradient_example.ino index 4addacc..57351f4 100644 --- a/moving_gradient_example.ino +++ b/moving_gradient_example.ino @@ -10,17 +10,18 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB -#define BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; // User variables -CHSV gradStartColor(0,255,255); // Gradient start color. -CHSV gradEndColor(161,255,255); // Gradient end color. +CHSV gradStartColor(0, 255, 255); // Gradient start color. +CHSV gradEndColor(161, 255, 255); // Gradient end color. uint8_t gradStartPos = 0; // Starting position of the gradient. #define gradLength 8 // How many pixels (in total) is the grad from start to end. int8_t gradDelta = 1; // 1 or -1. (Negative value reverses direction.) @@ -35,34 +36,34 @@ CRGB grad[gradLength]; // A place to save the gradient colors. (Don't edit this //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check your baud rate) - delay(3000); // Startup delay - FastLED.addLeds(leds, NUM_LEDS); // ***For strips using Clock. - //FastLED.addLeds(leds, NUM_LEDS); // ***For Clock-less strips. - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check your baud rate) + delay(3000); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); - //fill the array that stores the gradient colors. - fill_gradient(grad, gradStartPos, gradStartColor, gradStartPos+gradLength-1, gradEndColor, SHORTEST_HUES); + //fill the array that stores the gradient colors. + fill_gradient(grad, gradStartPos, gradStartColor, gradStartPos + gradLength - 1, gradEndColor, SHORTEST_HUES); } //end setup //--------------------------------------------------------------- void loop() { //START MAIN LOOP - EVERY_N_MILLISECONDS(gradMoveDelay) { - uint8_t count = 0; - for (uint8_t i = gradStartPos; i < gradStartPos+gradLength; i++) { - leds[i % NUM_LEDS] = grad[count]; - count++; - } - FastLED.show(); // Display the pixels. - FastLED.clear(); // Clear the strip to not leave behind lit pixels as grad moves. - - gradStartPos = gradStartPos + gradDelta; // Update start position. - if ( (gradStartPos > NUM_LEDS-1) || (gradStartPos < 0) ) { // Check if outside NUM_LEDS range - gradStartPos = gradStartPos % NUM_LEDS; // Loop around as needed. - } + EVERY_N_MILLISECONDS(gradMoveDelay) { + uint8_t count = 0; + for (uint8_t i = gradStartPos; i < gradStartPos + gradLength; i++) { + leds[i % NUM_LEDS] = grad[count]; + count++; + } + FastLED.show(); // Display the pixels. + FastLED.clear(); // Clear the strip to not leave behind lit pixels as grad moves. + + gradStartPos = gradStartPos + gradDelta; // Update start position. + if ( (gradStartPos > NUM_LEDS - 1) || (gradStartPos < 0) ) { // Check if outside NUM_LEDS range + gradStartPos = gradStartPos % NUM_LEDS; // Loop around as needed. + } + + } //end EVERY_N gradMoveDelay - } //end EVERY_N gradMoveDelay - } //END MAIN LOOP diff --git a/moving_simple_pattern.ino b/moving_simple_pattern.ino index 4484791..37c9827 100644 --- a/moving_simple_pattern.ino +++ b/moving_simple_pattern.ino @@ -12,14 +12,14 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB -#define BRIGHTNESS 255 - -CRGB leds[NUM_LEDS]; //what gets displayed +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + +CRGB leds[NUM_LEDS]; CRGB base[NUM_LEDS]; int8_t delta = 1; // 1 or -1. (Negative value reverses direction.) @@ -30,31 +30,31 @@ uint8_t pos = 0; // position along strip //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check your baud rate) - delay(3000); // Startup delay - FastLED.addLeds(leds, NUM_LEDS); // ***For strips using Clock. - //FastLED.addLeds(leds, NUM_LEDS); // ***For Clock-less strips. - FastLED.setBrightness(BRIGHTNESS); - - //setup custom colors/pattern in the base array - fill_solid( base, NUM_LEDS, CHSV(200,160,55) ); // base color - base[0] = base[1] = base[2] = CRGB::Blue; //custom colors - base[3] = base[4] = base[5] = CRGB::Grey; - base[6] = base[7] = base[8] = CRGB::Red; + Serial.begin(115200); // Allows serial monitor output (check your baud rate) + delay(3000); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + + //setup custom colors/pattern in the base array + fill_solid( base, NUM_LEDS, CHSV(200, 160, 55) ); // base color + base[0] = base[1] = base[2] = CRGB::Blue; //custom colors + base[3] = base[4] = base[5] = CRGB::Grey; + base[6] = base[7] = base[8] = CRGB::Red; } //end setup //--------------------------------------------------------------- void loop() { - EVERY_N_MILLISECONDS(RATE) { - - for (uint8_t i = 0; i < NUM_LEDS; i++) { - leds[mod8(pos + delta + i, NUM_LEDS)] = base[i]; - } - FastLED.show(); // Display the pixels. - pos = pos + delta; - - } //end EVERY_N - + EVERY_N_MILLISECONDS(RATE) { + + for (uint8_t i = 0; i < NUM_LEDS; i++) { + leds[mod8(pos + delta + i, NUM_LEDS)] = base[i]; + } + FastLED.show(); // Display the pixels. + pos = pos + delta; + + } //end EVERY_N + } //end MAIN LOOP diff --git a/multiple_animations.ino b/multiple_animations.ino index c12d21b..79cade6 100644 --- a/multiple_animations.ino +++ b/multiple_animations.ino @@ -17,13 +17,14 @@ /*********************************************************************/ #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define COLOR_ORDER GRB -#define MASTER_BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 -#define NUM_LEDS 32 +CRGB leds[NUM_LEDS]; //Note: numA thru numD values must add up to NUM_LEDS #define numA 5 //pixels 0-4 @@ -40,88 +41,103 @@ CRGB ledsD[numD]; /*********************************************************************/ void setup() { - Serial.begin(115200); //allow for output to serial monitor - delay(2500); //power up delay - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(MASTER_BRIGHTNESS); - FastLED.clear(); - Serial.println("setup done"); + Serial.begin(115200); //allow for output to serial monitor + delay(2500); //power up delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); + Serial.println("setup done"); }//end_setup /*********************************************************************/ void loop() { - //--------------Animation A-------------- - static uint8_t color; - EVERY_N_MILLISECONDS(180) { - fadeToBlackBy( ledsA, numA, 230); - static uint8_t i = 0; - ledsA[i] = CHSV( color+random8(0,10), 160, 255 ); - i++; - if (i == numA) { i = 0; } //reset - - //copy ledsA data to leds - for (uint8_t i=0; i(leds, NUM_LEDS); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - colorIndex = startIndex; - for( int i = 0; i < NUM_LEDS; i++) { - //ColorFromPalette( paletteName, colorIndex[0-255], brightness[0-255], blendType[NOBLEND or LINEARBLEND]) - leds[i] = ColorFromPalette( RainbowColors_p, colorIndex, 255, LINEARBLEND); - colorIndex = colorIndex + 10; //how fast to advance through palette - } - - FastLED.show(); - FastLED.delay(10); - startIndex = startIndex + 1; //how fast to move the palette down the strip + colorIndex = startIndex; + for( int i = 0; i < NUM_LEDS; i++) { + //ColorFromPalette( paletteName, colorIndex[0-255], brightness[0-255], blendType[NOBLEND or LINEARBLEND]) + leds[i] = ColorFromPalette( RainbowColors_p, colorIndex, 255, LINEARBLEND); + colorIndex = colorIndex + 10; //how fast to advance through palette + } + + FastLED.show(); + FastLED.delay(10); + startIndex = startIndex + 1; //how fast to move the palette down the strip } diff --git a/palette_example2.ino b/palette_example2.ino index 02bd9fc..a52177b 100644 --- a/palette_example2.ino +++ b/palette_example2.ino @@ -16,14 +16,14 @@ #if FASTLED_VERSION < 3001000 #error "Requires FastLED 3.1 or later; check github for latest code." #endif +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB CRGB leds[NUM_LEDS]; -#define BRIGHTNESS 255 CRGBPalette256 currentPalette; CHSV hsv; @@ -31,59 +31,59 @@ CRGB rgb; //--------------------------------------------------------------- void setup() { - Serial.begin(115200); - delay(500); // startup delay - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); + delay(500); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop () { - EVERY_N_SECONDS(2){ - newGradientPalette(); - } - FastLED.show(); - FastLED.delay(100); + EVERY_N_SECONDS(2) { + newGradientPalette(); + } + FastLED.show(); + FastLED.delay(100); } //--------------------------------------------------------------- -void newGradientPalette(){ - uint8_t xyz[16]; // Needs to be 4 times however many colors are being used. - // 3 colors = 12, 4 colors = 16, etc. - - hsv = CHSV(random8(), 255, 255); // pick random hue - hsv2rgb_rainbow( hsv, rgb); // convert to R,G,B - - xyz[0] = 0; // anchor of first color - must be zero - xyz[1] = rgb.r; - xyz[2] = rgb.g; - xyz[3] = rgb.b; - - xyz[4] = random8(48,118); // random anchor point for second color - xyz[5] = 255; - xyz[6] = 0; - xyz[7] = 0; - - xyz[8] = random8(138,225); // random anchor point for third color - xyz[9] = 0, - xyz[10] = 255; - xyz[11] = 0; - - hsv = CHSV(random8(), 255, 255); // pick random hue - hsv2rgb_rainbow( hsv, rgb); // convert to R,G,B - - xyz[12] = 255; // anchor of last color - must be 255 - xyz[13] = rgb.r; - xyz[14] = rgb.g; - xyz[15] = rgb.b; - - currentPalette = xyz; - - for (int p = 0; p < NUM_LEDS; p++) { - leds[p] = ColorFromPalette(currentPalette, p*255/(NUM_LEDS-1), BRIGHTNESS, NOBLEND); - } +void newGradientPalette() { + uint8_t xyz[16]; // Needs to be 4 times however many colors are being used. + // 3 colors = 12, 4 colors = 16, etc. + + hsv = CHSV(random8(), 255, 255); // pick random hue + hsv2rgb_rainbow( hsv, rgb); // convert to R,G,B + + xyz[0] = 0; // anchor of first color - must be zero + xyz[1] = rgb.r; + xyz[2] = rgb.g; + xyz[3] = rgb.b; + + xyz[4] = random8(48, 118); // random anchor point for second color + xyz[5] = 255; + xyz[6] = 0; + xyz[7] = 0; + + xyz[8] = random8(138, 225); // random anchor point for third color + xyz[9] = 0, + xyz[10] = 255; + xyz[11] = 0; + + hsv = CHSV(random8(), 255, 255); // pick random hue + hsv2rgb_rainbow( hsv, rgb); // convert to R,G,B + + xyz[12] = 255; // anchor of last color - must be 255 + xyz[13] = rgb.r; + xyz[14] = rgb.g; + xyz[15] = rgb.b; + + currentPalette = xyz; + + for (int p = 0; p < NUM_LEDS; p++) { + leds[p] = ColorFromPalette(currentPalette, p * 255 / (NUM_LEDS - 1), BRIGHTNESS, NOBLEND); + } } diff --git a/patterns_of_blinking.ino b/patterns_of_blinking.ino index d4a7454..bb0bb30 100644 --- a/patterns_of_blinking.ino +++ b/patterns_of_blinking.ino @@ -17,12 +17,13 @@ #include "FastLED.h" -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 -#define BRIGHTNESS 64 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; #define ARRAY_SIZE(A) (sizeof(A) / sizeof((A)[0])) @@ -34,10 +35,10 @@ uint16_t patternDelay = 1000; //time to display each color [milliseconds] long colorA = 0x00FF7F; //using HEX long black = 0x000000; -CRGB temp = CRGB(200,64,200); //using RGB +CRGB temp = CRGB(200, 64, 200); //using RGB long colorB = ((long)temp.r << 16L) | ((long)temp.g << 8L) | (long)temp.b; -CRGB temp2 = CHSV(140,160,255); //using HSV +CRGB temp2 = CHSV(140, 160, 255); //using HSV long colorC = ((long)temp2.r << 16L) | ((long)temp2.g << 8L) | (long)temp2.b; @@ -72,46 +73,49 @@ uint8_t patternCount[nPatterns]; //keeps track of each pattern's current positi //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1500); // startup delay - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); - FastLED.show(); - - Serial.print("Number of patterns: "); Serial.println(nPatterns); - Serial.println("Number of colors per pattern: "); - for (uint8_t i=0; i < nPatterns; i++) { - Serial.print(" psize"); Serial.print(i); Serial.print(" = "); - Serial.println(patternSize[i]); - } - Serial.println("\nSetup done. \n"); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); + FastLED.show(); + + Serial.print("Number of patterns: "); + Serial.println(nPatterns); + Serial.println("Number of colors per pattern: "); + for (uint8_t i = 0; i < nPatterns; i++) { + Serial.print(" psize"); + Serial.print(i); + Serial.print(" = "); + Serial.println(patternSize[i]); + } + Serial.println("\nSetup done. \n"); } //--------------------------------------------------------------- void loop() { - EVERY_N_MILLISECONDS(patternDelay) { - - for (uint8_t p=0; p < nPatterns; p++) { - // Can use this to print out info for checking the pattern counts. - //Serial.print("p"); Serial.print(p); - //Serial.print(" patternCount: "); - //Serial.println(patternCount[p]); - - leds[p] = patternList[p][patternCount[p]]; - patternCount[p] = patternCount[p] + 1; - if (patternCount[p] == patternSize[p]) { - patternCount[p] = 0; //reset count for this pattern - } - } + EVERY_N_MILLISECONDS(patternDelay) { + + for (uint8_t p = 0; p < nPatterns; p++) { + // Can use this to print out info for checking the pattern counts. + //Serial.print("p"); Serial.print(p); + //Serial.print(" patternCount: "); + //Serial.println(patternCount[p]); + + leds[p] = patternList[p][patternCount[p]]; + patternCount[p] = patternCount[p] + 1; + if (patternCount[p] == patternSize[p]) { + patternCount[p] = 0; //reset count for this pattern + } + } + + FastLED.show(); //this can be moved outside the EVERY_N block as needed - FastLED.show(); //this can be moved outside the EVERY_N block as needed + }//end_EVERY_N - }//end_EVERY_N - }//end_main_loop diff --git a/print_HSV_values.ino b/print_HSV_values.ino index 2f9c2a2..88fb2c0 100644 --- a/print_HSV_values.ino +++ b/print_HSV_values.ino @@ -5,47 +5,51 @@ //*************************************************************** #include "FastLED.h" -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GBR -#define NUM_LEDS 32 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 -#define BRIGHTNESS 50 CRGB leds[NUM_LEDS]; CHSV hsv[NUM_LEDS]; //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1500); // startup delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // startup delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); } //--------------------------------------------------------------- void loop() { - EVERY_N_SECONDS( 5 ) { - - for (uint8_t i=0; i < NUM_LEDS; i++) { - hsv[i].h = random8(); - hsv[i].s = random8(200,256); - hsv[i].v = random8(64,85); - leds[i] = CHSV(hsv[i].h, hsv[i].s, hsv[i].v); - - Serial.print("HSV["); Serial.print(i); - Serial.print("]: "); Serial.print(hsv[i].h); - Serial.print(" "); Serial.print(hsv[i].s); - Serial.print(" "); Serial.println(hsv[i].v); - } - - FastLED.show(); - - }//end_EVERY_N + EVERY_N_SECONDS( 5 ) { + + for (uint8_t i = 0; i < NUM_LEDS; i++) { + hsv[i].h = random8(); + hsv[i].s = random8(200, 256); + hsv[i].v = random8(64, 85); + leds[i] = CHSV(hsv[i].h, hsv[i].s, hsv[i].v); + + Serial.print("HSV["); + Serial.print(i); + Serial.print("]: "); + Serial.print(hsv[i].h); + Serial.print(" "); + Serial.print(hsv[i].s); + Serial.print(" "); + Serial.println(hsv[i].v); + } + + FastLED.show(); + + }//end_EVERY_N }//end_main_loop diff --git a/quadwave8_fade_up.ino b/quadwave8_fade_up.ino index 587c658..ed29704 100644 --- a/quadwave8_fade_up.ino +++ b/quadwave8_fade_up.ino @@ -5,10 +5,13 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE NEOPIXEL // ***Update to your strip type. NEOPIXEL, APA102, LPD8806, etc. -#define DATA_PIN 6 // ***Remember to set this to your data pin -#define NUM_LEDS 12 // ***Remember to set this to your strip length -#define MASTER_BRIGHTNESS 255 // Master brightness range is 0-255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint16_t count; @@ -16,24 +19,25 @@ uint8_t speed = 15; // Higher number gives slower pulse //--------------------------------------------------------------- void setup() { - delay(1000); // Startup delay - Serial.begin(115200); // Allows serial monitor output (check baud rate) - FastLED.addLeds(leds, NUM_LEDS); // ***For Clock-less strips. - FastLED.setBrightness(MASTER_BRIGHTNESS); + delay(1000); // Startup delay + Serial.begin(115200); // Allows serial monitor output (check baud rate) + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - uint8_t value = quadwave8(count/speed); - //Serial.print(" count: "); Serial.print(count); - //Serial.print(" value: "); Serial.println(value); - for (int i=0; i= 255){ // If value is maxed out then reset count. - count = 0; - } + uint8_t value = quadwave8(count / speed); + //Serial.print(" count: "); Serial.print(count); + //Serial.print(" value: "); Serial.println(value); + for (int i = 0; i < NUM_LEDS; i++) { + leds[i] = CHSV(80, 255, value); + } + FastLED.show(); + count++; + if (value >= 255) { // If value is maxed out then reset count. + count = 0; + } } diff --git a/rainbow_brightness_and_saturation.ino b/rainbow_brightness_and_saturation.ino index b6fd729..39187fb 100644 --- a/rainbow_brightness_and_saturation.ino +++ b/rainbow_brightness_and_saturation.ino @@ -7,7 +7,13 @@ //*************************************************************** #include "FastLED.h" -#define NUM_LEDS 12 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint8_t V; //brightness for rainbow @@ -17,39 +23,43 @@ boolean toggleV; //Amount to tint (desaturate) rainbow. Can use either RGB or HSV format //CRGB tintAmt(128,128,128); -CHSV tintAmt(0,0,90); +CHSV tintAmt(0, 0, 90); //--------------------------------------------------------------- -void setup() { - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(255); +void setup() { + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- -void loop() -{ - fill_rainbow(leds, NUM_LEDS, millis()/100); //fill strip with moving rainbow +void loop() { + fill_rainbow(leds, NUM_LEDS, millis() / 100); //fill strip with moving rainbow + + EVERY_N_SECONDS(5) { + toggleS = !toggleS; //toggle Saturation (ie. "tint") + } + EVERY_N_SECONDS(30) { + toggleV = !toggleV; //toggle Value (brightness) + } - EVERY_N_SECONDS(5) { toggleS = !toggleS; } //toggle Saturation (ie. "tint") - EVERY_N_SECONDS(30) { toggleV = !toggleV; } //toggle Value (brightness) + if (toggleS) { + for (uint8_t i = 0; i < NUM_LEDS; i++) { + leds[i] += tintAmt; + } + } else { + //No tint added + } - if (toggleS) { - for (uint8_t i=0; i leds; // Operate on this array as if it had the correct layout. CRGBArray actual; // Display this array after mapping "leds" to "actual". //Since we'll opperate on our nicely arranged "leds" array, we can make a CRGBSet for each diamond. -CRGBSet d0( leds(PixelsPerDiamond*0, PixelsPerDiamond-1+(PixelsPerDiamond*0) )); //Define pixel range for diamond 0. -CRGBSet d1( leds(PixelsPerDiamond*1, PixelsPerDiamond-1+(PixelsPerDiamond*1) )); //Define pixel range for diamond 1. -CRGBSet d2( leds(PixelsPerDiamond*2, PixelsPerDiamond-1+(PixelsPerDiamond*2) )); //Define pixel range for diamond 2. +CRGBSet d0( leds(PixelsPerDiamond * 0, PixelsPerDiamond - 1 + (PixelsPerDiamond * 0) )); //Define pixel range for diamond 0. +CRGBSet d1( leds(PixelsPerDiamond * 1, PixelsPerDiamond - 1 + (PixelsPerDiamond * 1) )); //Define pixel range for diamond 1. +CRGBSet d2( leds(PixelsPerDiamond * 2, PixelsPerDiamond - 1 + (PixelsPerDiamond * 2) )); //Define pixel range for diamond 2. //etc.. @@ -48,36 +48,38 @@ CRGBSet d2( leds(PixelsPerDiamond*2, PixelsPerDiamond-1+(PixelsPerDiamond*2) //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // 3 second delay for recovery - - //***NOTE: Putting the CRGBArray "actual" in here, not "leds"*** - FastLED.addLeds(actual, NUM_LEDS); - - FastLED.setBrightness(BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay for recovery + + /* ********************* + NOTE: Putting the CRGBArray "actual" in here, not "leds"*** + * ********************* */ + // FastLED.addLeds(actual, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(actual, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - EVERY_N_SECONDS(3){ - static uint8_t hue; - for (uint8_t n=0; n < NumberOfDiamonds; n++){ - fill_rainbow( &(leds[ (n*PixelsPerDiamond) ]), PixelsPerDiamond, hue+millis(), 8 ); + EVERY_N_SECONDS(3) { + static uint8_t hue; + for (uint8_t n = 0; n < NumberOfDiamonds; n++) { + fill_rainbow( &(leds[ (n * PixelsPerDiamond) ]), PixelsPerDiamond, hue + millis(), 8 ); + } } - } - EVERY_N_SECONDS(12){ - random16_add_entropy( random() ); - uint8_t randomColor = random8(); //pick a random color - d0 = CHSV(randomColor,170,150); - d1 = CHSV(randomColor+64,170,150); - d2 = CHSV(randomColor-64,170,150); - } + EVERY_N_SECONDS(12) { + random16_add_entropy( random() ); + uint8_t randomColor = random8(); //pick a random color + d0 = CHSV(randomColor, 170, 150); + d1 = CHSV(randomColor + 64, 170, 150); + d2 = CHSV(randomColor - 64, 170, 150); + } - remap(); //***Always run the remap function just before calling show().*** - FastLED.show(); + remap(); //***Always run the remap function just before calling show().*** + FastLED.show(); }//end_main_loop @@ -85,18 +87,18 @@ void loop() { //--------------------------------------------------------------- // Function to remap "leds" array to "actual" array void remap() { - uint8_t mapped; - uint8_t diamondNumber; - for (uint8_t i=0; i < NUM_LEDS; i++) { - if (i % PixelsPerDiamond == 0) { - diamondNumber = i / PixelsPerDiamond; - mapped = (diamondNumber * PixelsPerDiamond) + 11; - actual[i] = leds[mapped]; - //Serial.print("Diamond#: "); Serial.println(diamondNumber); - } else { - mapped = i-1; - actual[i] = leds[mapped]; + uint8_t mapped; + uint8_t diamondNumber; + for (uint8_t i = 0; i < NUM_LEDS; i++) { + if (i % PixelsPerDiamond == 0) { + diamondNumber = i / PixelsPerDiamond; + mapped = (diamondNumber * PixelsPerDiamond) + 11; + actual[i] = leds[mapped]; + //Serial.print("Diamond#: "); Serial.println(diamondNumber); + } else { + mapped = i - 1; + actual[i] = leds[mapped]; + } + //Serial.print(" For leds[i] = "); Serial.print(i); Serial.print(" actual[i] = "); Serial.println(mapped); } - //Serial.print(" For leds[i] = "); Serial.print(i); Serial.print(" actual[i] = "); Serial.println(mapped); - } } diff --git a/repeating_block_pattern.ino b/repeating_block_pattern.ino index 09f485f..c7dd3f2 100644 --- a/repeating_block_pattern.ino +++ b/repeating_block_pattern.ino @@ -9,12 +9,13 @@ //*************************************************************** #include "FastLED.h" -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 -#define BRIGHTNESS 50 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint8_t blockSize = 5; // number of pixels to light up in a block @@ -27,42 +28,46 @@ uint16_t loopEnd = blockSize; //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1500); // startup delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); // clear strip data + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // startup delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); // clear strip data } //--------------------------------------------------------------- void loop() { - loopStart = count * blockSize; - loopEnd = blockSize + count*blockSize; - - // Trying to write data to pixels that don't exit is bad. - // Check to make sure we are still within our NUM_LEDS range - // and clamp to NUM_LEDS if needed. - if (loopEnd > NUM_LEDS) { loopEnd = NUM_LEDS; } // limit maximum to NUM_LEDS - - uint8_t hue = random8(); // for fun, pick a new color for each block - for(uint16_t i=loopStart; i < loopEnd; i++) { - leds[i] = CHSV( hue, 255, 255 ); - } - FastLED.delay(wait); - - for(uint16_t i=loopStart; i < loopEnd; i++) { - leds[i] = CRGB::Black; - } - - count++; // increase count by one - // reset count if we have come to the end of the strip - if ((count * blockSize) >= NUM_LEDS) { count = 0; } - - //EVERY_N_SECONDS(5){ - // blockSize = random8(2,9); // for fun, pick a new random block size - //} + loopStart = count * blockSize; + loopEnd = blockSize + count * blockSize; + + // Trying to write data to pixels that don't exit is bad. + // Check to make sure we are still within our NUM_LEDS range + // and clamp to NUM_LEDS if needed. + if (loopEnd > NUM_LEDS) { + loopEnd = NUM_LEDS; // limit maximum to NUM_LEDS + } + + uint8_t hue = random8(); // for fun, pick a new color for each block + for(uint16_t i = loopStart; i < loopEnd; i++) { + leds[i] = CHSV( hue, 255, 255 ); + } + FastLED.delay(wait); + + for(uint16_t i = loopStart; i < loopEnd; i++) { + leds[i] = CRGB::Black; + } + + count++; // increase count by one + // reset count if we have come to the end of the strip + if ((count * blockSize) >= NUM_LEDS) { + count = 0; + } + + //EVERY_N_SECONDS(5){ + // blockSize = random8(2,9); // for fun, pick a new random block size + //} }//end_main_loop diff --git a/repeating_pattern.ino b/repeating_pattern.ino index cb5b6cb..f683bcf 100644 --- a/repeating_pattern.ino +++ b/repeating_pattern.ino @@ -12,12 +12,13 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB -#define MASTER_BRIGHTNESS 100 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint8_t hue; // Pixel color @@ -28,50 +29,57 @@ uint16_t i; // A pixel position on the strip static uint16_t repeatEvery = 5; // Therefore the number of times the pattern will repeat down the strip is: -static uint16_t numberOfRepeats = NUM_LEDS/repeatEvery; +static uint16_t numberOfRepeats = NUM_LEDS / repeatEvery; //--------------------------------------------------------------- -void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(MASTER_BRIGHTNESS); - delay(2500); // Delay to make sure serial monitor is ready. - Serial.print("NumberOfRepeats = "); Serial.print(numberOfRepeats); - Serial.print(" within the strip of length "); Serial.print(NUM_LEDS); +void setup() { + Serial.begin(115200); // Allows serial monitor output (check baud rate) + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + delay(2500); // Delay to make sure serial monitor is ready. + Serial.print("NumberOfRepeats = "); + Serial.print(numberOfRepeats); + Serial.print(" within the strip of length "); + Serial.print(NUM_LEDS); Serial.println("."); } //END SETUP //--------------------------------------------------------------- void loop() { - - for (offset = 0; offset < repeatEvery; offset++) { // Operate on each repeating pixel set - hue = (255/repeatEvery) * offset; // Change the hue for each pixel set. - for (uint16_t x = 0; x < numberOfRepeats+1; x++) { - i = (repeatEvery*(x-1)) + repeatEvery + offset; // The pixel number to draw - if (i < NUM_LEDS) { // Only draw pixel numbers within NUM_LEDS - leds[i] = CHSV(hue,180,255); - Serial.print(" offset: "); Serial.print(offset); - Serial.print(" x: "); Serial.print(x); - Serial.print(" leds[i]: "); Serial.print(i); - Serial.print(" hue: "); Serial.println(hue); - FastLED.show(); // Display each pixel individually in a set - delay(100); - } - } //end of loop for pixel set - - Serial.println(" "); - // Uncomment the show() below and comment out the show() above to - // have all the pixels in a set display at the same time. - //FastLED.show(); // Display all pixels in a set at the same time. - - delay(800); // Pause before lighting next pixel set - } //end offset loop - - delay(1000); // pause before clearing - FastLED.clear(); // clear the strip - FastLED.delay(1400); // pause before starting over + + for (offset = 0; offset < repeatEvery; offset++) { // Operate on each repeating pixel set + hue = (255 / repeatEvery) * offset; // Change the hue for each pixel set. + for (uint16_t x = 0; x < numberOfRepeats + 1; x++) { + i = (repeatEvery * (x - 1)) + repeatEvery + offset; // The pixel number to draw + if (i < NUM_LEDS) { // Only draw pixel numbers within NUM_LEDS + leds[i] = CHSV(hue, 180, 255); + Serial.print(" offset: "); + Serial.print(offset); + Serial.print(" x: "); + Serial.print(x); + Serial.print(" leds[i]: "); + Serial.print(i); + Serial.print(" hue: "); + Serial.println(hue); + FastLED.show(); // Display each pixel individually in a set + delay(100); + } + } //end of loop for pixel set + + Serial.println(" "); + // Uncomment the show() below and comment out the show() above to + // have all the pixels in a set display at the same time. + //FastLED.show(); // Display all pixels in a set at the same time. + + delay(800); // Pause before lighting next pixel set + } //end offset loop + + delay(1000); // pause before clearing + FastLED.clear(); // clear the strip + FastLED.delay(1400); // pause before starting over } //END MAIN LOOP diff --git a/sin_cos_linear_test.ino b/sin_cos_linear_test.ino index 9747b5d..f306c86 100644 --- a/sin_cos_linear_test.ino +++ b/sin_cos_linear_test.ino @@ -12,12 +12,13 @@ #include #include "FastLED.h" -#define LED_TYPE LPD8806 -#define NUM_LEDS 32 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define COLOR_ORDER GRB -#define MASTER_BRIGHTNESS 255 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; uint8_t potValue; // Simulated potentiometer value. @@ -29,78 +30,83 @@ uint16_t slowBy = 15; // miliseconds to delay /*********************************************************************/ //PROGRAM SETUP void setup() { - Serial.begin(115200); // Allow for output to serial monitor - delay(2000); // power up safety delay - FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(MASTER_BRIGHTNESS); -}//END SETUP + Serial.begin(115200); // Allow for output to serial monitor + delay(2000); // power up safety delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); +} //END SETUP /*********************************************************************/ //MAIN LOOP void loop() { - //====run forward direction==== - for (potValue = 0; potValue < 255; potValue++) { - sin_output = sin8(potValue); - cos_output = cos8(potValue); - - for (uint8_t j = 0; j < 2; j++) { - leds[j] = CHSV(sin_output, 255, 255); - } - for (uint8_t j = 2; j < 4; j++) { - leds[j] = CHSV(cos_output, 255, 255); + //====run forward direction==== + for (potValue = 0; potValue < 255; potValue++) { + sin_output = sin8(potValue); + cos_output = cos8(potValue); + + for (uint8_t j = 0; j < 2; j++) { + leds[j] = CHSV(sin_output, 255, 255); + } + for (uint8_t j = 2; j < 4; j++) { + leds[j] = CHSV(cos_output, 255, 255); + } + for (uint8_t j = 4; j < 6; j++) { + leds[j] = CHSV(potValue, 255, 255); + } + + FastLED.show(); + Serial.print(" potValue = "); + Serial.print(potValue); + Serial.print("\tsin8: "); + Serial.print(sin_output); + Serial.print("\tcos8: "); + Serial.println(cos_output); + + //Blink pixel 7 white as a visual to show loop ends. + if (potValue == 0) { + leds[7] = CHSV(0, 0, 64); + Serial.println("----------------------------------------------"); + } else { + leds[7] = CRGB::Black; + } + + delay(slowBy); } - for (uint8_t j = 4; j < 6; j++) { - leds[j] = CHSV(potValue, 255, 255); - } - - FastLED.show(); - Serial.print(" potValue = "); Serial.print(potValue); - Serial.print("\tsin8: "); Serial.print(sin_output); - Serial.print("\tcos8: "); Serial.println(cos_output); - //Blink pixel 7 white as a visual to show loop ends. - if (potValue == 0) { - leds[7] = CHSV(0,0,64); - Serial.println("----------------------------------------------"); + //====run reverse direction==== + for (potValue = 255; potValue > 0; potValue--) { + sin_output = sin8(potValue); + cos_output = cos8(potValue); + + for (uint8_t j = 0; j < 2; j++) { + leds[j] = CHSV(sin_output, 255, 255); + } + for (uint8_t j = 2; j < 4; j++) { + leds[j] = CHSV(cos_output, 255, 255); + } + for (uint8_t j = 4; j < 6; j++) { + leds[j] = CHSV(potValue, 255, 255); + } + + FastLED.show(); + Serial.print(" potValue = "); + Serial.print(potValue); + Serial.print("\tsin8: "); + Serial.print(sin_output); + Serial.print("\tcos8: "); + Serial.println(cos_output); + + //Blink pixel 7 white as a visual to show loop ends. + if (potValue == 255) { + leds[7] = CHSV(0, 0, 64); + Serial.println("----------------------------------------------"); + } else { + leds[7] = CRGB::Black; + } + + delay(slowBy); } - else { - leds[7] = CRGB::Black; - } - - delay(slowBy); - } - - //====run reverse direction==== - for (potValue = 255; potValue > 0; potValue--) { - sin_output = sin8(potValue); - cos_output = cos8(potValue); - - for (uint8_t j = 0; j < 2; j++) { - leds[j] = CHSV(sin_output, 255, 255); - } - for (uint8_t j = 2; j < 4; j++) { - leds[j] = CHSV(cos_output, 255, 255); - } - for (uint8_t j = 4; j < 6; j++) { - leds[j] = CHSV(potValue, 255, 255); - } - - FastLED.show(); - Serial.print(" potValue = "); Serial.print(potValue); - Serial.print("\tsin8: "); Serial.print(sin_output); - Serial.print("\tcos8: "); Serial.println(cos_output); - - //Blink pixel 7 white as a visual to show loop ends. - if (potValue == 255) { - leds[7] = CHSV(0,0,64); - Serial.println("----------------------------------------------"); - } - else { - leds[7] = CRGB::Black; - } - - delay(slowBy); - } }//END MAIN LOOP diff --git a/test_ArrayOfLedArrays.ino b/test_ArrayOfLedArrays.ino index 5a29065..698d3e3 100644 --- a/test_ArrayOfLedArrays.ino +++ b/test_ArrayOfLedArrays.ino @@ -3,66 +3,79 @@ //--------------------------------------------------------------- #include "FastLED.h" -#define LED_TYPE NEOPIXEL -#define NUM_STRIPS 3 // Total number of strips +#define LED_TYPE NEOPIXEL +#define NUM_STRIPS 3 // Total number of strips -#define NUM_LEDS 12 // Specify length of each strip -#define NUM_LEDS1 32 -#define NUM_LEDS2 30 +// Specify details for each of the strips +#define NUM_LEDS1 12 // Specify length of each strip +#define DATA_PIN1 6 // Specify data pin for each strip + +#define NUM_LEDS2 32 +#define DATA_PIN2 11 + +#define NUM_LEDS3 30 +#define DATA_PIN3 13 //etc. -CRGB leds[NUM_STRIPS][NUM_LEDS + NUM_LEDS1 + NUM_LEDS2]; // Add all together here +CRGB leds[NUM_STRIPS][NUM_LEDS1 + NUM_LEDS2 + NUM_LEDS3]; // Add all together here uint8_t stripLength; // Used to store a strip length. //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); - FastLED.addLeds(leds[0], NUM_LEDS); // Assign data pins - FastLED.addLeds(leds[1], NUM_LEDS1); - FastLED.addLeds(leds[2], NUM_LEDS2); - //etc. + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); + + FastLED.addLeds(leds[0], NUM_LEDS1); + FastLED.addLeds(leds[1], NUM_LEDS2); + FastLED.addLeds(leds[2], NUM_LEDS3); + //etc. } //--------------------------------------------------------------- void loop() { - for(uint8_t x = 0; x < NUM_STRIPS; x++) { - stripLength = getStripLength(x); - fill_rainbow( leds[x], stripLength, millis()/3, 256/stripLength ); - } - FastLED.show(); - delay(3000); - - for(uint8_t x = 0; x < NUM_STRIPS; x++) { - stripLength = getStripLength(x); - uint8_t randomColor = random8(); - fill_solid(leds[x], stripLength, CHSV(randomColor,255,255)); - } - FastLED.show(); - delay(2000); - - FastLED.clear(); // Clear all data - FastLED.show(); - delay(1000); + for(uint8_t x = 0; x < NUM_STRIPS; x++) { + stripLength = getStripLength(x); + fill_rainbow( leds[x], stripLength, millis() / 3, 256 / stripLength ); + } + FastLED.show(); + delay(3000); + + for(uint8_t x = 0; x < NUM_STRIPS; x++) { + stripLength = getStripLength(x); + uint8_t randomColor = random8(); + fill_solid(leds[x], stripLength, CHSV(randomColor, 255, 255)); + } + FastLED.show(); + delay(2000); + + FastLED.clear(); // Clear all data + FastLED.show(); + delay(1000); }//end main loop //-----function to return strip length----- -uint8_t getStripLength(uint8_t stripNumber){ - uint8_t L; - if (stripNumber == 0) { L = NUM_LEDS; } - if (stripNumber == 1) { L = NUM_LEDS1; } - if (stripNumber == 2) { L = NUM_LEDS2; } - //etc. - - //Serial.print("stripNumber "); - //Serial.print(stripNumber); - //Serial.print(" = "); - //Serial.println(L); - return L; +uint8_t getStripLength(uint8_t stripNumber) { + uint8_t L; + if (stripNumber == 0) { + L = NUM_LEDS1; + } + if (stripNumber == 1) { + L = NUM_LEDS2; + } + if (stripNumber == 2) { + L = NUM_LEDS3; + } + //etc. + + //Serial.print("stripNumber "); + //Serial.print(stripNumber); + //Serial.print(" = "); + //Serial.println(L); + return L; } diff --git a/three_moving_colors.ino b/three_moving_colors.ino index f4c0802..c473e93 100644 --- a/three_moving_colors.ino +++ b/three_moving_colors.ino @@ -6,16 +6,17 @@ //*************************************************************** #include "FastLED.h" -#define LED_TYPE LPD8806 -#define DATA_PIN 11 -#define CLOCK_PIN 13 -#define NUM_LEDS 32 -#define COLOR_ORDER GRB -#define MASTER_BRIGHTNESS 64 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; -int16_t positionRed = NUM_LEDS*2/3; // Set initial start position of Red -int16_t positionWhite = NUM_LEDS/3; // Set initial start position of White +int16_t positionRed = NUM_LEDS * 2 / 3; // Set initial start position of Red +int16_t positionWhite = NUM_LEDS / 3; // Set initial start position of White int16_t positionBlue = 0; // Set initial start position of Blue #define holdTime 120 // Milliseconds to hold position before advancing @@ -24,31 +25,31 @@ int8_t delta = 1; // 1 or -1. Sets forward or backwards direction. //--------------------------------------------------------------- void setup() { - delay(1500); // Startup delay - FastLED.addLeds(leds, NUM_LEDS); - //FastLED.addLeds(leds, NUM_LEDS); - FastLED.setBrightness(MASTER_BRIGHTNESS); + delay(1500); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { - EVERY_N_MILLISECONDS(holdTime) { - - //set position and color of pixels - leds[(positionRed + delta + NUM_LEDS) % NUM_LEDS] = CRGB::Red; - leds[(positionWhite + delta + NUM_LEDS) % NUM_LEDS] = CRGB::Grey; - leds[(positionBlue + delta + NUM_LEDS) % NUM_LEDS] = CRGB::Blue; - - FastLED.show(); //show the pixels - - //advance position based on delta, and rollover if needed. - positionRed = ((positionRed + delta + NUM_LEDS) % NUM_LEDS); - positionWhite = ((positionWhite + delta + NUM_LEDS) % NUM_LEDS); - positionBlue = ((positionBlue + delta + NUM_LEDS) % NUM_LEDS); - - }//end_every_n + EVERY_N_MILLISECONDS(holdTime) { + + //set position and color of pixels + leds[(positionRed + delta + NUM_LEDS) % NUM_LEDS] = CRGB::Red; + leds[(positionWhite + delta + NUM_LEDS) % NUM_LEDS] = CRGB::Grey; + leds[(positionBlue + delta + NUM_LEDS) % NUM_LEDS] = CRGB::Blue; + + FastLED.show(); //show the pixels + + //advance position based on delta, and rollover if needed. + positionRed = ((positionRed + delta + NUM_LEDS) % NUM_LEDS); + positionWhite = ((positionWhite + delta + NUM_LEDS) % NUM_LEDS); + positionBlue = ((positionBlue + delta + NUM_LEDS) % NUM_LEDS); + + }//end_every_n }//end_main_loop diff --git a/three_moving_pixels_v3.ino b/three_moving_pixels_v3.ino index 263aebe..33bc52b 100644 --- a/three_moving_pixels_v3.ino +++ b/three_moving_pixels_v3.ino @@ -8,12 +8,13 @@ #include "FastLED.h" -#define LED_TYPE NEOPIXEL // Strip type: NEOPIXEL, APA102, LPD8806, etc. -#define DATA_PIN 6 -//#define CLOCK_PIN 13 -#define NUM_LEDS 12 -//#define COLOR_ORDER BGR -#define MASTER_BRIGHTNESS 100 // Master brightness (Range is 0-255) +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; int16_t positionRed = 0; // Set initial start position of Red pixel @@ -25,44 +26,44 @@ uint16_t holdTime = 1000; // Milliseconds to hold position before advancing //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check your baud rate) - delay(3000); // Startup delay - //FastLED.addLeds,COLOR_ORDER,(leds, NUM_LEDS); // ***For strips using Clock. - FastLED.addLeds(leds, NUM_LEDS); // ***For Clock-less strips. - FastLED.setBrightness(MASTER_BRIGHTNESS); + Serial.begin(115200); // Allows serial monitor output (check your baud rate) + delay(3000); // Startup delay + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); } //--------------------------------------------------------------- void loop() { // START MAIN LOOP - EVERY_N_MILLISECONDS(holdTime) { + EVERY_N_MILLISECONDS(holdTime) { + + // Set pixel color + leds[positionRed] = CRGB::Red; + leds[positionWhite] = CRGB::White; + leds[positionBlue] = CRGB::Blue; + + // Show the pixels + FastLED.show(); + //delay(holdTime); // Delay for a bit. + + // Set pixels back to Black for the next loop around. + leds[positionRed] = CRGB::Black; + leds[positionWhite] = CRGB::Black; + leds[positionBlue] = CRGB::Black; - // Set pixel color - leds[positionRed] = CRGB::Red; - leds[positionWhite] = CRGB::White; - leds[positionBlue] = CRGB::Blue; - - // Show the pixels - FastLED.show(); - //delay(holdTime); // Delay for a bit. - - // Set pixels back to Black for the next loop around. - leds[positionRed] = CRGB::Black; - leds[positionWhite] = CRGB::Black; - leds[positionBlue] = CRGB::Black; - - // Set new position, moving (forward or backward) by delta. - // NUM_LEDS is added to the position before doing the modulo - // to cover cases where delta is a negative value. - positionRed = (positionRed + delta + NUM_LEDS) % NUM_LEDS; - positionWhite = (positionWhite + delta + NUM_LEDS) % NUM_LEDS; - positionBlue = (positionBlue + delta + NUM_LEDS) % NUM_LEDS; + // Set new position, moving (forward or backward) by delta. + // NUM_LEDS is added to the position before doing the modulo + // to cover cases where delta is a negative value. + positionRed = (positionRed + delta + NUM_LEDS) % NUM_LEDS; + positionWhite = (positionWhite + delta + NUM_LEDS) % NUM_LEDS; + positionBlue = (positionBlue + delta + NUM_LEDS) % NUM_LEDS; - // Print out position values to see what's happening. - //Serial.print("pos R = "); Serial.print(positionRed); - //Serial.print("\t pos W = "); Serial.print(positionWhite); - //Serial.print("\t pos B = "); Serial.println(positionBlue); - } + // Print out position values to see what's happening. + //Serial.print("pos R = "); Serial.print(positionRed); + //Serial.print("\t pos W = "); Serial.print(positionWhite); + //Serial.print("\t pos B = "); Serial.println(positionBlue); + } } // END MAIN LOOP diff --git a/toggle_pixels_off_with_button.ino b/toggle_pixels_off_with_button.ino index e000fca..b3e37c0 100644 --- a/toggle_pixels_off_with_button.ino +++ b/toggle_pixels_off_with_button.ino @@ -31,38 +31,38 @@ Button OnOff_Button(ButtonPin, true, true, 100); //--------------------------------------------------------------- #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; -#define BRIGHTNESS 128 boolean OnOff_Status = 1; // Status of extra pixels. [1=On, 0=Off] //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(1500); // short delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(1500); // short delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); } //--------------------------------------------------------------- -void loop() -{ - readbutton(); // check the button to see if it's been pressed +void loop() { + readbutton(); // check the button to see if it's been pressed + + fill_rainbow( leds, NUM_LEDS, millis() / 20 ); - fill_rainbow( leds, NUM_LEDS, millis()/20 ); - - extraLeds_OnOff(); // always run right before FastLED.show() - FastLED.show(); // display the pixels + extraLeds_OnOff(); // always run right before FastLED.show() + FastLED.show(); // display the pixels }//end_main_loop @@ -75,25 +75,26 @@ void loop() //--------------------------------------------------------------- //Check the button and set the appropriate flag void readbutton() { - OnOff_Button.read(); // check the state of the button + OnOff_Button.read(); // check the state of the button - if(OnOff_Button.wasPressed()) { - OnOff_Status = !OnOff_Status; - Serial.print("OnOff_Status: "); Serial.println(OnOff_Status); - } + if(OnOff_Button.wasPressed()) { + OnOff_Status = !OnOff_Status; + Serial.print("OnOff_Status: "); + Serial.println(OnOff_Status); + } }//end_readbutton //--------------------------------------------------------------- // Turn extra pixels on or off -void extraLeds_OnOff(){ +void extraLeds_OnOff() { - if (OnOff_Status ==0) { - for (uint8_t i=24; i < NUM_LEDS; i++) { //i=24 is the first pixel in the extras to be turned off. - leds[i] = CRGB::Black; // turn "off" + if (OnOff_Status == 0) { + for (uint8_t i = 24; i < NUM_LEDS; i++) { //i=24 is the first pixel in the extras to be turned off. + leds[i] = CRGB::Black; // turn "off" + } } - } }//end_extraLeds_OnOff diff --git a/trigger_update_from_input.ino b/trigger_update_from_input.ino index eb72fef..04d8cd3 100644 --- a/trigger_update_from_input.ino +++ b/trigger_update_from_input.ino @@ -7,66 +7,69 @@ // // This example uses JChristensen's Button Library from: // https://github.com/JChristensen/Button -// +// // // Marc Miller, Feb 2017 //*************************************************************** #include "FastLED.h" -#define DATA_PIN 11 -#define CLK_PIN 13 -#define LED_TYPE LPD8806 -#define COLOR_ORDER GRB -#define NUM_LEDS 32 -#define BRIGHTNESS 50 +#define LED_TYPE APA102 +#define DATA_PIN 11 +#define CLK_PIN 13 +#define NUM_LEDS 32 +#define COLOR_ORDER BGR +#define BRIGHTNESS 128 + CRGB leds[NUM_LEDS]; -// use JChristensen's Button library -#include "Button.h" +// use JChristensen's Button library +#include "Button.h" const int buttonPin = 4; // digital pin used for debounced push button Button myButton(buttonPin, true, true, 40); // declare the button -uint8_t pos = NUM_LEDS-1; // set initial position +uint8_t pos = NUM_LEDS - 1; // set initial position boolean input = false; // set input status //--------------------------------------------------------------- void setup() { - Serial.begin(115200); // Allows serial monitor output (check baud rate) - delay(3000); // 3 second delay for recovery - //FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); - FastLED.setBrightness(BRIGHTNESS); - FastLED.clear(); - Serial.println("Setup done. \n"); + Serial.begin(115200); // Allows serial monitor output (check baud rate) + delay(3000); // 3 second delay for recovery + // FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.addLeds(leds, NUM_LEDS).setCorrection(TypicalLEDStrip); + FastLED.setBrightness(BRIGHTNESS); + FastLED.clear(); + Serial.println("Setup done. \n"); } //--------------------------------------------------------------- void loop() { - checkInput(); // calls funtion to check the input + checkInput(); // calls funtion to check the input - if (input == true) { - leds[pos] = CRGB::Black; // turn off previously lit pixel - pos++; // Advance to next pixel - if (pos == NUM_LEDS) { pos = 0; } // rollover if needed - leds[pos] = CHSV(random8(),255,255); // turn on new pixel with random color - //input = false; // set input status back to false - } + if (input == true) { + leds[pos] = CRGB::Black; // turn off previously lit pixel + pos++; // Advance to next pixel + if (pos == NUM_LEDS) { + pos = 0; // rollover if needed + } + leds[pos] = CHSV(random8(), 255, 255); // turn on new pixel with random color + //input = false; // set input status back to false + } - FastLED.show(); // update the display + FastLED.show(); // update the display }//end_main_loop //--------------------------------------------------------------- -void checkInput(){ // function to check input - myButton.read(); - if(myButton.wasPressed() ) { - Serial.println("Button pressed!"); - input = true; // set input status to true - } else { - input = false; - } +void checkInput() { // function to check input + myButton.read(); + if(myButton.wasPressed() ) { + Serial.println("Button pressed!"); + input = true; // set input status to true + } else { + input = false; + } }//end_checkInput