#include "FastLED.h"
#include <LiquidCrystal.h>
#define PB_PIN 2
#define LB_PIN 3
#define SW_PIN 4
#define FR_PIN A0
#define LED_PIN 6
#define NUM_LEDS 16*16
byte baza = 1;
byte bright = 2000;
bool sbros=false;
volatile int mode=1;
LiquidCrystal lcd(12, 11, 10, 9, 8, 7);
CRGB leds[NUM_LEDS];
void setup() {
lcd.begin(16, 2);
FastLED.addLeds <WS2812, LED_PIN, GRB>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
FastLED.setBrightness(bright);
pinMode(PB_PIN, INPUT_PULLUP);
pinMode(LB_PIN, INPUT_PULLUP);
pinMode(SW_PIN, INPUT_PULLUP);
attachInterrupt(0,pravo,FALLING);
attachInterrupt(1,levo,FALLING);
}
void loop() {
int svet = analogRead(FR_PIN);
if(svet<511 && !digitalRead(SW_PIN)){
sbros=true;
black();
}
if(svet>511 && !digitalRead(SW_PIN)){
switch(mode){
case 1:
lcd.setCursor(0,0);
lcd.print(" 1: STARS ");
lcd.setCursor(0,1);
lcd.print("< 3 2 >");
stars();
break;
case 2:
lcd.setCursor(0,0);
lcd.print(" 2: FIRERUN ");
lcd.setCursor(0,1);
lcd.print("< 1 3 >");
firerun();
break;
case 3:
lcd.setCursor(0,0);
lcd.print(" 3: MAGIC ");
lcd.setCursor(0,1);
lcd.print("< 2 1 >");
magic();
break;
}
}
if(digitalRead(SW_PIN)){
switch(mode){
case 1:
lcd.setCursor(0,0);
lcd.print(" 1: STARS ");
lcd.setCursor(0,1);
lcd.print("< 3 2 >");
stars();
break;
case 2:
lcd.setCursor(0,0);
lcd.print(" 2: FIRERUN ");
lcd.setCursor(0,1);
lcd.print("< 1 3 >");
firerun();
break;
case 3:
lcd.setCursor(0,0);
lcd.print(" 3: MAGIC ");
lcd.setCursor(0,1);
lcd.print("< 2 1 >");
magic();
break;
}
}
}
void pravo() {
mode++;
if(mode>3){
mode=1;
}
lcd.clear();
sbros=true;
}
void levo() {
mode--;
if(mode<1){
mode=3;
}
lcd.clear();
sbros=true;
}
void stars() {
black();
fadeToBlackBy(leds, NUM_LEDS, 30);
int pos = random16(NUM_LEDS);
leds[pos] += CHSV(baza++ + random8(64), 200, 255);
FastLED.setBrightness(bright);
FastLED.show();
}
void firerun() {
black();
fadeToBlackBy(leds, NUM_LEDS, 5);
int pos = beatsin16(13, 0, NUM_LEDS - 1);
leds[pos] += CHSV(baza++, 255, 192);
FastLED.setBrightness(bright);
FastLED.show();
}
void magic() {
black();
fadeToBlackBy(leds, NUM_LEDS, 10);
for (int i = 0; i < 8; i++) {
leds[beatsin16(i + 7, 0, NUM_LEDS - 1)] |= CHSV(baza+=16, 200, 255);
}
FastLED.setBrightness(bright);
FastLED.show();
delay(50);
}
void black(){
if(sbros){
for(int b=0;b<NUM_LEDS;b++){
leds[b]=0x000000;
}
FastLED.setBrightness(bright);
FastLED.show();
sbros=false;
}
}