//#define FASTLED_RMT_BUILTIN_DRIVER 1
#include <FastLED.h>
#include "mapping.h"
#define NUM_LEDS 750
#define LED_PIN 13
#define NUM_PATH 100 // Total Number of LEDs
CRGB pattern[100]; // Used in Charles Goodwin effects
int path[125]; // Used in Charles Goodwin effects
int refLEDs[750]; // Used in Charles Goodwin effects
CRGB leds[NUM_LEDS];
//General app
uint8_t brightness_wifi = 255; // Wifi brightness value (0-255)
bool on_off_button_wifi = true; // Wifi on/off button
//Colors menu app
uint8_t hue_wifi = 0; // Wifi color value (0-255)
uint8_t saturation_wifi = 255; // Wifi sat value (0-255)
//Effects menu app
uint8_t effect_wifi = 1; // Wifi effect value
uint8_t speed_wifi = 30; // Wifi speed value (0-100)
uint8_t features_wifi = 100; // Wifi features value (0-100)
//Sounds page app
uint8_t effect_sound_wifi = 0; // Wifi sound value (0-255)
uint8_t sensitivity_sound_wifi = 125; // Wifi sensitivity value (0-255)
bool autoslider_wifi = false; // Wifi sensitivity slider
unsigned long CurrentTime = 0; // Used for millis effect delays
unsigned long LastTime = 0; // Used for millis effect delays
unsigned long wifitime = 0; // Used to track how long wifi has been inactive
double fps = 0; // FPS counter
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
FastLED.addLeds<WS2812, LED_PIN, GRB>(leds, NUM_LEDS); // Add our LED strip to the FastLED library
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
extern CRGB leds[];
void Twinkle(uint8_t type, bool autocolor){
static uint8_t starbrightness[750] = {0};
static uint8_t starpassed[750] = {0};
static int starhue[750] = {0};
static int randomstar[20] = {0};
static uint8_t hue1 = 0;
static uint8_t hue2 = 0;
static uint8_t hue3 = 0;
static uint8_t sat1 = 0;
static uint8_t sat2 = 0;
EVERY_N_MILLISECONDS(100){
hue3 = hue3 + 1;
}
switch(type){
case 1: //Color enabled
hue1 = hue_wifi;
hue2 = 0;
sat1 = saturation_wifi;
sat2 = 0;
if (autocolor == true) hue1 = hue3;
break;
case 2: //Color enabled
hue1 = hue_wifi;
hue2 = hue_wifi;
sat1 = saturation_wifi;
sat2 = saturation_wifi;
if (autocolor == true) hue1 = hue3;
if (autocolor == true) hue2 = hue3;
break;
case 3: //Color enabled
hue1 = hue_wifi;
hue2 = hue_wifi + 30;
sat1 = saturation_wifi;
sat2 = saturation_wifi;
if (autocolor == true) hue1 = hue3;
if (autocolor == true) hue2 = hue3 + 30;
break;
}
uint8_t speed = map(speed_wifi, 0,100,120,0);
uint8_t numberstar = map(features_wifi, 0,100,0,18);
int starmap[19] = {1,1,2,2,3,3,3,4,4,5,5, 6 ,8,10,12,14,16,18,20};
numberstar = starmap[numberstar];
if(CurrentTime - LastTime >= speed){
LastTime = CurrentTime;
for (int i = 0; i < numberstar; i++){
randomstar[i] = random(0,NUM_LEDS);
if (starbrightness[randomstar[i]] == 0) {
starbrightness[randomstar[i]] = 20;
}
}
for (int i = 0; i < NUM_LEDS; i++){
if ((starbrightness[i] >= 20) && (starpassed[i] == 0)){
starbrightness[i] = starbrightness[i] + 20;
}
if (starbrightness[i] == 240) starpassed[i] = 1;
if (starbrightness[i] == 0) starpassed[i] = 0;
if (starpassed[i] == 1){
starbrightness[i] = starbrightness[i] - 20;
}
}
for (int i = 0; i < NUM_LEDS; i=i+2){
leds[i] = CHSV(hue1,sat1,starbrightness[i]);
}
for (int i = 1; i < NUM_LEDS; i=i+2){
leds[i] = CHSV(hue2,sat2,starbrightness[i]);
}
FastLED.show(brightness_wifi);
}
}
void Comet(uint8_t type) {
//FastLED.clear();
static int path[10][25] = {0};
static uint8_t eInd[10] = {0,1,2,8,18,9,10,18,12,21};
static uint8_t pInd[10] = {9,1,17,12,19,0,0,19,16,18};
static int position[10] = {0,3,6,9,11,14,16,18,21,23};
int speed = map(speed_wifi, 0,100,25,0);
int numbercomet = 10;
uint8_t sat = 0;
int colorshift = map(features_wifi, 0,100,0,255);
if(millis() >= LastTime + speed){
for (int i = 0; i<numbercomet; i++){
if (position[i] == 25){
getPath(eInd[i], pInd[i], random8(2), path[i]);
position[i] = 0;
}
}
for (int i = 0; i<numbercomet; i++){
if (type == 1) leds[path[i][position[i]]] = CHSV(hue_wifi+(i*(colorshift/numbercomet)),saturation_wifi,255);
if (type == 2){
if ((i == 0) || (i == 2) || (i == 4) || (i == 6) || (i == 8)) sat = 0;
else sat = 255;
leds[path[i][position[i]]] = CHSV(hue_wifi+(i*(colorshift/numbercomet)),sat,255);
}
}
for (int i = 0; i<numbercomet; i++){
position[i] = position[i] + 1;
}
fadeToBlackBy(leds,NUM_LEDS,80);
delay(speed);
LastTime = millis();
FastLED.show(brightness_wifi);
}
}
void pride() {
static uint16_t sPseudotime = 0;
static uint16_t sLastMillis = 0;
static uint16_t sHue16 = 0;
uint8_t sat8 = beatsin88( 87, 220, 250);
uint8_t brightdepth = beatsin88( 341, 96, 224);
uint16_t brightnessthetainc16 = beatsin88( 203, (25 * 256), (40 * 256));
uint8_t msmultiplier = beatsin88(147, 23, 60);
uint16_t hue16 = sHue16;//gHue * 256;
uint16_t hueinc16 = beatsin88(113, 1, 3000);
uint16_t ms = millis();
uint16_t deltams = ms - sLastMillis ;
sLastMillis = ms;
sPseudotime += deltams * msmultiplier;
sHue16 += deltams * beatsin88( 400, 5,9);
uint16_t brightnesstheta16 = sPseudotime;
for( uint16_t i = 0 ; i < NUM_PATH; i++) {
hue16 += hueinc16;
uint8_t hue8 = hue16 / 256;
brightnesstheta16 += brightnessthetainc16;
uint16_t b16 = sin16( brightnesstheta16 ) + 32768;
uint16_t bri16 = (uint32_t)((uint32_t)b16 * (uint32_t)b16) / 65536;
uint8_t bri8 = (uint32_t)(((uint32_t)bri16) * brightdepth) / 65536;
bri8 += (255 - brightdepth);
CRGB newcolor = CHSV( hue8, sat8, bri8);
uint16_t pixelnumber = i;
pixelnumber = (NUM_PATH-1) - pixelnumber;
nblend(pattern[pixelnumber], newcolor, 64);
}
}
void drawPride(uint8_t face){
pride();
// run through all the edges of the face
for ( int i =0; i<5; i++){
uint8_t vec = faces[face].sides[i];
uint8_t edge = vec;
if (edge>=128) edge -= 128;
uint8_t clk = edges[edge].point1;
uint8_t antiClk = edges[edge].point2;
if (vec >=128) {
antiClk = edges[edge].point1;
clk = edges[edge].point2;
}
// First bear off clockwise
getLEDs(vec, 1, path);
getPath(edge,clk,false, path +25);
getPath(edge,clk,true , path +50);
getPath(edge,clk,false , path +75);
getPath(edge,clk,false, path +100);
for(int i=13; i<113; i++){
leds[path[i]] = pattern[i-13];
}
// reverse direction and
// go anticlockwise
if (vec >=128) vec -=128;
else vec += 128;
//reset starting edge
edge = vec;
if (edge>=128) edge -= 128;
getLEDs(vec, 1, path);
getPath(edge,antiClk,true , path +25);
getPath(edge,antiClk,false , path +50);
getPath(edge,antiClk,true , path +75);
getPath(edge,antiClk,true , path +100);
for(int i=12; i<112; i++){
if ( i<25 || (i>=50 && i<75) || i>=100){
leds[path[i]] = pattern[i-12];
}
}
}
FastLED.show(brightness_wifi);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
void loop() {
CurrentTime = millis(); // define current clock time
Comet(1);
//Twinkle(1,false);
//drawPride(0);
}
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////