Hey. It's been a while. I am close to finishing this code for a model kit for a friend, and I can't seem to get one of the case functions to work. Code follows. On power up, the FastLED strip is dark. With
button push 1, the string lights up blue in a sequential manner.
Button push 2 should send the strip into a build in intensity and a white flash, returning to the previous blue.
Push 3 fades to black, and
push 4 resets the Arduino to be able to go again.
The problem is that the case 2 FN_WARP does not do anything. The serial print registers the click, but no action is seen.
What am I missing?
Sketch:
/* Enterprise E warp nacelle functions
* 0-start black on power-up
* 1-fill in sequence blue
* 2- warp flash - will not work**.
* 3-fadeout
* 4- reset
* **-code by itself does: fade up blue to white @100,flash white @ 250,return blue
* this warp effect is the one I need help with- what am I missing??
*
*/
void(* resetFunc) (void) = 0;
#include <OneButton.h>
#include <FastLED.h>
#define NUM_LEDS 20
#define LED_PIN 2
#define BTN_PIN 14
// Push button connected between pin 7 and GND (no resistor required)
OneButton btn = OneButton(BTN_PIN, true, true);
CRGB leds[NUM_LEDS];
CRGB Warp[NUM_LEDS];
int hue = 160;
int saturation = 255;
int saturation2 = 0;
int brightness = 100;
int brightness2 = 200;
uint8_t patternCounter = 0;
//tell function to run once
int N = 1;
int runXTimes = 0;
void setup() {
FastLED.addLeds<WS2812B, LED_PIN, GRB>(leds, NUM_LEDS);
// FastLED.setBrightness(50);
Serial.begin(9600);
btn.attachClick(nextPattern);
}
void loop() {
switch (patternCounter) {
case 0:
fadeToBlackBy(leds, NUM_LEDS, 8);
Serial.println("begin");
break;
case 1:
if (runXTimes < N)
{
lightup();
runXTimes++;
}
Serial.println("lightup");
break;
case 2:
FN_WARP();
Serial.println("warp");
break;
case 3:
fadeToBlackBy(leds, NUM_LEDS, 8);
Serial.println("blackout");
break;
case 4:
resetFunc();
break;
}
FastLED.show();
btn.tick();
}
void nextPattern() {
patternCounter = (patternCounter + 1) % 5; // Change the number after the % to the number of patterns you have
}
//------- Put your patterns below -------//
void lightup() {
FastLED.clear();
for (int i = 0; i < NUM_LEDS; i++) {
leds[i].setRGB(0, 0, 255);
FastLED.show();
delay(80);
}
}
void FN_WARP() {
if (runXTimes < N)
{
FastLED.clear();
delay(1000);
fill_solid (Warp, 20, CHSV (hue, saturation, brightness));
FastLED.show();
for (int i = 0; i < 40; i++) {
saturation = saturation - 5;
brightness = brightness + 4;
fill_solid (Warp, 20, CHSV (hue, saturation, brightness));
FastLED.show();
FastLED.delay(20);
}
fill_solid (Warp, 20, CHSV (hue, saturation2, brightness2));
FastLED.show();
delay(250);
brightness = 100;
saturation = 255;
fill_solid (Warp, 20, CHSV (hue, saturation, brightness));
FastLED.show();
}
runXTimes++;
}