You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

118 lines
2.6 KiB

#include <FastLED.h>
#include <Button.h>
// How many leds in your strip?
#define BRIGHTNESS 96
#define NUM_LEDS 12
#define TEMPO 100
#define DATA_PIN 0 // led pin
#define BTN_PIN 3 // button pin
CRGB leds[NUM_LEDS];
float tcount = 0.0; //-INC VAR FOR SIN LOOPS
int ibright = 0; //-BRIGHTNESS (0-255)
int tempo_anim = TEMPO;
uint8_t gHue = 0; // rotating "base color"
boolean run_mod = false; // run mode
Button button1(BTN_PIN, PULLUP, 3000);
void colorWipe_up(struct CRGB rgb, uint8_t wait)
{
for (int i = 0; i < NUM_LEDS; i++) {
leds[i] = rgb;
FastSPI_LED.show();
delay(wait);
}
}
void colorWipe_down(struct CRGB rgb, uint8_t wait)
{
for (int i = NUM_LEDS - 1; i >= 0; i--) {
leds[i] = rgb;
FastSPI_LED.show();
delay(wait);
}
}
void black_out()
{
// all leds off
memset(leds, 0, NUM_LEDS * 3); // all leds off
FastSPI_LED.show();
}
void dual_color(struct CRGB color1, struct CRGB color2, uint8_t wait)
{
for (int i = 0; i < NUM_LEDS; i++) {
memset(leds, 0, NUM_LEDS * 3); // all leds off
leds[i] = color1;
leds[NUM_LEDS - (i + 1)] = color2;
FastSPI_LED.show();
delay(wait);
}
}
void xmas(uint8_t wait){
for (int j = 0; j < 2; j++){
for (int i = 0; i< NUM_LEDS; i++){
leds[i] = ((i % 2) == j)? CRGB::Red: CRGB::Green;
FastSPI_LED.show();
}
delay(wait);
}
}
boolean check_button(){
if (button1.checkPress() == 1) {
run_mod = true; // Serial.println("SHORT PRESS!");
} else if (button1.checkPress() == -1) {
black_out();
run_mod = false;
// Serial.println("LONG PRESS!");
}
return run_mod;
}
void setup()
{
// put your setup code here, to run once:
FastLED.addLeds < WS2812B, DATA_PIN, GRB > (leds, NUM_LEDS);
FastLED.setBrightness(BRIGHTNESS);
black_out();
}
void loop()
{
if (run_mod){
// put your main code here, to run repeatedly:
for (int i = 0; i < 5; i++) {
colorWipe_up(CRGB::Red, tempo_anim);
delay(tempo_anim);
colorWipe_up(CRGB::Green, tempo_anim);
delay(tempo_anim);
if (!check_button()) break;
}
}
if (run_mod) {
for (int i = 0; i < 5; i++) {
dual_color(CRGB::Red, CRGB::Green, tempo_anim);
if (!check_button()) break;
}
}
if (run_mod){
for (int i = 0; i < 20; i++) {
xmas( tempo_anim);
if (!check_button()) break;
}
}
check_button();
black_out();
delay(tempo_anim);
}