Skip to content

Instantly share code, notes, and snippets.

@marmilicious
Last active April 6, 2017 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save marmilicious/033dbe5d7bc2943af86fe22ca9df7cbd to your computer and use it in GitHub Desktop.
Save marmilicious/033dbe5d7bc2943af86fe22ca9df7cbd to your computer and use it in GitHub Desktop.
boolean locked = false;
void loop()
{
if (locked == false) {
gPatterns[gCurrentPatternNumber]();
}
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
}
} //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.pressedFor(1000)) {
longpress = 1;
locked = !locked; // toggle variable whenever button pressed for 1 second.
return;
}
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);
}
}//readbutton()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment