Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save perigalacticon/ccd37d07b1354947127ac00f4dfdce11 to your computer and use it in GitHub Desktop.
Save perigalacticon/ccd37d07b1354947127ac00f4dfdce11 to your computer and use it in GitHub Desktop.
inoise8_pal_demo_fastLed_sPillar_post
/*
Name: inoise8_pal_demo_fastLed_sPillar_post.ino
Created: 11/7/2019 2:46:46 PM
Author: APOGALACTICON2\perigalacticon
*/
// inoise8_pal_demo_fastLed_sPillar.ino
// https://pastebin.com/r70Qk6Bn
/* Title: inoise8_pal_demo.ino
By: Andrew Tuline
Date: August, 2016
This short sketch demonstrates some of the functions of FastLED, including:
Perlin noise
Palettes
Palette blending
Alternatives to blocking delays
Beats (and not the Dr. Dre kind, but rather the sinewave kind)
Refer to the FastLED noise.h and lib8tion.h routines for more information on these functions.
Recommendations for high performance routines:
Don't use blocking delays, especially if you plan to use buttons for input.
Keep loops to a minimum, and don't use nested loops.
Don't use floating point math. It's slow. Use 8 bit where possible.
Let high school and not elementary school math do the work for you, i.e. don't just count pixels; use sine waves or other math functions instead.
FastLED math functions are faster than built in math functions.
*/
//#define FASTLED_ALLOW_INTERRUPTS 0 // must be before including FastLED
//#define FASTLED_INTERRUPT_RETRY_COUNT 0 // must be before including FastLED
#include "FastLED.h"
#include <ESP8266WiFi.h>
#include <ESP8266mDNS.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
#include <ESP8266HTTPUpdateServer.h>
#include <NeoPixelBus.h>
#if FASTLED_VERSION < 3001000
#error "Requires FastLED 3.1 or later; check github for latest code."
#endif
#define LED_PIN 2
#define BRIGHTNESS 255
#define LED_TYPE WS2812B // Only use the LED_PIN for WS2812's
#define COLOR_ORDER GRB
#define NUM_LEDS 130
struct CRGB leds[NUM_LEDS];
const char* host = "";
const char* ssid = "";
const char* password = "";
//
ESP8266WebServer httpServer(80);
ESP8266HTTPUpdateServer httpUpdater;
static uint16_t dist; // A random number for our noise generator.
uint16_t scale = 20; // 20 80 Wouldn't recommend changing this on the fly, or the animation will be really blocky.
uint8_t maxChanges = 48; // Value for blending between palettes.
// Summer fades to Autumn Color Palette:
// SFTA
// http://www.color-hex.com/color-palette/10894
// CRGB SFTA[5];
CRGB SFTA0 = CRGB(88, 140, 115);
CRGB SFTA1 = CRGB(242, 174, 148);
CRGB SFTA2 = CRGB(242, 174, 114);
CRGB SFTA3 = CRGB(217, 100, 89);
CRGB SFTA4 = CRGB(140, 70, 70);
// CRGB SFTA0 = CRGB(0,255,0);
// CRGB SFTA1 = CRGB(0,255,0);
// CRGB SFTA2 = CRGB(0,255,0);
// CRGB SFTA3 = CRGB(0,255,0);
// CRGB SFTA4 = CRGB(0,255,0);
// extern CRGBPalette16 summerFadesToAutumnPalette;
// extern const TProgmemPalette16 summerFadesToAutumnPalette_p FL_PROGMEM;
CRGBPalette16 SFTA_p =
{
SFTA0, SFTA1, SFTA2, SFTA3,
SFTA4, SFTA0, SFTA1, SFTA2,
SFTA3, SFTA4, SFTA0, SFTA1,
SFTA2, SFTA3, SFTA4, SFTA0
};
// const TProgmemPalette16 SFTA_p FL_PROGMEM =
// {
// SFTA[0],
// SFTA[1],
// SFTA[2],
// SFTA[3],
// SFTA[4],
//
// SFTA[0],
// SFTA[1],
// SFTA[2],
// SFTA[3],
// SFTA[4],
//
// SFTA[0],
// SFTA[1],
// SFTA[2],
// SFTA[3],
// SFTA[4],
//
// SFTA[0]
// };
// Autumn Color Palette:
// http://www.color-hex.com/color-palette/1278
// extern CRGBPalette16 autumnColorPalette;
// extern const TProgmemPalette16 autumnColorPalette_p FL_PROGMEM;
// const CRGB AC[5];
CRGB AC0 = CRGB(255, 210, 0);
CRGB AC1 = CRGB(156, 87, 8);
CRGB AC2 = CRGB(244, 123, 32);
CRGB AC3 = CRGB(247, 151, 98);
CRGB AC4 = CRGB(240, 81, 51);
CRGBPalette16 AC_p =
{
AC0, AC1, AC2, AC3,
AC4, AC0, AC1, AC2,
AC3, AC4, AC0, AC1,
AC2, AC3, AC4, AC0
};
// const TProgmemPalette16 AC_p FL_PROGMEM =
// {
// AC[0],
// AC[1],
// AC[2],
// AC[3],
// AC[4],
//
// AC[0],
// AC[1],
// AC[2],
// AC[3],
// AC[4],
//
// AC[0],
// AC[1],
// AC[2],
// AC[3],
// AC[4],
//
// AC[0]
// };
// Colors of Autumn Color Palette
// http://www.color-hex.com/color-palette/10153
CRGB COA0 = CRGB(251, 54, 54);
CRGB COA1 = CRGB(234, 199, 56);
CRGB COA2 = CRGB(240, 249, 97);
CRGB COA3 = CRGB(210, 236, 0);
CRGB COA4 = CRGB(122, 195, 19);
// extern CRGBPalette16 colorsOfAutumnPalette;
// extern const TProgmemPalette16 colorsOfAutumnPalette FL_PROGMEM;
// const CRGB COA[5];
// COA[0] = CRGB(88,140,115);
// COA[1] = CRGB(242,174,148);
// COA[2] = CRGB(242,174,114);
// COA[3] = CRGB(217,100,89);
// COA[4] = CRGB(140,70,70);
CRGBPalette16 COA_p =
{
COA0, COA1, COA2, COA3,
COA4, COA0, COA1, COA2,
COA3, COA4, COA0, COA1,
COA2, COA3, COA4, COA0
};
// const TProgmemPalette16 COA_p FL_PROGMEM =
// {
// COA[0],
// COA[1],
// COA[2],
// COA[3],
// COA[4],
//
// COA[0],
// COA[1],
// COA[2],
// COA[3],
// COA[4],
//
// COA[0],
// COA[1],
// COA[2],
// COA[3],
// COA[4],
//
// COA[0]
// };
// CRGBPalette16 currentPalette(CRGB::Black);
CRGBPalette16 currentPalette;
// CRGBPalette16 targetPalette(SFTA_p);
CRGBPalette16 targetPalette;
// A red and white striped palette
// "CRGB::Gray" is used as white to keep the brightness more uniform.
const TProgmemRGBPalette16 RedWhite_p FL_PROGMEM =
{ CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
CRGB::Gray, CRGB::Gray, CRGB::Gray, CRGB::Gray,
CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
CRGB::Gray, CRGB::Gray, CRGB::Gray, CRGB::Gray
};
//
//// RWB
//// "CRGB::Gray" is used as white to keep the brightness more uniform.
//const TProgmemRGBPalette16 RWB_p FL_PROGMEM =
//{
// CRGB::Red, CRGB::White, CRGB::Blue, CRGB::Red,
// CRGB::White, CRGB::Blue, CRGB::Red, CRGB::White,
// CRGB::Blue, CRGB::Red, CRGB::White, CRGB::Blue,
// CRGB::Red, CRGB::White, CRGB::Blue, CRGB::Red
//};
CHSV Pink1 = CHSV(250, 255, 213);
CHSV Purple1 = CHSV(196, 255, 129);
CRGBPalette16 Mothers_Day_p =
{
CRGB::Red, CRGB::Red, CRGB::Red, CRGB::Red,
Pink1, Pink1, Pink1, Pink1,
Purple1, Purple1, Purple1, Purple1,
CRGB::Magenta, CRGB::Magenta, CRGB::Magenta, CRGB::Magenta
};
//CRGBPalette16 Mothers_Day_p =
//{
// CRGB::Red, CRGB::DeepPink, CRGB::DeepPink, CRGB::DeepPink,
// CRGB::Purple, CRGB::Purple, CRGB::Purple, CRGB::Purple,
// CRGB::Fuchsia, CRGB::Fuchsia, CRGB::Fuchsia, CRGB::Fuchsia,
// CRGB::Magenta, CRGB::Magenta, CRGB::Magenta, CRGB::Magenta
//};
CRGBPalette16 Valentines_p =
{
CRGB::Red, CRGB::Pink, CRGB::LightPink, CRGB::DeepPink,
CRGB::Purple, CRGB::MediumPurple, CRGB::Red, CRGB::Red,
CRGB::Fuchsia, CRGB::HotPink, CRGB::Lavender, CRGB::Violet,
CRGB::Magenta, CRGB::PaleVioletRed, CRGB::Salmon, CRGB::MediumPurple
};
CRGBPalette16 Mardi_Gras_p =
{
CRGB::Purple, CRGB::Purple, CRGB::Purple, CRGB::Purple,
CRGB::Purple, CRGB::Purple, CRGB::Yellow, CRGB::Yellow,
CRGB::Yellow, CRGB::Yellow, CRGB::Yellow, CRGB::Green,
CRGB::Green, CRGB::Green, CRGB::Green, CRGB::Green
};
CRGBPalette16 RWB_p =
{
CRGB::Red, CRGB::White, CRGB::Blue, CRGB::Red,
CRGB::White, CRGB::Blue, CRGB::Red, CRGB::White,
CRGB::Blue, CRGB::Red, CRGB::White, CRGB::Blue,
CRGB::Red, CRGB::White, CRGB::Blue, CRGB::Red
};
// A mostly blue palette with white accents.
// "CRGB::Gray" is used as white to keep the brightness more uniform.
const TProgmemRGBPalette16 BlueWhite_p FL_PROGMEM =
{ CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
CRGB::Blue, CRGB::Blue, CRGB::Blue, CRGB::Blue,
CRGB::Blue, CRGB::Gray, CRGB::Gray, CRGB::Gray
};
// "CRGB::Gray" is used as white to keep the brightness more uniform.
const TProgmemRGBPalette16 Green1_p FL_PROGMEM =
{ CRGB::Green, CRGB::Green, CRGB::Green, CRGB::Green,
CRGB::Green, CRGB::Green, CRGB::Green, CRGB::Green,
CRGB::Green, CRGB::Green, CRGB::Green, CRGB::Green,
CRGB::Green, CRGB::Green, CRGB::Green, CRGB::Green
};
// const TProgmemRGBPalette16* ActivePaletteList[] = {
// &SFTA_p,
// &AC_p,
// &CA_p
// };
// CRGBPalette16 SFTA_p;
// CRGBPalette16 AC_p;
// CRGBPalette16 COA_p;
const CRGBPalette16* ActivePaletteList[] =
{
// &Green1_p,
// &SFTA_p,
// &AC_p,
// &COA_p
// &RWB_p
// &Valentines_p
// &Mardi_Gras_p
&Mothers_Day_p
};
// const TProgmemPalette16 SFTA_p;
NeoPixelBus<NeoGrbFeature, NeoEsp8266BitBang800KbpsMethod> NPBStrip(NUM_LEDS, LED_PIN);
//=======================================================================================
void setup()
{
delay(2000);
Serial.begin(115200);
Serial.println();
Serial.println("inoise8_pal_demo");
Serial.println("Booting");
StartUp_Wemos_D1_R2_mini();
LEDS.addLeds<LED_TYPE, LED_PIN, COLOR_ORDER>(leds, NUM_LEDS);
LEDS.setBrightness(BRIGHTNESS);
dist = random16(1234); // A semi-random number for our noise generator
// for(uint8_t color = 0; color <5; color++) // convert RGB palette values to hex values.
// {
// uint32_t SFTA_HEX[color] = (SFTA[color].r << 16) | (SFTA[color].g << 8) | SFTA[color].b ;
// uint32_t AC_HEX[color] = (AC[color].r << 16) | (AC[color].g << 8) | AC[color].b ;
// uint32_t COA_HEX[color] = (COA[color].r << 16) | (COA[color].g << 8) | COA[color].b ;
// }
//
// for(uint8_t index = 0; index < 16; index++)
// TProgmemPalette16 SFTA_p FL_PROGMEM =
// for(uint8_t index = 0; index < 16; index++)
// {
// SFTA_p[index] = SFTA[index % 5];
// AC_p[index] = AC[index % 5] ;
// COA_p[index] = COA[index % 5] ;
// }
chooseNextColorPalette(targetPalette);
currentPalette = targetPalette;
// LEDS.show();
NPBStrip.Begin();
NPBStrip.Show();
Serial.println("end setup");
}
//=======================================================================================
void loop() {
EVERY_N_MILLISECONDS(10)
{
// nblendPaletteTowardPalette(currentPalette, targetPalette, maxChanges); // Blend towards the target palette
fillnoise8(); // Update the LED array with noise at the new location
// delay(1000);
TransferToNeoPixelBus();
NPBStrip.Show();
// LEDS.show();
}
//cycle_palette();
//TransferToNeoPixelBus();
//NPBStrip.Show();
//delay(5000);
// EVERY_N_SECONDS(10)
// { // Change the target palette to a random one every 5 seconds.
// chooseNextColorPalette( targetPalette );
// }
EVERY_N_MILLISECONDS(1000)
{
httpServer.handleClient();
Serial.println("running inoise8_pal_demo_fastLed_sPillar");
}
// TransferToNeoPixelBus();
// NPBStrip.Show();
// LEDS.show();
// delay(1);
}
void cycle_palette()
{
static uint8_t index;
fill_solid(leds, NUM_LEDS, ColorFromPalette(currentPalette, index, 255, NOBLEND)); //LINEARBLEND
Serial.print("index = ");
Serial.println(index);
index = index + 16;
}
//=======================================================================================
void fillnoise8()
{
for (int i = 0; i < NUM_LEDS; i++) // Just ONE loop to fill up the LED array as all of the pixels change.
{
// Get a value from the noise function. I'm using both x and y axis.
uint8_t index = inoise8(i * scale, dist) % 255;
// String withScale = "0 ";
// withScale += index;
// withScale += " 255";
// Serial.println(withScale);
// delay(5);
// Serial.print("currentPalette = ");
// Serial.println(currentPalette);
leds[i] = ColorFromPalette(currentPalette, index, 255, LINEARBLEND); // NOBLEND);
// With that value, look up the 8 bit colour palette value and assign it to the current LED.
// delay(1);
}
// beatsin8( BPM, low8, high8).
dist += beatsin8(10, 3, 4); //beatsin8(10, 1, 2);
// Serial.println(dist);
// delay(5);
// Moving along the distance (that random number we started out with). Vary it a bit with a sine wave.
// In some sketches, I've used millis() instead of an incremented counter. Works a treat.
}
//=======================================================================================
// Advance to the next color palette in the list (above).
void chooseNextColorPalette(CRGBPalette16& pal)
{
const uint8_t numberOfPalettes = sizeof(ActivePaletteList) / sizeof(ActivePaletteList[0]);
static uint8_t whichPalette = -1;
whichPalette = addmod8(whichPalette, 1, numberOfPalettes);
Serial.print("palette # = ");
Serial.println(whichPalette);
pal = *(ActivePaletteList[whichPalette]);
}
//=======================================================================================
void TransferToNeoPixelBus(void)
{
RgbColor NPBPixel;
for (int i = 0; i < NUM_LEDS; i++)
{
NPBPixel = RgbColor(leds[i].r, leds[i].g, leds[i].b);
NPBStrip.SetPixelColor(i, NPBPixel);
}
}
// =======================================================================================
// void startWIFI(void)
// {
// WiFi.begin(ssid, password);
//
// while (WiFi.status() != WL_CONNECTED)
// {
// Serial.print(".");
// delay(500);
// }
// Serial.println("");
// Serial.println("WiFi reconnected");
//
// }
//=============================================================================================================================
void StartUp_Wemos_D1_R2_mini(void)
{
IPAddress ip(10, 0, 0, 200); //
IPAddress gateway(10, 0, 0, 1);
IPAddress subnet(255, 255, 255, 0);
IPAddress dns(8, 8, 8, 8);
WiFi.config(ip, dns, gateway, subnet);
WiFi.mode(WIFI_AP_STA);
WiFi.begin(ssid, password);
while (WiFi.waitForConnectResult() != WL_CONNECTED)
{
Serial.println("Connection Failed! Rebooting...");
delay(5000);
ESP.restart();
}
Serial.println("");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
Serial.print("MAC: ");
Serial.println(WiFi.macAddress());
Serial.print("ChipId: ");
Serial.println(ESP.getChipId(), HEX);
uint32_t realSize = ESP.getFlashChipRealSize();
Serial.printf("Flash real size: %u\n\n", realSize);
Serial.println("");
//Serial.println("Starting UDP");
//udp.begin(localPort);
//Serial.print("Local port: ");
//Serial.println(udp.localPort());
//udpData.begin(localPortData);
MDNS.begin(host);
httpUpdater.setup(&httpServer);
httpServer.begin();
MDNS.addService("http", "tcp", 80);
Serial.printf("HTTPUpdateServer ready! Open http://%s.local/update in your browser \n", host);
//SetUpOTA();
//Blynk.begin(auth, ssid, password);
/*
Wire.begin(5, 4); // 2, 0 // 1, 3 is Rx, Tx. 5,4 is SDA,SCL (D2,D!)
display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x32)
display.display();
delay(2000);
// Clear the buffer.
display.clearDisplay();
//Serial.println("display print begin");
// text display tests
display.setTextSize(1);
display.setTextColor(WHITE);
display.setCursor(0, 0);
display.println("Hello, world!");
display.display();
delay(2000);
display.clearDisplay();
*/
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment