#include "Arduino.h"
#include <FastLED.h>
#define LED_PIN 1 //LED Strip Signal Connection
#define buttonPin 0 //Push Button Pin
#define NUM_LEDS 16 //Total no of LEDs in the LED strip.
CRGB leds[NUM_LEDS];
int LED_POWER_7 = 255;
int LED_POWER_6 = 200;
int LED_POWER_5 = 150;
int LED_POWER_4 = 100;
int LED_POWER_3 = 50;
int LED_POWER_2 = 20;
int LED_POWER_1 = 5;
int LED_POWER_0 = 0;
int SPEED1 = 75;
int SPEED2 = 30;
int SPEED3 = 400;
int SPEED4 = 60;
int SPEED5 = 300;
int numb=1;
int pres=0;
void setup()
{
FastLED.addLeds<WS2811, LED_PIN, RGB>(leds, NUM_LEDS);
FastLED.clear();
pinMode(buttonPin, INPUT_PULLUP);
}
void loop()
{
ButtonScan();
switch (numb) {
case 1:
Pattern1();
break;
case 2:
Pattern2();
break;
case 3:
Pattern3();
break;
case 4:
Pattern4();
break;
case 5:
Pattern5();
break;
case 6:
Pattern6();
break;
case 7:
Pattern7();
break;
case 8:
Pattern8();
break;
default:
Pattern1();
break;
}
}
void Pattern1()
{
fadeToBlackBy(leds, NUM_LEDS, 16);
int pos = beatsin16(25, 0, NUM_LEDS-1 );
leds[pos] += CRGB(255, 0, 0);
FastLED.show();
FastLED.delay(5);
}
void Pattern2()
{
fadeToBlackBy(leds, NUM_LEDS, 16);
int pos = beatsin16(25, 0, NUM_LEDS-1 );
leds[pos] += CRGB(0, 255, 0);
FastLED.show();
FastLED.delay(5);
}
void Pattern3()
{
fadeToBlackBy(leds, NUM_LEDS, 16);
int pos = beatsin16(25, 0, NUM_LEDS-1 );
leds[pos] += CRGB(0, 0, 255);
FastLED.show();
FastLED.delay(5);
}
void Pattern4()
{
fadeToBlackBy(leds, NUM_LEDS, 16);
int pos = beatsin16(25, 0, NUM_LEDS-1);
leds[pos] += CRGB(255, 255, 255);
FastLED.show();
FastLED.delay(5);
}
void Pattern5()
{
for (int i = 0; i < 3; i++)
{
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB(255, 0, 0);
}
FastLED.show(); ButtonScan();
delay (SPEED4);
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB(0, 0, 0);
}
FastLED.show(); ButtonScan();
delay (SPEED4);
}
delay (SPEED5);
}
void Pattern6()
{
for (int i = 0; i < 3; i++)
{
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB(0, 255, 0);
}
FastLED.show(); ButtonScan();
delay (SPEED4);
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB(0, 0, 0);
}
FastLED.show(); ButtonScan();
delay (SPEED4);
}
delay (SPEED5);
}
void Pattern7()
{
for (int i = 0; i < 3; i++)
{
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB(0, 0, 255);
}
FastLED.show(); ButtonScan();
delay (SPEED4);
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB(0, 0, 0);
}
FastLED.show(); ButtonScan();
delay (SPEED4);
}
delay (SPEED5);
}
void Pattern8()
{
for (int i = 0; i < 3; i++)
{
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB(255, 255, 255);
}
FastLED.show(); ButtonScan();
delay (SPEED4);
for (int i = 0; i < NUM_LEDS; i++)
{
leds[i] = CRGB(0, 0, 0);
}
FastLED.show(); ButtonScan();
delay (SPEED4);
}
delay (SPEED5);
}
void ButtonScan()
{
if(digitalRead(buttonPin)==0)
{
if(pres==0)
{
numb++;
pres=1;
}
}
else
{
pres=0;
}
if(numb == 9)
{
numb = 1;
}
}