Alrighty, you may like this one ... I've attached a video of the effect (at 5 seconds, I press the button briefly).
As usual, you'll need to:
- set the number of LEDs (NUM_LEDS 60),
- pin for the LEDs (PIN 5),
- pin for the button (BUTTON 2), and
- the number of swipes (blinkcount = 5).
You also may want to experiment with the values I have used in the "delay()" instructions as well (slower/faster/etc).
CAUTION:
For the switch you'll need a slightly different electrical approach - see attached image button.png for the schematics (source).
Just follow the original schematics, however you need to remove the switch (the yellow wires) and add this instead:
GND -> 10K Ohm resistor -> pin 2.
Pin 2 -> one side of the switch.
+5V (Arduino) -> other side of the switch.
The color code of the resistors are (see also my resistor calculator):
470 Ohms = yellow, violet, brown,
10 Kilo Ohms = brown, black, orange.
I have also attached the source as a .ino sketch, and I'm assuming you're using the FastLED library (recommended).
You may also notice that I simplified the code, by removing anything NeoPixel related.
What it does: when the button is being pressed, it will do the effect 5 times (= blinkcount).
#include "FastLED.h"
#include <EEPROM.h>
#define NUM_LEDS 60
#define blinkcount 5
CRGB leds[NUM_LEDS];
#define PIN 6
#define BUTTON 2
byte selectedEffect=0;
int buttonState = 0;
void setup()
{
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
pinMode(BUTTON, INPUT);
}
void loop() {
buttonState = digitalRead(BUTTON);
if (buttonState == HIGH) {
for(int blink=0; blink<blinkcount; blink++) {
for(int i=0; i<NUM_LEDS; i++) {
leds.setRGB(255,50,0);
FastLED.show();
delay(10);
}
delay(200);
// Cleanup swipe after swipe
//setAll(0,0,0);
for(int i=0; i<NUM_LEDS; i++) {
leds.setRGB(0,0,0);
FastLED.show();
delay(10);
}
delay(200);
}
setAll(0,0,0);
}
else {
setAll(0,0,0);
}
}
// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
leds.setRGB(red, green, blue);
}
FastLED.show();
}
In this code it does a cleanup swipe after each swipe - which is something you may want or not.
If you do not want this, and just want the leds to go dark right away, then change the code to this (compare the bold section in the code to see what and where).
#include "FastLED.h"
#include <EEPROM.h>
#define NUM_LEDS 60
#define blinkcount 5
CRGB leds[NUM_LEDS];
#define PIN 6
#define BUTTON 2
byte selectedEffect=0;
int buttonState = 0;
void setup()
{
FastLED.addLeds<WS2811, PIN, GRB>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
pinMode(BUTTON, INPUT);
}
void loop() {
buttonState = digitalRead(BUTTON);
if (buttonState == HIGH) {
for(int blink=0; blink<blinkcount; blink++) {
for(int i=0; i<NUM_LEDS; i++) {
leds.setRGB(255,50,0);
FastLED.show();
delay(10);
}
delay(200);
// Instant black after swipe
setAll(0,0,0);
//for(int i=0; i<NUM_LEDS; i++) {
// leds.setRGB(0,0,0);
// FastLED.show();
// delay(10);
//}
delay(200);
}
setAll(0,0,0);
}
else {
setAll(0,0,0);
}
}
// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
leds.setRGB(red, green, blue);
}
FastLED.show();
}
Hope this is what you're looking for.