FastLED function to fade/pulse LED brightness

OK, thank you very much, I’ve zipped and attached.

(Attachment SmartLED_v8.zip is missing)

Hi - zip file was rejected, so I’ll paste the code below. I greatly appreciate your help!

// Program for Smart LED tape. Button debounce (working) and responds to a contact closure on pin8
// At power on, LEDS all on, colour solid. 4 pins output different colours
// so one this one program can be used for any roundel.
// Upon contact closure (5V n/o) momentary event, the following happens to all 4 colour pins:
// LEDS all off / all on fast pulse (x2), with a LED chase effect to finish
// Lights all on when this finishes, so roundel colour remains visible.
//
// 20/08/2020 tested stable, with 110k-Ohm resistor between GND and pin8
// 24/08/2020 tested stable, with 4 extenstions of Cat5 (185M) between 12V PSU & 5V relay and Arduino & LED strip
// 25/08/2020 V3_2: test code removed, leaving only code in use
// 30/09/2020 V5: code replacement with ALL leds on and off now (instead of quick increment)
// Timings adjusted for best responsiveness of flashes
// 02/10/2020 V8: Light_Pulse slowly fades between 50% - 100% brightness in a loop, to add minor animation to the solid ON state
// Added an interval timer, so a number of light pulses happen after an adjustable length of time of solid LEDs on
//
// by S.Arbuckle

#include <FastLED.h>

#define NUM_LEDS 38 //number of LEDs in the roundel strip
#define NUM_STRIPS 3
#define DATA_PIN_R 3
#define DATA_PIN_G 5
#define DATA_PIN_B 6
#define DATA_PIN_P 9
#define NUM_COLORS 3
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB

//define input pins
const int PinIn = 8;
const long interval = 15000; //interval at which to run Light_Pulse
int i = 0;
int j = 0;
int brightness = 1;
int fadeAmount = 2;
int flashes = 1;
int buttonState1 = 0;
int lastButtonState = LOW; // the previous reading from the input pin

unsigned long lastDebounceTime = 0; //the last time the output pin was toggled
unsigned long debounceDelay = 200; //the debounce time; increase if the output flickers
unsigned long previousMillis = 0; //store the last time interval timer was updated

CRGB redLeds [NUM_LEDS];
CRGB greenLeds [NUM_LEDS];
CRGB blueLeds [NUM_LEDS];
CRGB purpleLeds[NUM_LEDS];

void setup() {
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN_R,COLOR_ORDER>(redLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_G,COLOR_ORDER>(greenLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_B,COLOR_ORDER>(blueLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_P,COLOR_ORDER>(purpleLeds, NUM_LEDS);

pinMode(PinIn,INPUT);
digitalWrite(PinIn,LOW); // set initial trigger state
}

void loop(){
// read the state of the switch into a local variable:
int reading = digitalRead(PinIn);
unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
Light_Pulse(); //activate Light_Pulse at interval time
}

Light_Max(); //switch all LEDs on

if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it’s been there for longer than the debounce
// delay, so take it as the actual current state:

if (reading != buttonState1) { // if the button state has changed:
buttonState1 = reading;

buttonState1 = digitalRead(PinIn); // only toggle if the new button state is HIGH
if (buttonState1 == HIGH) {
Flash_X();
}
}
}
// save the reading. Next time through the loop, it’ll be the lastButtonState:
lastButtonState = reading;
}

void Light_Max(){
fill_solid(redLeds, NUM_LEDS, CRGB::Red);
fill_solid(greenLeds, NUM_LEDS, CRGB::Green);
fill_solid(blueLeds, NUM_LEDS, CRGB::Blue);
fill_solid(purpleLeds, NUM_LEDS,CRGB::Purple);
FastLED.show();
}

void Light_Pulse(){
//fade count limits how many times Light_Pulse runs
for (int fade_count=0; fade_count <= 2; fade_count++){
for (int fade_loop = 0; fade_loop < 135 * 4; fade_loop++) // 135 * 2 gives it the opportunity to go through 0 to 135 twice
brightness = 135; //Set this so its starts at full brightness
fadeAmount = -1; //Start from light to dark
{
for(i=0; i< NUM_LEDS; i++){

redLeds[i] = CRGB::Red; //set colours in the array
greenLeds[i] = CRGB::Green;
blueLeds[i] = CRGB::Blue;
purpleLeds[i] = CRGB::Purple;

redLeds[i]. fadeLightBy(brightness); //apply the brightness
greenLeds[i]. fadeLightBy(brightness);
blueLeds[i]. fadeLightBy(brightness);
purpleLeds[i].fadeLightBy(brightness);
}
FastLED.show();

brightness = brightness + fadeAmount; //raise the brightness value

if (brightness <= 0){ //fade up
fadeAmount = -fadeAmount;
brightness = 0 + fadeAmount;
}
if (brightness >= 155){ //fade down (not to off)
fadeAmount = -fadeAmount;
brightness = 155 + fadeAmount; //0=full brightness, 255=minimum brightness
}
delay(10); //this setting is the speed of the brighness change
}
}
}

void Flash_X(){
for (j=0; j<=flashes; j++){

FastLED.clear(true); //all LED arrays cleared / off
delay(225); //delay time of transition for OFF to ON for flash sequence
fill_solid(redLeds, NUM_LEDS, CRGB::Red);
fill_solid(greenLeds, NUM_LEDS, CRGB::Green);
fill_solid(blueLeds, NUM_LEDS, CRGB::Blue);
fill_solid(purpleLeds, NUM_LEDS,CRGB::Purple);
FastLED.show(); //all LED arrays set to full brightness
delay(225); //delay time of transition for ON to OFF for flash sequence
}

for(i=0; i< NUM_LEDS; i++){
redLeds[i] = CRGB::Black;
greenLeds[i] = CRGB::Black;
blueLeds[i] = CRGB::Black;
purpleLeds[i] = CRGB::Black;
FastLED.show(); //all LED arrays set to increment off pixels
delay(8); //this setting is the speed of pixel movement
}
}

Try this :

/ Program for Smart LED tape. Button debounce (working) and responds to a contact closure on pin8

// At power on, LEDS all on, colour solid. 4 pins output different colours
// so one this one program can be used for any roundel.
// Upon contact closure (5V n/o) momentary event, the following happens to all 4 colour pins:
// LEDS all off / all on fast pulse (x2), with a LED chase effect to finish
// Lights all on when this finishes, so roundel colour remains visible.
//
// 20/08/2020 tested stable, with 110k-Ohm resistor between GND and pin8
// 24/08/2020 tested stable, with 4 extenstions of Cat5 (185M) between 12V PSU & 5V relay and Arduino & LED strip
// 25/08/2020 V3_2: test code removed, leaving only code in use
// 30/09/2020 V5: code replacement with ALL leds on and off now (instead of quick increment)
// Timings adjusted for best responsiveness of flashes
// 02/10/2020 V8: Light_Pulse slowly fades between 50% - 100% brightness in a loop, to add minor animation to the solid ON state
// Added an interval timer, so a number of light pulses happen after an adjustable length of time of solid LEDs on
//
// by S.Arbuckle

#include <FastLED.h>

#define NUM_LEDS 38 //number of LEDs in the roundel strip
#define NUM_STRIPS 3
#define DATA_PIN_R 3
#define DATA_PIN_G 5
#define DATA_PIN_B 6
#define DATA_PIN_P 9
#define NUM_COLORS 3
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB

//define input pins
const int PinIn = 8;
const long interval = 15000; //interval at which to run Light_Pulse
int i = 0;
int j = 0;
int brightness = 1;
int fadeAmount = 2;
int flashes = 1;
int buttonState1 = 0;
int lastButtonState = LOW; // the previous reading from the input pin

unsigned long lastDebounceTime = 0; //the last time the output pin was toggled
unsigned long debounceDelay = 200; //the debounce time; increase if the output flickers
unsigned long previousMillis = 0; //store the last time interval timer was updated

CRGB redLeds [NUM_LEDS];
CRGB greenLeds [NUM_LEDS];
CRGB blueLeds [NUM_LEDS];
CRGB purpleLeds[NUM_LEDS];

void setup()
{
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN_R,COLOR_ORDER>(redLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_G,COLOR_ORDER>(greenLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_B,COLOR_ORDER>(blueLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_P,COLOR_ORDER>(purpleLeds, NUM_LEDS);

pinMode(PinIn,INPUT);
digitalWrite(PinIn,LOW); // set initial trigger state

}

void loop()
{
// read the state of the switch into a local variable:
int reading = digitalRead(PinIn);
unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) 
{
	previousMillis = currentMillis;
	Light_Pulse(); //activate Light_Pulse at interval time
}

Light_Max(); //switch all LEDs on

if (reading != lastButtonState) 
{
	// reset the debouncing timer
	lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) 
{
	// whatever the reading is at, it’s been there for longer than the debounce
	// delay, so take it as the actual current state:
	if (reading != buttonState1) 
	{
		// if the button state has changed:
		buttonState1 = reading;
		buttonState1 = digitalRead(PinIn); // only toggle if the new button state is HIGH
		if (buttonState1 == HIGH) 
		{
			Flash_X();
		}
	}
}
// save the reading. Next time through the loop, it’ll be the lastButtonState:
lastButtonState = reading;

}

void Light_Max()
{
fill_solid(redLeds, NUM_LEDS, CRGB::Red);
fill_solid(greenLeds, NUM_LEDS, CRGB::Green);
fill_solid(blueLeds, NUM_LEDS, CRGB::Blue);
fill_solid(purpleLeds, NUM_LEDS,CRGB::Purple);
FastLED.show();
}

void Light_Pulse()
{
//fade count limits how many times Light_Pulse runs
for (int fade_count=0; fade_count <= 2; fade_count++)
{
brightness = 135; //Set this so its starts at full brightness
fadeAmount = -1; //Start from light to dark
for (int fade_loop = 0; fade_loop < 135 * 4; fade_loop++) // 135 * 2 gives it the opportunity to go through 0 to 135 twice
{
for(i=0; i< NUM_LEDS; i++)
{
redLeds[i] = CRGB::Red; //set colours in the array
greenLeds[i] = CRGB::Green;
blueLeds[i] = CRGB::Blue;
purpleLeds[i] = CRGB::Purple;

			redLeds[i]. fadeLightBy(brightness); //apply the brightness
			greenLeds[i]. fadeLightBy(brightness);
			blueLeds[i]. fadeLightBy(brightness);
			purpleLeds[i].fadeLightBy(brightness);
		}
		FastLED.show();

		brightness = brightness + fadeAmount; //raise the brightness value

		if (brightness <= 0)
		{ //fade up
			fadeAmount = -fadeAmount;
			brightness = 0 + fadeAmount;
		}
		if (brightness >= 155)
		{ //fade down (not to off)
			fadeAmount = -fadeAmount;
			brightness = 155 + fadeAmount; //0=full brightness, 255=minimum brightness
		}
		delay(10); //this setting is the speed of the brighness change
	}
}

}

void Flash_X()
{
for (j=0; j<=flashes; j++)
{
FastLED.clear(true); //all LED arrays cleared / off
delay(225); //delay time of transition for OFF to ON for flash sequence
fill_solid(redLeds, NUM_LEDS, CRGB::Red);
fill_solid(greenLeds, NUM_LEDS, CRGB::Green);
fill_solid(blueLeds, NUM_LEDS, CRGB::Blue);
fill_solid(purpleLeds, NUM_LEDS,CRGB::Purple);
FastLED.show(); //all LED arrays set to full brightness
delay(225); //delay time of transition for ON to OFF for flash sequence
}

for(i=0; i< NUM_LEDS; i++)
{
	redLeds[i] = CRGB::Black;
	greenLeds[i] = CRGB::Black;
	blueLeds[i] = CRGB::Black;
	purpleLeds[i] = CRGB::Black;
	FastLED.show(); //all LED arrays set to increment off pixels
	delay(8); //this setting is the speed of pixel movement
}

}

Hi - thanks for your help…it’s close but not quite there. On first run, LEDs come on for the preset time ok, pulsing of lights starts, but never stops.

It was just these two lines you moved above the loop, yes? I’ve looked carefully to see if there are any other changes, but have I missed any?

brightness = 135; //Set this so its starts at full brightness
fadeAmount = -1; //Start from light to dark

Thank you, Sean.

Hmm … I’ve looked through the code, and it appears to be ok.

Try increasing the const long interval = 15000 - it maybe taking so long to run the flash routine, it starts again immediately ?

Yes, increasing the interval does the trick! Brilliant, thanks! I’ve a side effect off the button read being disabled while the pulse loop runs, I don’t think there’s a workaround for that, is there?

Yes - you could put a test in the loop for the button, if it’s pressed, you call a “break;” - that will cancel the loop.

I would set up a bool at the start of the function, and “break” if true on all of the loops.

Hi again - could I bend your ear one more time? I’ve put a boolean in, and breaks in the loops, but it’s not functioning (button press trigger a lights flash during light fade effect).

// Program for Smart LED tape. Button debounce (working) and responds to a contact closure on pin8
// At power on, LEDS all on, colour solid. 4 pins output different colours
// so one this one program can be used for any roundel.
// Upon contact closure (5V n/o) momentary event, the following happens to all 4 colour pins:
// LEDS all off / all on fast pulse (x2), with a LED chase effect to finish
// Lights all on when this finishes, so roundel colour remains visible.
//
// 20/08/2020 tested stable, with 110k-Ohm resistor between GND and pin8
// 24/08/2020 tested stable, with 4 extenstions of Cat5 (185M) between 12V PSU & 5V relay and Arduino & LED strip
// 25/08/2020 V3_2: test code removed, leaving only code in use
// 30/09/2020 V5: code replacement with ALL leds on and off now (instead of quick increment)
// Timings adjusted for best responsiveness of flashes
// 02/10/2020 V8: Light_Pulse slowly fades between 50% - 100% brightness in a loop, to add minor animation to the solid ON state
// Added an interval timer, so a number of light pulses happen after an adjustable length of time of solid LEDs on
// 05/10/2020 V9: added a check for if a tag event happens while Light_Pulse is in progress, break out and execute Flash_X
//
// by S.Arbuckle

#include <FastLED.h>

#define NUM_LEDS 38 //number of LEDs in the roundel strip
#define NUM_STRIPS 3
#define DATA_PIN_R 3
#define DATA_PIN_G 5
#define DATA_PIN_B 6
#define DATA_PIN_P 9
#define NUM_COLORS 3
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB

//define input pins
const int PinIn = 8;
const long interval = 18000; //interval at which to run Light_Pulse
int i = 0;
int j = 0;
int brightness = 1;
int fadeAmount = 2;
int flashes = 1;
int buttonState1 = 0;
int lastButtonState = LOW; //the previous reading from the input pin
bool ButtonBreak = LOW; //variable to monitor for tag event, while Light_Pulse is in progress

unsigned long lastDebounceTime = 0; //the last time the output pin was toggled
unsigned long debounceDelay = 200; //the debounce time; increase if the output flickers
unsigned long previousMillis = 0; //store the last time interval timer was updated

CRGB redLeds [NUM_LEDS];
CRGB greenLeds [NUM_LEDS];
CRGB blueLeds [NUM_LEDS];
CRGB purpleLeds[NUM_LEDS];

void setup() {
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN_R,COLOR_ORDER>(redLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_G,COLOR_ORDER>(greenLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_B,COLOR_ORDER>(blueLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_P,COLOR_ORDER>(purpleLeds, NUM_LEDS);

pinMode(PinIn,INPUT);
digitalWrite(PinIn,LOW); // set initial trigger state
}

void loop(){
// read the state of the switch into a local variable:
int reading = digitalRead(PinIn);
unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) {
previousMillis = currentMillis;
Light_Pulse(); //activate Light_Pulse at interval time
}

Light_Max(); //switch all LEDs on

if (reading != lastButtonState) {
// reset the debouncing timer
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
// whatever the reading is at, it’s been there for longer than the debounce
// delay, so take it as the actual current state:

if (reading != buttonState1) { // if the button state has changed:
buttonState1 = reading;

buttonState1 = digitalRead(PinIn); // only toggle if the new button state is HIGH
if (buttonState1 == HIGH) {
ButtonBreak = HIGH; //to interrupt Light_Pulse if the button state changes
Flash_X();
}
}
}
// save the reading. Next time through the loop, it’ll be the lastButtonState:
lastButtonState = reading;
}

void Light_Max(){
fill_solid(redLeds, NUM_LEDS, CRGB::Red);
fill_solid(greenLeds, NUM_LEDS, CRGB::Green);
fill_solid(blueLeds, NUM_LEDS, CRGB::Blue);
fill_solid(purpleLeds, NUM_LEDS,CRGB::Purple);
FastLED.show();
}

void Light_Pulse(){
//fade count limits how many times Light_Pulse runs
for (int fade_count=0; fade_count <= 5; fade_count++)
{
// brightness = 1; //Set this so its starts at full brightness
if (ButtonBreak == HIGH){ //to interrupt Light_Pulse if the button state changes
Flash_X();
break;
}
fadeAmount = -1; //Start from light to dark

for (int fade_loop = 0; fade_loop < 150; fade_loop++){ // 135 * 2 gives it the opportunity to go through 0 to 135 twice

for(i=0; i< NUM_LEDS; i++){

if (ButtonBreak == HIGH){ //to interrupt Light_Pulse if the button state changes
Flash_X();
break;
}
redLeds[i] = CRGB::Red; //set colours in the array
greenLeds[i] = CRGB::Green;
blueLeds[i] = CRGB::Blue;
purpleLeds[i] = CRGB::Purple;

redLeds[i]. fadeLightBy(brightness); //apply the brightness
greenLeds[i]. fadeLightBy(brightness);
blueLeds[i]. fadeLightBy(brightness);
purpleLeds[i].fadeLightBy(brightness);
}
FastLED.show();

brightness = brightness + fadeAmount; //raise the brightness value

if (brightness <= 0){ //fade up
fadeAmount = -fadeAmount;
brightness = 0 + fadeAmount;
}
if (brightness >= 155){ //fade down (not to off)
fadeAmount = -fadeAmount;
brightness = 255 + fadeAmount; //0=full brightness, 255=minimum brightness
}
delay(10); //this setting is the speed of the brighness change
}
}
}

void Flash_X(){
for (j=0; j<=flashes; j++){

FastLED.clear(true); //all LED arrays cleared / off
delay(225); //delay time of transition for OFF to ON for flash sequence
fill_solid(redLeds, NUM_LEDS, CRGB::Red);
fill_solid(greenLeds, NUM_LEDS, CRGB::Green);
fill_solid(blueLeds, NUM_LEDS, CRGB::Blue);
fill_solid(purpleLeds, NUM_LEDS,CRGB::Purple);
FastLED.show(); //all LED arrays set to full brightness
delay(225); //delay time of transition for ON to OFF for flash sequence
}

for(i=0; i< NUM_LEDS; i++){
redLeds[i] = CRGB::Black;
greenLeds[i] = CRGB::Black;
blueLeds[i] = CRGB::Black;
purpleLeds[i] = CRGB::Black;
FastLED.show(); //all LED arrays set to increment off pixels
delay(8); //this setting is the speed of pixel movement
}
ButtonBreak = LOW;
}

I used the previous code I sent, because I had formatted it with the correct indentations etc - I haven’t looked through what you sent, because I’d have to format it again.

Basically, I created a function Button_Check - this returns true or false. This function is then called in your Light_Pulse function, and if true, will break out of the loops and call your Flash_X before it exits.

// Program for Smart LED tape. Button debounce (working) and responds to a contact closure on pin8
// At power on, LEDS all on, colour solid. 4 pins output different colours
// so one this one program can be used for any roundel.
// Upon contact closure (5V n/o) momentary event, the following happens to all 4 colour pins:
// LEDS all off / all on fast pulse (x2), with a LED chase effect to finish
// Lights all on when this finishes, so roundel colour remains visible.
//
// 20/08/2020 tested stable, with 110k-Ohm resistor between GND and pin8
// 24/08/2020 tested stable, with 4 extenstions of Cat5 (185M) between 12V PSU & 5V relay and Arduino & LED strip
// 25/08/2020 V3_2: test code removed, leaving only code in use
// 30/09/2020 V5: code replacement with ALL leds on and off now (instead of quick increment)
// Timings adjusted for best responsiveness of flashes
// 02/10/2020 V8: Light_Pulse slowly fades between 50% - 100% brightness in a loop, to add minor animation to the solid ON state
// Added an interval timer, so a number of light pulses happen after an adjustable length of time of solid LEDs on
//
// by S.Arbuckle

#include <FastLED.h>

#define NUM_LEDS 38 //number of LEDs in the roundel strip
#define NUM_STRIPS 3
#define DATA_PIN_R 3
#define DATA_PIN_G 5
#define DATA_PIN_B 6
#define DATA_PIN_P 9
#define NUM_COLORS 3
#define LED_TYPE WS2812B
#define COLOR_ORDER RGB

//define input pins
const int PinIn = 8;
const long interval = 15000; //interval at which to run Light_Pulse
int i = 0;
int j = 0;
int brightness = 1;
int fadeAmount = 2;
int flashes = 1;
int buttonState1 = 0;
int lastButtonState = LOW; // the previous reading from the input pin

unsigned long lastDebounceTime = 0; //the last time the output pin was toggled
unsigned long debounceDelay = 200; //the debounce time; increase if the output flickers
unsigned long previousMillis = 0; //store the last time interval timer was updated

CRGB redLeds [NUM_LEDS];
CRGB greenLeds [NUM_LEDS];
CRGB blueLeds [NUM_LEDS];
CRGB purpleLeds[NUM_LEDS];

void setup()
{
// tell FastLED about the LED strip configuration
FastLED.addLeds<LED_TYPE,DATA_PIN_R,COLOR_ORDER>(redLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_G,COLOR_ORDER>(greenLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_B,COLOR_ORDER>(blueLeds, NUM_LEDS);
FastLED.addLeds<LED_TYPE,DATA_PIN_P,COLOR_ORDER>(purpleLeds, NUM_LEDS);

pinMode(PinIn,INPUT);
digitalWrite(PinIn,LOW); // set initial trigger state

}

void loop()
{
// read the state of the switch into a local variable:
int reading = digitalRead(PinIn);
unsigned long currentMillis = millis();

if (currentMillis - previousMillis >= interval) 
{
	previousMillis = currentMillis;
	Light_Pulse(); //activate Light_Pulse at interval time
}

Light_Max(); //switch all LEDs on

if (Check_Button == true)
{
	Flash_X();
}

}

bool Check_Button()
{
if (reading != lastButtonState)
{
// reset the debouncing timer
lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) 
{
	// whatever the reading is at, it’s been there for longer than the debounce
	// delay, so take it as the actual current state:
	if (reading != buttonState1) 
	{
		// if the button state has changed:
		buttonState1 = reading;
		buttonState1 = digitalRead(PinIn); // only toggle if the new button state is HIGH
		if (buttonState1 == HIGH) 
		{
			return true;
		}
	}
}
// save the reading. Next time through the loop, it’ll be the lastButtonState:
lastButtonState = reading;
return false;

}

void Light_Max()
{
fill_solid(redLeds, NUM_LEDS, CRGB::Red);
fill_solid(greenLeds, NUM_LEDS, CRGB::Green);
fill_solid(blueLeds, NUM_LEDS, CRGB::Blue);
fill_solid(purpleLeds, NUM_LEDS,CRGB::Purple);
FastLED.show();
}

void Light_Pulse()
{
bool ButtonPressed = false;
//fade count limits how many times Light_Pulse runs
for (int fade_count=0; fade_count <= 2; fade_count++)
{
brightness = 135; //Set this so its starts at full brightness
fadeAmount = -1; //Start from light to dark
for (int fade_loop = 0; fade_loop < 135 * 4; fade_loop++) // 135 * 2 gives it the opportunity to go through 0 to 135 twice
{
ButtonPressed = Check_Button();
if (ButtonPressed)
{
break; //If the button is pressed, we will exit out of this fade_loop
}

		for(i=0; i< NUM_LEDS; i++)
		{
			redLeds[i] = CRGB::Red; //set colours in the array
			greenLeds[i] = CRGB::Green;
			blueLeds[i] = CRGB::Blue;
			purpleLeds[i] = CRGB::Purple;

			redLeds[i]. fadeLightBy(brightness); //apply the brightness
			greenLeds[i]. fadeLightBy(brightness);
			blueLeds[i]. fadeLightBy(brightness);
			purpleLeds[i].fadeLightBy(brightness);
		}
		FastLED.show();

		brightness = brightness + fadeAmount; //raise the brightness value

		if (brightness <= 0)
		{ //fade up
			fadeAmount = -fadeAmount;
			brightness = 0 + fadeAmount;
		}
		if (brightness >= 155)
		{ //fade down (not to off)
			fadeAmount = -fadeAmount;
			brightness = 155 + fadeAmount; //0=full brightness, 255=minimum brightness
		}
		delay(10); //this setting is the speed of the brighness change
	}
	if (ButtonPressed)
	{
		break;	//If the button was pressed, we exit out of the fade_count loop too
	}
}
if (ButtonPressed)
{
	Flash_X();
}

}

void Flash_X()
{
for (j=0; j<=flashes; j++)
{
FastLED.clear(true); //all LED arrays cleared / off
delay(225); //delay time of transition for OFF to ON for flash sequence
fill_solid(redLeds, NUM_LEDS, CRGB::Red);
fill_solid(greenLeds, NUM_LEDS, CRGB::Green);
fill_solid(blueLeds, NUM_LEDS, CRGB::Blue);
fill_solid(purpleLeds, NUM_LEDS,CRGB::Purple);
FastLED.show(); //all LED arrays set to full brightness
delay(225); //delay time of transition for ON to OFF for flash sequence
}

for(i=0; i< NUM_LEDS; i++)
{
	redLeds[i] = CRGB::Black;
	greenLeds[i] = CRGB::Black;
	blueLeds[i] = CRGB::Black;
	purpleLeds[i] = CRGB::Black;
	FastLED.show(); //all LED arrays set to increment off pixels
	delay(8); //this setting is the speed of pixel movement
}

}

Should work, but I don’t have the hardware you have - I’m programming in Notepad++

If you paste your code this way it will format right:

```C++
<your code goes here>
```

You can edit old posts to fix that up, too. :slight_smile:

2 Likes

@Sean_Arby and @Jammy, I will offer the suggestion to use pastebin.com (login not required) or gist.github.com when sharing larger amounts of code like this. Put the code there and share a link to the code in your forum posts. The code will always be formatted nicely no matter what device it’s viewed on and it will also have line numbers which can sometime greatly aid discussion.

1 Like

Hi … thank you again. I’ve compared the files with Notepadd++ to ensure every character is right, but it’s not compiling, and I’ve been tracing it through but I think I’m making it worse…

Is the highlighted bit below right, as the main code loop will be closed? I’ve then removed the closed parenthesis, but get a compile error with Check_Button within the Light_Pulse module…

Thanks ! It was all getting a bit messy !

Thanks ! I wasn’t aware of that.

The problem with pastebin is it don’t help people search for problems and find a solution. If you use pastebin, please set it to never expire.

1 Like

I may have missed the () off the check button function.

Hi Jammy - thanks, the PasteBin is so much more readable! Compile error on line 106 ‘reading’ was not declared in this scope…

It’s been declared within your loop. Like I said before, I can’t test compile it because I don’t have your hardware.

Perhaps you need some C++ help ?

1 Like

I note that this topic was not originally created in the FastLED Archive category because it can’t be. I moved it here because there was content and conversation happening, but the FastLED community has asked that new FastLED questions go to their subreddit.

Wearing my site moderator hat, I’m going to close this topic and ask the OP to follow the request of the FastLED community.

1 Like