#include <FastLED.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,20,4); // set the LCD address to 0x27 for a 16 chars and 2 line display
#define LED_PIN 3
#define COLOR_ORDER GRB
#define CHIPSET WS2812
#define NUM_LEDS 70
#define BRIGHTNESS 250
#define FRAMES_PER_SECOND 600
#define COOLING 55
#define SPARKING 120
bool gReverseDirection = false;
CRGB leds[NUM_LEDS];
const int button1 = 13;
const int button2 = 12;
const int button3 = 11;
const int button4 = 10;
void setup() {
delay(3000); // sanity delay
FastLED.addLeds<CHIPSET, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
FastLED.setBrightness( BRIGHTNESS );
pinMode(button1, INPUT_PULLUP);
pinMode(button2, INPUT_PULLUP);
pinMode(button3, INPUT_PULLUP);
pinMode(button4, INPUT_PULLUP);
lcd.init(); // initialize the lcd
// Print a message to the LCD.
lcd.backlight();
}
void loop() {
int but1 = digitalRead(button1);
int but2 = digitalRead(button2);
int but3 = digitalRead(button3);
int but4 = digitalRead(button4);
if (but1==0)
{
Lcd("Position 1","Lights off");
for (int x=0;x<479;x++)
{
leds[x] = CRGB(0, 0, 0);
FastLED.show();
}
}
else if (but2==0)
{
Lcd("Position 2","Lights White");
for (int x=0;x<479;x++)
{
leds[x] =CRGB::White;
FastLED.show();
}
}
else if (but3==0)
{
Lcd("Position 3","Lights Orange");
for (int x=0;x<479;x++)
{
leds[x] = CRGB(255, 128, 0);
FastLED.show();
}
}
else if (but4==0)
{
Lcd("Position 4","Lights Flame");
Fire(); // run simulation frame
FastLED.show(); // display this frame
FastLED.delay(1000 / FRAMES_PER_SECOND);
}
}
void Lcd(String a,String b)
{
lcd.setCursor(0, 0);
lcd.print(a);
lcd.setCursor(0, 1);
lcd.print(b);
}
void Fire()
{
// Array of temperature readings at each simulation cell
static uint8_t heat[NUM_LEDS];
// Step 1. Cool down every cell a little
for( int i = 0; i < NUM_LEDS; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= NUM_LEDS - 1; k >= 2; k--) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}
// Step 3. Randomly ignite new 'sparks' of heat near the bottom
if( random8() < SPARKING ) {
int y = random8(7);
heat[y] = qadd8( heat[y], random8(160,255) );
}
// Step 4. Map from heat cells to LED colors
for( int j = 0; j < NUM_LEDS; j++) {
CRGB color = HeatColor( heat[j]);
int pixelnumber;
if( gReverseDirection ) {
pixelnumber = (NUM_LEDS-1) - j;
} else {
pixelnumber = j;
}
leds[pixelnumber] = color;
}
}