/********************** Effects
//
Set Mode Effects
0. Static - No blinking. Just plain old static light.
1. Blink - Normal blinking. 50% on/off time.
2. Breath - Does the "standby-breathing" of well known i-Devices. Fixed Speed.
3. Color Wipe - Lights all LEDs after each other up. Then turns them in that order off. Repeat.
4. Color Wipe Inverse - Same as Color Wipe, except swaps on/off colors.
5. Color Wipe Reverse - Lights all LEDs after each other up. Then turns them in reverse order off. Repeat.
6. Color Wipe Reverse Inverse - Same as Color Wipe Reverse, except swaps on/off colors.
7. Color Wipe Random - Turns all LEDs after each other to a random color. Then starts over with another color.
8. Random Color - Lights all LEDs in one random color up. Then switches them to the next random color.
9. Single Dynamic - Lights every LED in a random color. Changes one random LED after the other to a random color.
10. Multi Dynamic - Lights every LED in a random color. Changes all LED at the same time to new random colors.
11. Rainbow - Cycles all LEDs at once through a rainbow.
12. Rainbow Cycle - Cycles a rainbow over the entire string of LEDs.
13. Scan - Runs a single pixel back and forth.
14. Dual Scan - Runs two pixel back and forth in opposite directions.
15. Fade - Fades the LEDs on and (almost) off again.
16. Theater Chase - Theatre-style crawling lights. Inspired by the Adafruit examples.
17. Theater Chase Rainbow - Theatre-style crawling lights with rainbow effect. Inspired by the Adafruit examples.
18. Running Lights - Running lights effect with smooth sine transition.
19. Twinkle - Blink several LEDs on, reset, repeat.
20. Twinkle Random - Blink several LEDs in random colors on, reset, repeat.
21. Twinkle Fade - Blink several LEDs on, fading out.
22. Twinkle Fade Random - Blink several LEDs in random coors on, fading out.
23. Sparkle - Blinks one LED at a time.
24. Flash Sparkle - Lights all LEDs in the selected color. Flashes single white pixels randomly.
25. Hyper Sparkle - Like flash sparkle. With more flash.
26. Strobe - Classic Strobe effect.
27. Strobe Rainbow - Classic Strobe effect. Cycling through the rainbow.
28. Multi Strobe - Strobe effect with different strobe count and pause, controlled by speed setting.
29. Blink Rainbow - Classic Blink effect. Cycling through the rainbow.
30. Chase White - Color running on white.
31. Chase Color - White running on color.
32. Chase Random - White running followed by random color.
33. Chase Rainbow - White running on rainbow.
34. Chase Flash - White flashes running on color.
35. Chase Flash Random - White flashes running, followed by random color.
36. Chase Rainbow White - Rainbow running on white.
37. Chase Blackout - Black running on color.
38. Chase Blackout Rainbow - Black running on rainbow.
39. Color Sweep Random - Random color introduced alternating from start and end of strip.
40. Running Color - Alternating color/white pixels running.
41. Running Red Blue - Alternating red/blue pixels running.
42. Running Random - Random colored pixels running.
43. Larson Scanner - K.I.T.T.
44. Comet - Firing comets from one end.
45. Fireworks - Firework sparks.
46. Fireworks Random - Random colored firework sparks.
47. Merry Christmas - Alternating green/red pixels running
48, Fire Flicker - Fire flickering effect. Like in harsh wind.
49. Fire Flicker (soft) - Fire flickering effect. Runs slower/softer.
50. Fire Flicker (intense) - Fire flickering effect. More range of color.
51. Circus Combustus - Alternating white/red/black pixels running.
52. Halloween - Alternating orange/purple pixels running.
53. Bicolor Chase - Two LEDs running on a background color.
54. Tricolor Chase - Alternating three color pixels running.
55. TwinkleFOX - Lights fading in and out randomly.
56. thru 63. Custom - Up to eight user created custom effects.
*/
#include <WS2812FX.h>
#include <FastLED.h>
#include <Adafruit_NeoPixel.h>
//#ifdef __AVR__
//#include <avr/power.h>
//#endif
#define LED_COUNT 14
#define LED_PIN 0
#define BRIGHTNESS 20
const int button1 = 1; // the number of the pushbutton pin
const int button2 = 2; // the number of the pushbutton pin RESET
volatile int COUNT = 0; // CONTADOR
volatile int estado = 0;
//volatile int valor = false;
//#define TIMER_MS 5200
WS2812FX ws2812fx = WS2812FX(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip = Adafruit_NeoPixel(LED_COUNT, LED_PIN, NEO_GRB + NEO_KHZ800);
//..................................................................
byte ballColors[5][3] = { {0xff, 0,0}, // red
{0, 0xff, 0}, // green
{0, 0, 0xff}, // blue
{0xff, 0xff, 0xff},// white
{0xff, 0xff, 0} }; // yellow
bool oldState = HIGH;
int showType = 0;
bool gReverseDirection = false; //con fastled
//+++++++++++++++++
const int rainbowColors[][3] = {
{255, 0, 0}, // Red
{255, 32, 0}, //
{255, 64, 0}, //
{255, 96, 0}, //
{255, 128, 0}, //
{255, 160, 0}, //
{255, 192, 0}, //
{255, 224, 0}, //
{255, 255, 0}, // yellow
{224, 255, 0}, //
{192, 255, 0}, //
{160, 255, 0}, //
{128, 255, 0}, //
{96, 255, 0}, //
{64, 255, 0}, //
{32, 255, 0}, //
{0, 255, 0}, // green
{0, 255, 32}, //
{0, 255, 64}, //
{0, 255, 96}, //
{0, 255, 128}, //
{0, 255, 160}, //
{0, 255, 192}, //
{0, 255, 224}, //
{0, 255, 255}, // cyan
{0, 224, 255}, //
{0, 192, 255}, //
{0, 160, 255}, //
{0, 128, 255}, //
{0, 96, 255}, //
{0, 64, 255}, //
{0, 32, 255}, //
{0, 0, 255}, // blue
{32, 0, 255}, //
{64, 0, 255}, //
{96, 0, 255}, //
{128, 0, 255}, //
{160, 0, 255}, //
{192, 0, 255}, //
{224, 0, 255}, //
{255, 0, 255}, // magenta
{255, 0, 224}, //
{255, 0, 192}, //
{255, 0, 160}, //
{255, 0, 128}, //
{255, 0, 96}, //
{255, 0, 64}, //
{255, 0, 32}, //
};
const int numColors = sizeof(rainbowColors)/sizeof(rainbowColors[0]);
int mixedColors[numColors][3] = {};
//+++++++++++++++++++++++++++++++++++
//Adafruit_NeoPixel strip
// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
if(WheelPos < 85) {
return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}
else if(WheelPos < 170) {
WheelPos -= 85;
return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
}
else {
WheelPos -= 170;
return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
}
}
unsigned long last_change = 0;
unsigned long now = 0;
//...............................................................................
void setup() {
// put your setup code here, to run once:
Serial.begin(115200);
Serial.println("Hello, ESP32-C3!");
pinMode(LED_PIN,OUTPUT);
pinMode(button1, INPUT);
pinMode(button2, INPUT);
strip.begin();
strip.setBrightness(BRIGHTNESS);
strip.show(); // Initialize all pixels to 'off'
for(int i = 0; i < numColors-1; i++){
int rand = random(numColors-1);
mixedColors[i][0] = rainbowColors[rand][0];
mixedColors[i][1] = rainbowColors[rand][1];
mixedColors[i][2] = rainbowColors[rand][2];
}
//++++++++++++++pruebas
// setup the custom fade effect
//uint8_t myFadeMode = ws2812fx.setCustomMode(F("Custom Fade"), myFade);
// setup the segment
//uint32_t colors[] = {RED, GREEN, BLUE};
//ws2812fx.setSegment(0, 0, LED_COUNT-1, myFadeMode, colors, 50, NO_OPTIONS);
//++++++++++++++++++++
ws2812fx.init();
ws2812fx.setColor(BLUE);
ws2812fx.setBrightness(100);
ws2812fx.setSpeed(1500); //(200);
ws2812fx.setMode(47);
ws2812fx.start();
}
void loop() {
now = millis();
ws2812fx.service();
// Get current button state.
bool newState = digitalRead(button1);
// Check if state changed from high to low (button press).
if (newState == LOW && oldState == HIGH) {
// Short delay to debounce button.
delay(20);
// Check if button is still low after debounce.
newState = digitalRead(button1);
if (newState == LOW) {
showType++;
if (showType > 4)
showType=0;
startShow(showType);
Serial.print(showType);
Serial.println(" = COUNT");
delay(500); // this speeds up the simulation
}
}
// Set the last button state to the old state.
oldState = newState;
}
void startShow(int i) {
ws2812fx.stop();
//fa
switch(i){
case 0:
uno();
break;
case 1:
//colorWipe(strip.Color(255, 5, 180), 50); // Pink
doce();
break;
case 2:
//colorWipe(strip.Color(255, 0, 0), 50); // Red
//rainbow(30);
tres();
break;
case 3:
//colorWipe(strip.Color(255, 150, 0), 50); // Orange
cinco();
//once();
break;
case 4:
//colorWipe(strip.Color(255, 150, 0), 50); // Orange
//siete(3);
//superNova(3);
//dos();
seis();
break;
}
//ws2812fx.service();
}
//........................................................................
// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
for(uint16_t i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, c);
strip.show();
delay(wait);
}
}
void uno(){
//ws2812fx.resetSegments();
//ws2812fx.resetSegmentRuntimes();
//ws2812fx.setSegment(0, 0, LED_COUNT-1, FX_MODE_STATIC, 0x000000, 1000, false); // off
//ws2812fx.setSegment(1, 5, 9, FX_MODE_STATIC, 0x000000, 1000, false);
//ws2812fx.setSegment(2, 10, 13, FX_MODE_STATIC, 0x000000, 1000, true);
ws2812fx.clear();
ws2812fx.resetSegments();
ws2812fx.init();
ws2812fx.setColor(0XFF00FF); //fuchsia
ws2812fx.setBrightness(100);
ws2812fx.setSpeed(1500); //(200);
ws2812fx.setMode(0);
ws2812fx.start();
//ws2812fx.resetSegments();
// ws2812fx.resetSegmentRuntimes();
//ws2812fx.init();
//ws2812fx.setBrightness(128);
//ws2812fx.setSegment(0, 0, LED_COUNT-1, FX_MODE_STATIC, 0xFF00FF, 1000, false); // fucsia
//ws2812fx.start();
}
void dos(){
ws2812fx.resetSegments();
ws2812fx.resetSegmentRuntimes();
ws2812fx.clear();
ws2812fx.init();
ws2812fx.setColor(RED);
ws2812fx.setBrightness(100);
ws2812fx.setSpeed(1500); //(200);
ws2812fx.setMode(0);
ws2812fx.start();
//colorWipe(strip.Color(255, 5, 180), 50); // Pink
}
void tres(){
ws2812fx.clear();
ws2812fx.init();
ws2812fx.setColor(0X00FFFF); //cyan
ws2812fx.setBrightness(100);
ws2812fx.setSpeed(1500); //(200);
ws2812fx.setMode(6);
ws2812fx.start();
}
void cuatro(){
ws2812fx.clear();
ws2812fx.init();
//ws2812fx.setColor(0XFF69B4); //hotpink
//ws2812fx.setBrightness(100);
//ws2812fx.setSpeed(1500); //(200);
//ws2812fx.setMode(44);
//ws2812fx.start();
// divide the string of LEDs into two independent segments
uint32_t colors[] = {RED, GREEN};
ws2812fx.setSegment(0, 0, (LED_COUNT/2)-1, FX_MODE_BLINK, colors, 1000, false);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT-1, FX_MODE_BLINK, COLORS(ORANGE, PURPLE), 1000, false);
ws2812fx.start();
}
void cinco(){
ws2812fx.resetSegments();
ws2812fx.resetSegmentRuntimes();
ws2812fx.clear();
ws2812fx.init();
ws2812fx.setSegment(0, 0, 4, FX_MODE_BLINK, 0xFF0000, 1000, false); // segment 0 is leds 0 - 9
ws2812fx.setSegment(1, 5, 9, FX_MODE_BLINK, 0x00FF00, 1000, false); // segment 1 is leds 10 - 19 FX_MODE_SCAN
ws2812fx.setSegment(2, 10, 13, FX_MODE_BLINK, 0x0000FF, 1000, true); // segment 2 is leds 20 - 29 FX_MODE_COMET
ws2812fx.start();
}
void seis(){
// El segmento 0 es el efecto cometa incorporado.
ws2812fx.resetSegments();
ws2812fx.resetSegmentRuntimes();
ws2812fx.setSegment(0, 0, LED_COUNT/2 - 1, FX_MODE_COMET, RED, 1000, false);
// El segmento 1 es nuestro efecto personalizado.
ws2812fx.setCustomMode(myCustomEffect);
ws2812fx.setSegment(1, LED_COUNT/2, LED_COUNT - 1, FX_MODE_CUSTOM, RED, 50, false);
ws2812fx.start();
}
void siete(int t){
//void superNova(int t){
int ctc = 16;
for(int ci = 0; ci < numColors; ci++){
int pxCount = strip.numPixels()-1;
for(int pi = 0; pi < pxCount; pi++){
strip.setPixelColor(pi-ci, strip.Color(rainbowColors[ci][0], rainbowColors[ci][1], rainbowColors[ci][2]));
strip.setPixelColor(pi-ci-1, strip.Color(0, 0, 0));
strip.setPixelColor(pxCount+ci , strip.Color(rainbowColors[ci][0], rainbowColors[ci][1], rainbowColors[ci][2]));
strip.setPixelColor(pxCount+ci+1, strip.Color(0, 0, 0));
strip.show();
delay(t);
pxCount--;
}
}
}
void ocho(){
//Configurar el efecto de desvanecimiento personalizado
uint8_t myFadeMode = ws2812fx.setCustomMode(F("Custom Fade"), myFade);
ws2812fx.init();
ws2812fx.setBrightness(50);
ws2812fx.setSpeed(1000);
ws2812fx.setColor(0x000000);
ws2812fx.setMode(FX_MODE_STATIC);
ws2812fx.setSegment(0, 0, LED_COUNT-1, myFadeMode, (const uint32_t[]) {RED, BLUE}, 25, NO_OPTIONS);
ws2812fx.start();
}
void nueve(){
ws2812fx.init();
ws2812fx.setBrightness(255);
ws2812fx.setColor(BLUE);
ws2812fx.setSpeed(1000);
ws2812fx.setMode(FX_MODE_CUSTOM);
ws2812fx.setCustomMode(myCustomEffect);
ws2812fx.start();
}
void diez(){
ws2812fx.init();
ws2812fx.setBrightness(128);
// parameters: index, start, stop, mode, color, speed, reverse
ws2812fx.setSegment(0, 0, 3, FX_MODE_BLINK, 0xFF0000, 1000, false); // segment 0 is leds 0 - 9
ws2812fx.setSegment(1, 4, 10, FX_MODE_SCAN, 0x00FF00, 1000, false); // segment 1 is leds 10 - 19
ws2812fx.setSegment(2, 11, 13, FX_MODE_COMET, 0x0000FF, 1000, true); // segment 2 is leds 20 - 29
ws2812fx.start();
}
void once(){
// palettes
const uint32_t palettes[][3] = {
{ RED, GREEN, BLUE }, // PRIMARY
{ YELLOW, CYAN, MAGENTA }, // SECONDARY
{ PURPLE, ORANGE, PINK }, // WEIRD
{ 0xf08000, 0x448211, 0x900820 } // CRAZY
};
// palette names used index into the palettes[] array for convenience
#define PRIMARY 0
#define SECONDARY 1
#define WEIRD 2
#define CRAZY 3
ws2812fx.init();
ws2812fx.setBrightness(32);
// parameters: index, start, stop, mode, color, speed
ws2812fx.setSegment(0, 0, 2, FX_MODE_BLINK, palettes[0], 1000);
ws2812fx.setSegment(1, 3, 5, FX_MODE_SCAN, palettes[SECONDARY], 1000);
ws2812fx.setSegment(2, 6, 8, FX_MODE_COMET, palettes[WEIRD], 1000);
ws2812fx.start();
}
void doce(){
ws2812fx.resetSegments();
ws2812fx.resetSegmentRuntimes();
ws2812fx.init();
ws2812fx.setBrightness(128);
// parameters: index, start, stop, mode, color, speed, reverse
ws2812fx.setSegment(0, 0, LED_COUNT-1, FX_MODE_STATIC, 0xFF0000, 1000, false); // rojo
//ws2812fx.setSegment(1, 4, 10, FX_MODE_SCAN, 0x00FF00, 1000, false); // segment 1 is leds 10 - 19
//ws2812fx.setSegment(2, 11, 13, FX_MODE_COMET, 0x0000FF, 1000, true); // segment 2 is leds 20 - 29
ws2812fx.start();
}
/*
uint16_t myCustomEffect1() {
Fire2012();
// return the animation speed based on the ws2812fx speed setting
return (ws2812fx.getSpeed() / LED_COUNT);
}
#define COOLING 55
#define SPARKING 120
void Fire2012()
{
// Array of temperature readings at each simulation cell
static byte heat[LED_COUNT];
// Step 1. Cool down every cell a little
for( int i = 0; i < LED_COUNT; i++) {
heat[i] = qsub8( heat[i], random8(0, ((COOLING * 10) / LED_COUNT) + 2));
}
// Step 2. Heat from each cell drifts 'up' and diffuses a little
for( int k= LED_COUNT - 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 < LED_COUNT; j++) {
CRGB color = HeatColor( heat[j]);
int pixelnumber;
if( gReverseDirection ) {
pixelnumber = (LED_COUNT-1) - j;
} else {
pixelnumber = j;
}
// **** modified for use with WS2812FX ****
// leds[pixelnumber] = color;
ws2812fx.setPixelColor(pixelnumber, color.red, color.green, color.blue);
// **** modified for use with WS2812FX ****
}
}
*/
uint16_t myCustomEffect(void) { // random chase
WS2812FX::Segment* seg = ws2812fx.getSegment(); // get the current segment
for(uint16_t i=seg->stop; i>seg->start; i--) {
ws2812fx.setPixelColor(i, ws2812fx.getPixelColor(i-1));
}
uint32_t color = ws2812fx.getPixelColor(seg->start + 1);
int r = random(6) != 0 ? (color >> 16 & 0xFF) : random(256);
int g = random(6) != 0 ? (color >> 8 & 0xFF) : random(256);
int b = random(6) != 0 ? (color & 0xFF) : random(256);
ws2812fx.setPixelColor(seg->start, r, g, b);
return seg->speed; // return the delay until the next animation step (in msec)
}
//-------------------------------------------
void rainbow(uint8_t wait) {
uint16_t i, j;
for (j=0; j<256; j++) {
for (i=0; i<strip.numPixels(); i++) {
strip.setPixelColor(i, Wheel((i+j) & 255));
}
strip.show();
delay(250);
}
}
//++++++++++++++++++++++++++++++++++++++++++++++++++++probando
//retardo
//long static then = 0;
//if(millis() > then + 5000) {
//ws2812fx.resetSegmentRuntimes();
//then = millis();
//}
uint16_t myFade(void) {
WS2812FX::Segment *segment = ws2812fx.getSegment();
WS2812FX::Segment_runtime *runtime = ws2812fx.getSegmentRuntime();
uint32_t color = ws2812fx.color_blend(segment->colors[0], segment->colors[1], runtime->counter_mode_step);
if (color == segment->colors[1] && segment->options != 1) {
runtime->counter_mode_step = 0;
return (segment->speed / 128);
}
for (uint16_t i = segment->start; i <= segment->stop; i++) {
ws2812fx.setPixelColor(i, color);
}
runtime->counter_mode_step += 4;
if (runtime->counter_mode_step > 255) {
runtime->counter_mode_step = 255;
segment->options = 1;
}
return (segment->speed / 128);
}
void setAll(byte red, byte green, byte blue) {
for (int i = 0; i < LED_COUNT; i++ ) {
ws2812fx.setPixelColor(i, red, green, blue);
}
//showStrip();
ws2812fx.start();
}
Loading
aitewinrobot-esp32c3-supermini
aitewinrobot-esp32c3-supermini