#include <Adafruit_CircuitPlayground.h>
#include <FastLED.h>
#define STRIP1_DATA_PIN 9
#define NUM_MODES 1
#define COLOR_ORDER GRB
#define NUM_LEDS 80
#define CAP_THRESHOLD 50
#define FRAMES_PER_SECOND 35
CRGBPalette16 currentPalette;
TBlendType currentBlending;
CRGBPalette16 gPal;
CRGB leds[NUM_LEDS];
//BUTTON SETUP STUFF
byte prevKeyState = HIGH;
//FIRST ACTIVE MODE
int ledMode = 0;
//GET CAP TOUCH BUTTON STATE
boolean capButton(uint8_t pad) {
if (CircuitPlayground.readCap(pad) > CAP_THRESHOLD) {
return true;
} else {
return false;
}
}
void setup() {
// Initialize serial.
Serial.begin(9600);
// Initialize Circuit Playground library.
CircuitPlayground.begin();
FastLED.addLeds<WS2812B, STRIP1_DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection( TypicalLEDStrip );
currentBlending = LINEARBLEND;
}
////////////////////////////////////////////////////////////////////////////
void loop() {
switch (ledMode) {
case 0: fire(); break;
case 1: alloff(); break;
}
// CHECK IF BUTTON IS PRESSED
byte currKeyState = capButton(10);
Serial.println (capButton(10));
if ((prevKeyState == true) && (currKeyState == false)) {
keyRelease();
}
prevKeyState = currKeyState;
}
//BUTTON CONTROL
void keyRelease() {
Serial.println(“short”);
ledMode++;
if (ledMode > NUM_MODES){
ledMode=0; }
}
void fire()
{
currentPalette = HeatColors_p;
Fire2012WithPalette(); // run simulation frame, using palette colors
FastLED.show(); // display this frame
FastLED.delay(1000 / FRAMES_PER_SECOND);
}
#define COOLING 55 // Less cooling = taller flames. Default 55, suggested range 20-100
#define SPARKING 120 //Higher chance = more roaring fire. Default 120, suggested range 50-200
void Fire2012WithPalette()
{
random16_add_entropy( random());
static byte heat[NUM_LEDS];
for( int i = 0; i < NUM_LEDS; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / NUM_LEDS) + 2));
}
for( int k= NUM_LEDS - 3; k > 0; k–) {
heat[k] = (heat[k - 1] + heat[k - 2] + heat[k - 2] ) / 3;
}
if( random8() < SPARKING ) {
int y = random8(7);
heat[y] = qadd8( heat[y], random8(160,255) );
}
for( int j = 0; j < NUM_LEDS; j++) {
byte colorindex = scale8( heat[j], 240);
leds[j] = ColorFromPalette( currentPalette, colorindex);
}
}
void alloff() { // Fade all LEDs slowly to black
for (int i = 0; i < NUM_LEDS; i++){
leds[i].fadeToBlackBy( 64 );
}
FastLED.show();
delay(20);
}