Programmable LED strip - how to turn off with code?

I have searched with no luck to find some code to turn off my LEDs (above) during the day

1 Like

Do you think it would help if you told us what sort of LEDs you have? And what library and code you are using to switch them on? They don't all work the same.

Steve

Sure...I am using Adafruit_NeoPixel and FastLED for 2 different effects....the programmable LED strip is from Alitov.

There is a ".fill" method for both those libraries. Use that to set all the LEDs to black.

For the FastLed library there is a fill_solid method:-

An example is:-

void fill_solid (struct CRGB *leds, int numToFill, const struct CRGB &color)
 fill_solid - fill a range of LEDs with a solid color Example: fill_solid( leds, NUM_LEDS, CRGB(50,0,200));

From :- The documentation

Or just write a for loop that sets each LED to black.
Post your code if you don't know enough to incorporate this into you code.

FastLED also has the FastLED.clear() function, which sets all the pixels to Black. You do of course have to do FastLED.show() to send the data out to the LEDs.

Wow, thanks! First time using the Forum!

I must have seen 100 Youtube videos on Andruino programming and never once saw that you can get all the Library detail either....

Having looked, I don't see the "clear" function listed...is that odd?

Turing to black from Karma .... the code is 0, 0, 0 ?

Kingdragon8:
Having looked, I don't see the "clear" function listed...is that odd?

Only place I can find it is in the documentation for classes http://fastled.io/docs/3.1/class_c_fast_l_e_d.html#a042989511cbc42390620bedc196ea956

Just noticed while looking that up that the clear function takes a parameter. By default it clears the CRGB array, then you need FastLED.show() afterwards, giving it a parameter of true clears the CRGB array and also turns the LEDs off FastLED.clear(true)

thanks...that's a little higher than my skill set so far!

I couldn't figure out that code unless it is as simple as calling the .clear class than the .show?

Kingdragon8:
I couldn't figure out that code unless it is as simple as calling the .clear class than the .show?

It is that simple.

I am stuck again! Need help please! This is for a solar powered mail box with a programmable LED strip around the roof, santa lights, interior lights, and porch lights. It worked except I needed to turn off the LED strip to conserve energy...

Now it won't do anything! Note: the "second" is actually "hour" but I am using "second" to check functionality.
won't even print the "made it here" on my serial monitor!

Here is the code

// A2 - roofRainbow as function, added 470 ohm resistor
// A3b - adds clock and both roof rainbow and snowflake working

// A5 - adding LEDS
// A6-2 roof plus house working
//A7 - frozen roof lights attributed to long delay in santa loop
// In-box Dec 9 - adding clear function

#include <FastLED.h>
#include <Adafruit_NeoPixel.h>
#define PIN 7
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
#include <Wire.h>
#include <DS3231.h>
DS3231 clock;
RTCDateTime dt;

FASTLED_USING_NAMESPACE

// FastLED "100-lines-of-code" demo reel, showing just a few
// of the kinds of animation patterns you can quickly and easily
// compose using FastLED.
//
// This example also shows one easy way to define multiple
// animations patterns and have them automatically rotate.
//
// -Mark Kriegsman, December 2014

#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning "Requires FastLED 3.1 or later; check github for latest code."
#endif

#define DATA_PIN 7
//#define CLK_PIN 4
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 156
CRGB leds[NUM_LEDS];

#define BRIGHTNESS 70
#define FRAMES_PER_SECOND 120
int leftWf = 4;
int ledPin1 = 5;
int ledPin2 = 9;
int ledPin3 = 6;
int ledPin4 = 10;
int ledPin5 = 11;
int ledPin6 = 12;
int ledPin7 = 8;
int santa2 = 3;
int santa1 = 2;
//-----------------------------------------------------

void setup() {
delay(1000); // 1 second delay for recovery
Serial.begin(9600);
clock.begin();
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
strip.begin();
strip.setBrightness(10);
strip.show(); // Initialize all pixels to 'off'
pinMode(leftWf, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(santa2, OUTPUT);
pinMode(santa1, OUTPUT);

}

// List of patterns to cycle through. Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter };

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns

void roofRainbow ()
{
// Call the current pattern function once, updating the 'leds' array
gPatternsgCurrentPatternNumber;

// 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
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 rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}

void snowflakes() {

// Setup the pixel array
int pixel[60];
for(int p=0; p<60; p++){
pixel[p] = random(0,255);
}

// Run some snowflake cycles
for (int j=0; j<200; j++) {

// Every five cycles, light a new pixel
if((j%500)==0){
strip.setPixelColor(random(0,60), 255,255,255);
}

// Dim all pixels by 10
for(int p=0; p<60; p++){
strip.setPixelColor(p, pixel[p],pixel[p],pixel[p] );
pixel[p] = pixel[p] - 10;
}
strip.show();
delay(100);
}
}
//------------------------------------------------------
void houseLights ()
{
// LED Fire Effect
analogWrite(ledPin1, random(60)+195);
analogWrite(ledPin3, random(60)+195);
analogWrite(ledPin5, random(60)+195);
analogWrite(ledPin6, random(60)+195);
analogWrite(leftWf, random(60)+195);
delay(random(50));
}
//-----------------------------------------------------
//-----------------------------------------------------

void santaClause ()
{
// LED Fire Effect
analogWrite(santa2, 255);
analogWrite(santa1, 255);
delay(random(50));
}
//-----------------------------------------------------
void porchLight () {
// LED Fire Effect
analogWrite(ledPin2, random(220)+135);

delay(random(50));
}
//-----------------------------------------------------
void roofOff () {
// clears all roof LEDs to off
FastLED.clear();
FastLED.show();
delay(random(50));
}
//-----------------------------------------------------
void loop()
{
dt = clock.getDateTime();
Serial.print('minute');
Serial.print("made it here");
// First hour turn on house, santa and porch lights only
if (dt.second > 17 && dt.second < 27) {

houseLights () ;
santaClause () ;
porchLight () ;
}
// Second hour turns on snowflake and all other lights
else if (dt.second > 27 && dt.second < 37) {
snowflakes();
houseLights () ;
santaClause () ;
porchLight () ;
}
// Third and Forth hour turns on roofRainbow and all other lights
else if (dt.second > 37 && dt.second < 57) {
roofRainbow ();
houseLights () ;
santaClause () ;
porchLight () ;
}
else{
analogWrite(ledPin1, 0);
analogWrite(ledPin3, 0);
analogWrite(ledPin5, 0);
analogWrite(ledPin6, 0);
analogWrite(ledPin2, 0);
analogWrite(ledPin7, 0);
analogWrite(leftWf, 0);
analogWrite(santa1, 0);
roofOff();

}
}

Can you edit that code and put it in code tags. Select all the code and hit the </> icon in the top left hand row of icons in he reply box.

What sort of Arduino are you running this code on.
I ask this because not all the pins on most Arduinos are capable of working with an analogWrite call.

// A2 - roofRainbow as function, added 470 ohm resistor
// A3b - adds clock and both roof rainbow and snowflake working

// A5 - adding LEDS
// A6-2 roof plus house working
//A7 - frozen roof lights attributed to long delay in santa loop
// In-box Dec 9 - adding clear function

#include <FastLED.h>
#include <Adafruit_NeoPixel.h>
#define PIN 7
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
#include <Wire.h>
#include <DS3231.h>
DS3231 clock;
RTCDateTime dt;

FASTLED_USING_NAMESPACE

// FastLED "100-lines-of-code" demo reel, showing just a few
// of the kinds of animation patterns you can quickly and easily
// compose using FastLED.
//
// This example also shows one easy way to define multiple
// animations patterns and have them automatically rotate.
//
// -Mark Kriegsman, December 2014

#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning "Requires FastLED 3.1 or later; check github for latest code."
#endif

#define DATA_PIN 7
//#define CLK_PIN 4
#define LED_TYPE WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS 156
CRGB leds[NUM_LEDS];

#define BRIGHTNESS 70
#define FRAMES_PER_SECOND 120
int leftWf = 4;
int ledPin1 = 5;
int ledPin2 = 9;
int ledPin3 = 6;
int ledPin4 = 10;
int ledPin5 = 11;
int ledPin6 = 12;
int ledPin7 = 8;
int santa2 = 3;
int santa1 = 2;
//-----------------------------------------------------

void setup() {
delay(1000); // 1 second delay for recovery
Serial.begin(9600);
clock.begin();
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
//FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

// set master brightness control
FastLED.setBrightness(BRIGHTNESS);
strip.begin();
strip.setBrightness(10);
strip.show(); // Initialize all pixels to 'off'
pinMode(leftWf, OUTPUT);
pinMode(ledPin1, OUTPUT);
pinMode(ledPin2, OUTPUT);
pinMode(ledPin3, OUTPUT);
pinMode(ledPin4, OUTPUT);
pinMode(ledPin5, OUTPUT);
pinMode(ledPin6, OUTPUT);
pinMode(ledPin7, OUTPUT);
pinMode(santa2, OUTPUT);
pinMode(santa1, OUTPUT);

}

// List of patterns to cycle through. Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter };

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns

void roofRainbow ()
{
// Call the current pattern function once, updating the 'leds' array
gPatternsgCurrentPatternNumber;

// 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
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 rainbow()
{
// FastLED's built-in rainbow generator
fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter()
{
// built-in FastLED rainbow, plus some random sparkly glitter
rainbow();
addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter)
{
if( random8() < chanceOfGlitter) {
leds[ random16(NUM_LEDS) ] += CRGB::White;
}
}

void snowflakes() {

// Setup the pixel array
int pixel[60];
for(int p=0; p<60; p++){
pixel[p] = random(0,255);
}

// Run some snowflake cycles
for (int j=0; j<200; j++) {

// Every five cycles, light a new pixel
if((j%500)==0){
strip.setPixelColor(random(0,60), 255,255,255);
}

// Dim all pixels by 10
for(int p=0; p<60; p++){
strip.setPixelColor(p, pixel[p],pixel[p],pixel[p] );
pixel[p] = pixel[p] - 10;
}
strip.show();
delay(100);
}
}
//------------------------------------------------------
void houseLights ()
{
// LED Fire Effect
analogWrite(ledPin1, random(60)+195);
analogWrite(ledPin3, random(60)+195);
analogWrite(ledPin5, random(60)+195);
analogWrite(ledPin6, random(60)+195);
analogWrite(leftWf, random(60)+195);
delay(random(50));
}
//-----------------------------------------------------
//-----------------------------------------------------

void santaClause ()
{
// LED Fire Effect
analogWrite(santa2, 255);
analogWrite(santa1, 255);
delay(random(50));
}
//-----------------------------------------------------
void porchLight () {
// LED Fire Effect
analogWrite(ledPin2, random(220)+135);

delay(random(50));
}
//-----------------------------------------------------
void roofOff () {
// clears all roof LEDs to off
FastLED.clear();
FastLED.show();
delay(random(50));
}
//-----------------------------------------------------
void loop()
{
dt = clock.getDateTime();
Serial.print('minute');
Serial.print("made it here");
// First hour turn on house, santa and porch lights only
if (dt.second > 17 && dt.second < 27) {

houseLights () ;
santaClause () ;
porchLight () ;
}
// Second hour turns on snowflake and all other lights
else if (dt.second > 27 && dt.second < 37) {
snowflakes();
houseLights () ;
santaClause () ;
porchLight () ;
}
// Third and Forth hour turns on roofRainbow and all other lights
else if (dt.second > 37 && dt.second < 57) {
roofRainbow ();
houseLights () ;
santaClause () ;
porchLight () ;
}
else{
analogWrite(ledPin1, 0);
analogWrite(ledPin3, 0);
analogWrite(ledPin5, 0);
analogWrite(ledPin6, 0);
analogWrite(ledPin2, 0);
analogWrite(ledPin7, 0);
analogWrite(leftWf, 0);
analogWrite(santa1, 0);
roofOff();

}
}

I am using a Mega..and all the write worked before!

Here is the code...which i didnt do correctly last time! UGH!

// A2 - roofRainbow as function, added 470 ohm resistor
// A3b - adds clock and both roof rainbow and snowflake working

// A5 - adding LEDS
// A6-2 roof plus house working
//A7 - frozen roof lights attributed to long delay in santa loop
// In-box Dec 9 - adding clear function

#include <FastLED.h>
#include <Adafruit_NeoPixel.h>
#define PIN 7
Adafruit_NeoPixel strip = Adafruit_NeoPixel(60, PIN, NEO_GRB + NEO_KHZ800);
#include <Wire.h>
#include <DS3231.h>
DS3231 clock;
RTCDateTime dt;

FASTLED_USING_NAMESPACE

// FastLED "100-lines-of-code" demo reel, showing just a few
// of the kinds of animation patterns you can quickly and easily
// compose using FastLED.
//
// This example also shows one easy way to define multiple
// animations patterns and have them automatically rotate.
//
// -Mark Kriegsman, December 2014

#if defined(FASTLED_VERSION) && (FASTLED_VERSION < 3001000)
#warning "Requires FastLED 3.1 or later; check github for latest code."
#endif

#define DATA_PIN    7
//#define CLK_PIN   4
#define LED_TYPE    WS2811
#define COLOR_ORDER GRB
#define NUM_LEDS    156
CRGB leds[NUM_LEDS];

#define BRIGHTNESS          70
#define FRAMES_PER_SECOND  120
int leftWf = 4;
int ledPin1 = 5;
int ledPin2 = 9;
int ledPin3 = 6;
int ledPin4 = 10;
int ledPin5 = 11;
int ledPin6 = 12;
int ledPin7 = 8;
int santa2 = 3;
int santa1 = 2;
//-----------------------------------------------------

void setup() {
  delay(1000); // 1 second delay for recovery
  Serial.begin(9600);
  clock.begin();
  // tell FastLED about the LED strip configuration
  FastLED.addLeds<LED_TYPE,DATA_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  //FastLED.addLeds<LED_TYPE,DATA_PIN,CLK_PIN,COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);

  // set master brightness control
  FastLED.setBrightness(BRIGHTNESS);
  strip.begin();
  strip.setBrightness(10);
  strip.show(); // Initialize all pixels to 'off'
  pinMode(leftWf, OUTPUT);
  pinMode(ledPin1, OUTPUT);
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);
  pinMode(ledPin6, OUTPUT);
  pinMode(ledPin7, OUTPUT);
  pinMode(santa2, OUTPUT);
  pinMode(santa1, OUTPUT);
 
}


// List of patterns to cycle through.  Each is defined as a separate function below.
typedef void (*SimplePatternList[])();
SimplePatternList gPatterns = { rainbow, rainbowWithGlitter };

uint8_t gCurrentPatternNumber = 0; // Index number of which pattern is current
uint8_t gHue = 0; // rotating "base color" used by many of the patterns
 
void roofRainbow ()
{
  // 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
  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 rainbow()
{
  // FastLED's built-in rainbow generator
  fill_rainbow( leds, NUM_LEDS, gHue, 7);
}

void rainbowWithGlitter()
{
  // built-in FastLED rainbow, plus some random sparkly glitter
  rainbow();
  addGlitter(80);
}

void addGlitter( fract8 chanceOfGlitter)
{
  if( random8() < chanceOfGlitter) {
    leds[ random16(NUM_LEDS) ] += CRGB::White;
  }
}

void snowflakes() {

// Setup the pixel array
int pixel[60];
for(int p=0; p<60; p++){
  pixel[p] = random(0,255);
}

// Run some snowflake cycles
for (int j=0; j<200; j++) {

// Every five cycles, light a new pixel
if((j%500)==0){
  strip.setPixelColor(random(0,60), 255,255,255);
}

// Dim all pixels by 10
for(int p=0; p<60; p++){
  strip.setPixelColor(p, pixel[p],pixel[p],pixel[p] );
  pixel[p] =  pixel[p] - 10;
}
   strip.show();
   delay(100);
}
}
//------------------------------------------------------
void houseLights ()
{
// LED Fire Effect
analogWrite(ledPin1, random(60)+195);
analogWrite(ledPin3, random(60)+195);
analogWrite(ledPin5, random(60)+195);
analogWrite(ledPin6, random(60)+195);
analogWrite(leftWf, random(60)+195);
delay(random(50));
}
//-----------------------------------------------------
//-----------------------------------------------------

void santaClause ()
{
// LED Fire Effect
analogWrite(santa2, 255);
analogWrite(santa1, 255);
delay(random(50));
}
//-----------------------------------------------------
void porchLight () {
// LED Fire Effect
analogWrite(ledPin2, random(220)+135);


delay(random(50));
}
//-----------------------------------------------------
void roofOff () {
// clears all roof LEDs to off
FastLED.clear();
FastLED.show();
delay(random(50));
}
//-----------------------------------------------------
void loop()
{
  dt = clock.getDateTime();
  Serial.print('minute');
  Serial.print("made it here");
  // First hour turn on house, santa and porch lights only
if (dt.second > 17 && dt.second < 27) {
 
  houseLights () ;
  santaClause () ;
  porchLight () ;
}
// Second hour turns on snowflake and all other lights
else if (dt.second > 27 && dt.second < 37) {
  snowflakes();
  houseLights () ;
  santaClause () ;
  porchLight () ;
}
// Third and Forth hour turns on roofRainbow and all other lights
else if (dt.second > 37 && dt.second < 57) {
  roofRainbow ();
  houseLights () ;
  santaClause () ;
  porchLight () ;
}
  else{
  analogWrite(ledPin1, 0);
  analogWrite(ledPin3, 0);
  analogWrite(ledPin5, 0);
  analogWrite(ledPin6, 0);
  analogWrite(ledPin2, 0);
  analogWrite(ledPin7, 0);
  analogWrite(leftWf, 0);
  analogWrite(santa1, 0);
  roofOff();

}
}

Under your thread click the down pointing triangle and chose delete from the drop down menu. Or chose modify to put the code tags in and delete your other thread.

I see you are using both the FastLED library and the Adafruit Neopixel library at the same time! The only other time I saw someone do that the code was jamming up as well. I suppose it is because you are a beginner but using them together is not a wise thing to do and no one would even think about doing this unless very very drunk.

I can't even get you code to compile, can you?
I get the error message:-

RTCDateTime' does not name a type; did you mean 'DateTime'?

Thanks so much for you continued support!

I do like wine and coding..........yes, I am a nerd

Mine compiles just fine and downloads also.

I used 2 different only because after MANY different patters on the LED's I like...I needed both libraries....one for rainbow and one for snowflakes.

It is functioning with both in my last mailbox download but I tried to add one more "if" statement to kill the power to the LED strip (using .clear) to conserve power because my solar panels won't provide enough on the dark days of winter...

I can certainly try using only 1 and see if that helps...I think "instability" is exactly what I am experiencing.

Happy Holidays
Steve

but I tried to add one more "if" statement to kill the power to the LED strip

When code gets complex it is all too easy to mismatch the braces {} do you know this trick? Put the cursor on an opening brace and the matching closing brace will have be in a small box. Then you can see what is within the scope of the if.

Mine compiles just fine and downloads also.

Do you have the link and version number of the RTC DS3231 library you used? I am probably not using the same one.

Don't forget to use CTRL-T in the IDE. If you have mismatched braces, it will be obvious after CTRL-T.

Problem solved! Thanks for the help...I did eliminate the one library and kept only FastLED. Also, I discovered I had too many wire.h libraries which seemed to conflict...live and learn.

Thanks for the help and happy holidays!