FastLED Memory Reset Question
Using an Arduino Uno and FastLED I wrote a Sketch that is supposedly speed up my process to find what type of 3 wire NeoPixel/WS28?? type of LED string.
Problem is, as I see it, when changing the (re-executing a different) FastLED command the one that use to work doesn’t. I figure some memory settings don’t get reset, because, if I reboot the Arduino, then things work again, until the wrong FastLED command is executed.
Please allow me to explain quickly; The intent is to execute different FastLED commands based on what digital pin in the Arduino is held down (low). This way, theoretically, all I have to do to figure out what type the NeoPicel string, is to work my way along the pins till the string works as desired. That pin would be associated with the FastLED definition.
My attached code will explain.
My question is about cleaning up FastLED after it has been executed once or more times in the same program. So far, all of the examples I have found on the Internet have FastLED executed in the void setup. Reading quickly through the FastLED documentation didn’t suggest any reset or clearing memory.
I don’t know enough about C++ to know if there is any sort of clear working memory or how to use it.
I’m looking for suggestions with examples.
/*
* To run, you will need a 10K Ohm resister where one side is grounded and the other will be placed in digital pins 2 through 11 as your testing advances.
*
* Read the code to know what type of LED strings you have when all of the LEDs are red in color.
*/
#include <FastLED.h>
#define NUM_LEDS 11
#define DATA_PIN 13 //<-- To LED Data
#define BRIGHTNESS 50
CRGB leds[NUM_LEDS];
int delayTime = 800;
int pin0 = 2;
int pin1 = 3;
int pin2 = 4;
int pin3 = 5;
int pin4 = 6;
int pin5 = 7;
int pin6 = 8;
int pin7 = 9;
int pin8 = 10;
int pin9 = 11;
void setup () {
pinMode (pin0, INPUT);
pinMode (pin1, INPUT);
pinMode (pin2, INPUT);
pinMode (pin3, INPUT);
pinMode (pin4, INPUT);
pinMode (pin5, INPUT);
pinMode (pin6, INPUT);
pinMode (pin7, INPUT);
pinMode (pin8, INPUT);
pinMode (pin9, INPUT);
//This turns on the pin /supplies it with 3.3 Volts
digitalWrite(pin0, HIGH);
digitalWrite(pin1, HIGH);
digitalWrite(pin2, HIGH);
digitalWrite(pin3, HIGH);
digitalWrite(pin4, HIGH);
digitalWrite(pin5, HIGH);
digitalWrite(pin6, HIGH);
digitalWrite(pin7, HIGH);
digitalWrite(pin8, HIGH);
digitalWrite(pin9, HIGH);
}
void loop () {
if (digitalRead(pin0) == LOW) {
FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS); // GRB ordering is assumed
Blink(delayTime, NUM_LEDS); }
if (digitalRead(pin1) == LOW) {
FastLED.addLeds<TM1809, DATA_PIN, GRB>(leds, NUM_LEDS);
Blink(delayTime, NUM_LEDS); }
if (digitalRead(pin2) == LOW) {
FastLED.addLeds<TM1809, DATA_PIN, RGB>(leds, NUM_LEDS);
Blink(delayTime, NUM_LEDS); }
if (digitalRead(pin3) == LOW) {
FastLED.addLeds<GW6205, DATA_PIN, GRB>(leds,NUM_LEDS);
Blink(delayTime, NUM_LEDS); }
if (digitalRead(pin4) == LOW) {
FastLED.addLeds<GW6205, DATA_PIN, RGB>(leds, NUM_LEDS);
Blink(delayTime, NUM_LEDS); }
if (digitalRead(pin5) == LOW) {
FastLED.addLeds<WS2801, DATA_PIN, RGB>(leds, NUM_LEDS);
Blink(delayTime, NUM_LEDS); }
if (digitalRead(pin6) == LOW) {
FastLED.addLeds<WS2801, DATA_PIN, RGB>(leds, NUM_LEDS);
Blink(delayTime, NUM_LEDS); }
/*
if (digitalRead(pin6) == LOW) {
FastLED.addLeds<SM16716, DATA_PIN, GRB>(leds, NUM_LEDS);
Blink(delayTime, NUM_LEDS); }
if (digitalRead(pin9) == LOW) {
FastLED.addLeds<WS2801, DATA_PIN, GRB>(leds, NUM_LEDS);
Blink(delayTime, NUM_LEDS);
FastLED.clearLedData<WS2801, DATA_PIN, GRB>(leds, NUM_LEDS);}
*/
delay(delayTime*4);
}
void Blink(int t, int n){
// Turn the LED on, then pause
for (int i = 0; i < n; ++i) {
leds[i] = CRGB::Red;
FastLED.setBrightness(BRIGHTNESS);
FastLED.show();}
delay(t);
// Now turn the LED off, then pause
for (int i = 0; i < n; ++i) {
leds[i] = CRGB::Black;
FastLED.show(); }
delay(t*2);
// LEDS.clear(true);
clearData(); // clears all previous FastLED data
}