I'm in need of a bit of assistance,

I’m in need of a bit of assistance, i’m messing around with a HEAVILY modified Demoreel100 based sketch that I’m working on integrating a button into, this does exactly what I want it to do for the most part, right now it changes patterns every 15 seconds like I want it to, it changes patterns with the press of the button, and it stores gCurrentPatternNumber to the eeprom when I hold the button for 1 second just like it should. I’m trying to get it to “ignore” the nextPattern(); loop every 15 seconds but only when there wasn’t a “longpress” event. I basically want it to cycle through my patterns normally every 15 seconds and also advance to the next pattern when I press the button, then “lock” the current pattern that it’s on when I press and hold the button for 1 second. It’s probably as simple as an “If/Else” statement but I’m having trouble figuring out where to put it and what it needs to do. Can anyone give me some insight? Any help is greatly appreciated.

void loop()
{
gPatternsgCurrentPatternNumber; // Call the current pattern function once, updating the ‘leds’ array
readbutton();
FastLED.show(); // send the ‘leds’ array out to the actual LED strip
// do some periodic updates
EVERY_N_MILLISECONDS( 15 ) { gHue++; } // slowly cycle the “base color” through the rainbow

EVERY_N_SECONDS( 15 ) { nextPattern();} // change patterns every N seconds

} //loop()

void nextPattern()
{
// add one to the current pattern number, and wrap around at the end
gCurrentPatternNumber = (gCurrentPatternNumber + 1) % ARRAY_SIZE( gPatterns);
Serial.println(gCurrentPatternNumber);

}//nextPattern()

void readbutton() { // Read the button and increase the mode.

myBtn.read();

if(myBtn.wasReleased()) {
if (longpress==1) {
EEPROM.write(eepaddress, gCurrentPatternNumber);
Serial.print("Writing: ");
} else {
gCurrentPatternNumber = gCurrentPatternNumber > maxMode-1 ? 0 : gCurrentPatternNumber+1; // Reset to 0 only during a mode change.
}
longpress = 0;
Serial.println(gCurrentPatternNumber);
}

if(myBtn.pressedFor(1000)) {
longpress = 1;
}

}//readbutton()

Wish i could help but my code is a bit more basic than this lol. It just reads the pattern number from EEPROM then when the button is pressed it stores that new value. But it doesnt cycle through patterns just does 1 at a time

Yeah I want it to change with the timer AND with a button press, and not change at all if I hold the button to lock it. :confused:

Shouldnt be too hard. But im not sure what to do lol

Something like:
If (the button was held, lock the current pattern into the eeprom)
Else (use the timer and button presses to change patterns)
I’m going to try some more later tonight.

Ight man. I gotta go sleep. Working night shift sucks lol

@Kyle_Halvorson My initial thought is one more variable to keep track of if it’s been locked or not, something like:
boolean locked = false;

Here’s some totally untested code scribblings. Added an “if” check a few places to check the status of locked. Also line 39 toggles the locked variable. You’ll probably need to adjust a few other things in the readbutton function, but hopefully this might give you a few ideas.

@marmil ok thank you! I’ll try it out when I get home and let you know what happens.

@marmil I still can’t get it to work, would there be a possibility to set the number of seconds as a variable and have it set at 0 when there was a longpress and set to a different value with a short press? EVERY_N_SECONDS( Seconds ) { nextPattern();
How would that be done?

@marmil Also, did you mean to do if(locked==false) on both of these? shouldn’t one be true and one false? i changed the first one to true, maybe that’s my problem…
if (locked == false) {
gPatternsgCurrentPatternNumber;
}

readbutton();
FastLED.show(); // send the ‘leds’ array out to the actual LED strip
// do some periodic updates
EVERY_N_MILLISECONDS( 15 ) { gHue++; } // slowly cycle the “base color” through the rainbow

if (locked == false) {
EVERY_N_SECONDS( 15 ) { nextPattern();} // change patterns every N seconds
}

Maybe an if statement that is checking for two things… such as
if (varA && varB)