I’m trying to get a button to turn my light strip on, and have it fade in and out endlessly, until I push another button to turn it off. I can get it to turn on and fade in and out once, but that’s it. I can also turn it off. I just can’t get it to loop endlessly. Any help would be appreciated. I’m new to this so I’m not the best with the code. I’m using windows, and here is my code.
#include <FastLED.h>
#define NUM_LEDS 32
#define ledPin 3
CRGB led[NUM_LEDS];
int d = 10;
int repeat = 0;
int buttonApin = 9;
int buttonBpin = 7;
byte leds = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonApin, INPUT_PULLUP);
pinMode(buttonBpin, INPUT_PULLUP);
FastLED.addLeds<NEOPIXEL, ledPin>(led, NUM_LEDS);
for (int r = 0; r < NUM_LEDS; r++) {
led[r] = CRGB(255, 0, 0);
}
FastLED.show();
for (int o = 0; o < NUM_LEDS; o++) {
led[o] = CRGB(0, 0, 0);
}
FastLED.show();
}
void setBlack(int val) {
for (int o = 0; o < NUM_LEDS; o++) {
led[o] = CRGB(0, 0, 0);
}
FastLED.show();
}
void setRed(int val) {
for (int r = 0; r < NUM_LEDS; r++) {
led[r] = CRGB(val, 0, 0);
}
FastLED.show();
}
void loop() {
{
if (digitalRead(buttonApin) == LOW)
{
digitalWrite(ledPin, HIGH);
red();
}
if (digitalRead(buttonBpin) == LOW)
{
digitalWrite(ledPin, LOW);
for (int o = 0; o < 256; o++) {
setBlack(o);
delay(5);
}
}
}
}
void red(){
if (repeat <=10){
fade();
}
else {
for (int o = 0; o < 256; o++) {
setBlack(o);
delay(5);
}
}
repeat = 0;
return repeat;
setup();
}
void fade() {
for (int r = 0; r < 256; r++) {
setRed(r);
delay(d);
}
for (int r = 255; r > 0; r–) {
setRed(r);
delay(d);
}
repeat = repeat + 1;
return repeat;
}