/*
* ==========================================================================
* Autor: Elmer Sorto
* Contacto: [email protected]
* Web: https://utec.devxi.com
* ==========================================================================
* LED Canvas - Herramienta de Diseño y Animación para Matrices de LEDs
* Desarrollada para facilitar a los estudiantes de electrónica el diseño
* y la creación de animaciones en matrices de LEDs utilizando la tecnología
* Adafruit NeoPixel.
*
* Este código fuente ha sido generado automáticamente por la herramienta
* LED Canvas, accesible exclusivamente para uso educativo y no comercial.
* Aunque el código generado no es abierto, la herramienta está diseñada
* para apoyar a estudiantes y entusiastas en sus proyectos educativos.
*
* Para soporte técnico o consultas, por favor contactar a [email protected].
* Agradecemos su interés en nuestra herramienta y esperamos que contribuya
* positivamente a sus proyectos educativos y de investigación.
* ==========================================================================
*/
#include <Adafruit_NeoPixel.h>
#define PIN 3 // Pin de datos de la matriz de LEDs
#define NUM_LEDS 256 // Número total de LEDs en la matriz
#define BRIGHTNESS 255 // Brillo de los LEDs (0-255)
#define NUM_FRAMES 4 // Total de frames en la animación
// Inicializar la matriz de LEDs
Adafruit_NeoPixel strip = Adafruit_NeoPixel(NUM_LEDS, PIN, NEO_GRB + NEO_KHZ800);
// Definir la estructura de un frame
struct Frame {
uint16_t index;
uint8_t r, g, b; // valores de color RGB
};
// Definir los frames de la animación Frame frames[frames][leds]
const Frame frames[NUM_FRAMES][256] PROGMEM = {{{144, 255, 181, 107}, {160, 255, 181, 107}, {176, 255, 181, 107}, {145, 255, 181, 107}, {161, 255, 181, 107}, {177, 255, 181, 107}, {209, 140, 86, 16}, {225, 140, 86, 16}, {130, 246, 57, 18}, {146, 246, 57, 18}, {162, 255, 181, 107}, {210, 3, 81, 172}, {226, 140, 86, 16}, {242, 140, 86, 16}, {67, 140, 86, 16}, {83, 140, 86, 16}, {99, 140, 86, 16}, {131, 246, 57, 18}, {147, 246, 57, 18}, {195, 3, 81, 172}, {211, 3, 81, 172}, {227, 140, 86, 16}, {243, 140, 86, 16}, {36, 246, 57, 18}, {52, 140, 86, 16}, {68, 255, 181, 107}, {84, 255, 181, 107}, {100, 140, 86, 16}, {116, 140, 86, 16}, {132, 246, 57, 18}, {148, 246, 57, 18}, {164, 246, 57, 18}, {180, 4, 78, 163}, {196, 3, 81, 172}, {212, 3, 81, 172}, {228, 3, 81, 172}, {244, 140, 86, 16}, {21, 246, 57, 18}, {37, 246, 57, 18}, {53, 140, 86, 16}, {69, 140, 86, 16}, {85, 140, 86, 16}, {101, 255, 181, 107}, {117, 255, 181, 107}, {133, 246, 57, 18}, {149, 246, 57, 18}, {165, 246, 57, 18}, {181, 0, 89, 193}, {197, 4, 78, 163}, {213, 3, 81, 172}, {229, 3, 81, 172}, {22, 246, 57, 18}, {38, 246, 57, 18}, {54, 140, 86, 16}, {70, 255, 181, 107}, {86, 140, 86, 16}, {102, 255, 181, 107}, {118, 255, 181, 107}, {134, 0, 89, 193}, {150, 0, 89, 193}, {166, 0, 89, 193}, {182, 0, 89, 193}, {198, 0, 89, 193}, {214, 3, 81, 172}, {23, 246, 57, 18}, {39, 246, 57, 18}, {55, 255, 181, 107}, {71, 255, 181, 107}, {87, 255, 181, 107}, {103, 255, 181, 107}, {119, 255, 181, 107}, {135, 0, 89, 193}, {151, 0, 89, 193}, {167, 221, 208, 36}, {183, 0, 89, 193}, {199, 0, 89, 193}, {215, 0, 89, 193}, {24, 246, 57, 18}, {40, 246, 57, 18}, {56, 255, 181, 107}, {72, 255, 181, 107}, {88, 255, 181, 107}, {104, 255, 181, 107}, {120, 255, 181, 107}, {136, 246, 57, 18}, {152, 0, 89, 193}, {168, 0, 89, 193}, {184, 0, 89, 193}, {200, 0, 89, 193}, {216, 0, 89, 193}, {25, 246, 57, 18}, {41, 246, 57, 18}, {57, 0, 164, 46}, {73, 0, 164, 46}, {89, 255, 181, 107}, {105, 92, 55, 8}, {121, 255, 181, 107}, {137, 246, 57, 18}, {153, 246, 57, 18}, {169, 0, 89, 193}, {185, 0, 89, 193}, {201, 0, 89, 193}, {217, 0, 89, 193}, {42, 246, 57, 18}, {58, 255, 181, 107}, {74, 255, 181, 107}, {90, 92, 55, 8}, {106, 92, 55, 8}, {122, 255, 181, 107}, {154, 246, 57, 18}, {170, 0, 89, 193}, {186, 0, 89, 193}, {202, 0, 89, 193}, {218, 0, 89, 193}, {234, 0, 89, 193}, {43, 246, 57, 18}, {75, 243, 170, 98}, {91, 255, 181, 107}, {107, 92, 55, 8}, {123, 255, 181, 107}, {155, 246, 57, 18}, {171, 246, 57, 18}, {187, 0, 89, 193}, {203, 0, 89, 193}, {219, 0, 89, 193}, {235, 0, 89, 193}, {44, 246, 57, 18}, {76, 240, 165, 90}, {92, 243, 170, 98}, {108, 92, 55, 8}, {156, 255, 181, 107}, {172, 246, 57, 18}, {204, 140, 86, 16}, {220, 140, 86, 16}, {236, 140, 86, 16}, {93, 243, 170, 98}, {157, 255, 181, 107}, {173, 255, 181, 107}, {189, 140, 86, 16}, {205, 140, 86, 16}, {221, 140, 86, 16}, {237, 140, 86, 16}, {174, 255, 181, 107}}, {{51, 140, 86, 16}, {67, 140, 86, 16}, {83, 140, 86, 16}, {195, 255, 181, 107}, {211, 255, 181, 107}, {20, 246, 57, 18}, {36, 140, 86, 16}, {52, 255, 181, 107}, {68, 255, 181, 107}, {84, 140, 86, 16}, {100, 140, 86, 16}, {132, 246, 57, 18}, {148, 246, 57, 18}, {164, 246, 57, 18}, {180, 255, 181, 107}, {196, 255, 181, 107}, {212, 255, 181, 107}, {228, 140, 86, 16}, {5, 246, 57, 18}, {21, 246, 57, 18}, {37, 140, 86, 16}, {53, 140, 86, 16}, {69, 140, 86, 16}, {85, 255, 181, 107}, {101, 255, 181, 107}, {117, 246, 57, 18}, {133, 246, 57, 18}, {149, 246, 57, 18}, {165, 246, 57, 18}, {181, 246, 57, 18}, {197, 255, 181, 107}, {213, 0, 89, 193}, {229, 140, 86, 16}, {6, 246, 57, 18}, {22, 246, 57, 18}, {38, 140, 86, 16}, {54, 255, 181, 107}, {70, 140, 86, 16}, {86, 255, 181, 107}, {102, 255, 181, 107}, {118, 0, 89, 193}, {134, 0, 89, 193}, {150, 246, 57, 18}, {166, 0, 89, 193}, {182, 0, 89, 193}, {198, 0, 89, 193}, {214, 140, 86, 16}, {230, 140, 86, 16}, {7, 246, 57, 18}, {23, 246, 57, 18}, {39, 255, 181, 107}, {55, 255, 181, 107}, {71, 255, 181, 107}, {87, 255, 181, 107}, {103, 255, 181, 107}, {119, 246, 57, 18}, {135, 246, 57, 18}, {151, 221, 208, 36}, {167, 0, 89, 193}, {183, 0, 89, 193}, {199, 0, 89, 193}, {215, 0, 89, 193}, {8, 246, 57, 18}, {24, 246, 57, 18}, {40, 255, 181, 107}, {56, 255, 181, 107}, {72, 255, 181, 107}, {88, 255, 181, 107}, {104, 255, 181, 107}, {120, 0, 89, 193}, {136, 0, 89, 193}, {152, 0, 89, 193}, {168, 0, 89, 193}, {184, 0, 89, 193}, {200, 0, 89, 193}, {216, 0, 89, 193}, {232, 0, 89, 193}, {248, 140, 86, 16}, {9, 246, 57, 18}, {25, 246, 57, 18}, {41, 0, 164, 46}, {57, 0, 164, 46}, {73, 255, 181, 107}, {89, 92, 55, 8}, {105, 255, 181, 107}, {121, 246, 57, 18}, {137, 0, 89, 193}, {153, 0, 89, 193}, {169, 0, 89, 193}, {185, 0, 89, 193}, {201, 0, 89, 193}, {217, 0, 89, 193}, {233, 0, 89, 193}, {249, 140, 86, 16}, {26, 246, 57, 18}, {42, 255, 181, 107}, {58, 255, 181, 107}, {74, 92, 55, 8}, {90, 92, 55, 8}, {106, 255, 181, 107}, {138, 246, 57, 18}, {154, 246, 57, 18}, {170, 0, 89, 193}, {186, 0, 89, 193}, {202, 0, 89, 193}, {218, 0, 89, 193}, {234, 140, 86, 16}, {250, 140, 86, 16}, {27, 246, 57, 18}, {59, 243, 170, 98}, {75, 255, 181, 107}, {91, 92, 55, 8}, {107, 255, 181, 107}, {155, 246, 57, 18}, {171, 255, 181, 107}, {187, 255, 181, 107}, {219, 0, 89, 193}, {235, 140, 86, 16}, {251, 140, 86, 16}, {28, 246, 57, 18}, {60, 240, 165, 90}, {76, 243, 170, 98}, {92, 92, 55, 8}, {172, 255, 181, 107}, {188, 255, 181, 107}, {252, 140, 86, 16}, {77, 243, 170, 98}, {173, 255, 181, 107}}, {{51, 140, 86, 16}, {67, 140, 86, 16}, {83, 140, 86, 16}, {131, 246, 57, 18}, {147, 246, 57, 18}, {163, 255, 181, 107}, {179, 0, 89, 193}, {195, 0, 89, 193}, {211, 0, 89, 193}, {20, 246, 57, 18}, {36, 140, 86, 16}, {52, 255, 181, 107}, {68, 255, 181, 107}, {84, 140, 86, 16}, {100, 140, 86, 16}, {116, 246, 57, 18}, {132, 0, 89, 193}, {148, 0, 89, 193}, {164, 0, 89, 193}, {180, 0, 89, 193}, {196, 0, 89, 193}, {212, 0, 89, 193}, {228, 0, 89, 193}, {244, 140, 86, 16}, {5, 246, 57, 18}, {21, 246, 57, 18}, {37, 140, 86, 16}, {53, 140, 86, 16}, {69, 140, 86, 16}, {85, 255, 181, 107}, {101, 255, 181, 107}, {117, 0, 89, 193}, {133, 246, 57, 18}, {149, 0, 89, 193}, {165, 0, 89, 193}, {181, 0, 89, 193}, {197, 0, 89, 193}, {213, 0, 89, 193}, {229, 0, 89, 193}, {245, 140, 86, 16}, {6, 246, 57, 18}, {22, 246, 57, 18}, {38, 140, 86, 16}, {54, 255, 181, 107}, {70, 140, 86, 16}, {86, 255, 181, 107}, {102, 255, 181, 107}, {118, 246, 57, 18}, {134, 246, 57, 18}, {150, 0, 89, 193}, {166, 0, 89, 193}, {182, 0, 89, 193}, {198, 0, 89, 193}, {214, 0, 89, 193}, {230, 140, 86, 16}, {246, 140, 86, 16}, {7, 246, 57, 18}, {23, 246, 57, 18}, {39, 255, 181, 107}, {55, 255, 181, 107}, {71, 255, 181, 107}, {87, 255, 181, 107}, {103, 255, 181, 107}, {119, 246, 57, 18}, {135, 246, 57, 18}, {151, 246, 57, 18}, {167, 246, 57, 18}, {183, 0, 89, 193}, {199, 0, 89, 193}, {215, 0, 89, 193}, {231, 140, 86, 16}, {247, 140, 86, 16}, {8, 246, 57, 18}, {24, 246, 57, 18}, {40, 255, 181, 107}, {56, 255, 181, 107}, {72, 255, 181, 107}, {88, 255, 181, 107}, {104, 255, 181, 107}, {120, 0, 89, 193}, {136, 246, 57, 18}, {152, 246, 57, 18}, {168, 246, 57, 18}, {184, 246, 57, 18}, {200, 255, 181, 107}, {248, 140, 86, 16}, {9, 246, 57, 18}, {25, 246, 57, 18}, {41, 255, 181, 107}, {57, 0, 164, 46}, {73, 255, 181, 107}, {89, 92, 55, 8}, {105, 255, 181, 107}, {137, 0, 89, 193}, {153, 246, 57, 18}, {169, 246, 57, 18}, {185, 255, 181, 107}, {201, 255, 181, 107}, {217, 255, 181, 107}, {26, 246, 57, 18}, {42, 255, 181, 107}, {58, 0, 164, 46}, {74, 92, 55, 8}, {90, 92, 55, 8}, {106, 255, 181, 107}, {170, 246, 57, 18}, {186, 255, 181, 107}, {202, 255, 181, 107}, {27, 246, 57, 18}, {59, 243, 170, 98}, {75, 255, 181, 107}, {91, 92, 55, 8}, {107, 255, 181, 107}, {28, 246, 57, 18}, {60, 240, 165, 90}, {76, 243, 170, 98}, {92, 92, 55, 8}, {77, 243, 170, 98}}, {{160, 255, 181, 107}, {176, 255, 181, 107}, {145, 255, 181, 107}, {161, 255, 181, 107}, {177, 255, 181, 107}, {209, 140, 86, 16}, {225, 140, 86, 16}, {146, 246, 57, 18}, {162, 246, 57, 18}, {178, 255, 181, 107}, {210, 0, 89, 193}, {226, 140, 86, 16}, {242, 140, 86, 16}, {67, 140, 86, 16}, {83, 140, 86, 16}, {99, 140, 86, 16}, {131, 246, 57, 18}, {147, 246, 57, 18}, {163, 246, 57, 18}, {195, 0, 89, 193}, {211, 0, 89, 193}, {227, 140, 86, 16}, {243, 140, 86, 16}, {36, 246, 57, 18}, {52, 140, 86, 16}, {68, 255, 181, 107}, {84, 255, 181, 107}, {100, 140, 86, 16}, {116, 140, 86, 16}, {132, 246, 57, 18}, {148, 246, 57, 18}, {164, 246, 57, 18}, {180, 0, 89, 193}, {196, 0, 89, 193}, {212, 0, 89, 193}, {228, 0, 89, 193}, {244, 140, 86, 16}, {21, 246, 57, 18}, {37, 246, 57, 18}, {53, 140, 86, 16}, {69, 140, 86, 16}, {85, 140, 86, 16}, {101, 255, 181, 107}, {117, 255, 181, 107}, {133, 0, 89, 193}, {149, 0, 89, 193}, {165, 0, 89, 193}, {181, 0, 89, 193}, {197, 0, 89, 193}, {213, 0, 89, 193}, {229, 0, 89, 193}, {22, 246, 57, 18}, {38, 246, 57, 18}, {54, 140, 86, 16}, {70, 255, 181, 107}, {86, 140, 86, 16}, {102, 255, 181, 107}, {118, 255, 181, 107}, {134, 246, 57, 18}, {150, 0, 89, 193}, {166, 0, 89, 193}, {182, 0, 89, 193}, {198, 0, 89, 193}, {214, 0, 89, 193}, {23, 246, 57, 18}, {39, 246, 57, 18}, {55, 255, 181, 107}, {71, 255, 181, 107}, {87, 255, 181, 107}, {103, 255, 181, 107}, {119, 255, 181, 107}, {135, 246, 57, 18}, {151, 246, 57, 18}, {167, 221, 208, 36}, {183, 0, 89, 193}, {199, 0, 89, 193}, {215, 3, 81, 172}, {24, 246, 57, 18}, {40, 246, 57, 18}, {56, 255, 181, 107}, {72, 255, 181, 107}, {88, 255, 181, 107}, {104, 255, 181, 107}, {120, 255, 181, 107}, {136, 246, 57, 18}, {152, 246, 57, 18}, {168, 246, 57, 18}, {184, 0, 89, 193}, {200, 3, 81, 172}, {216, 3, 81, 172}, {25, 246, 57, 18}, {41, 246, 57, 18}, {57, 0, 164, 46}, {73, 0, 164, 46}, {89, 255, 181, 107}, {105, 92, 55, 8}, {121, 255, 181, 107}, {137, 246, 57, 18}, {153, 246, 57, 18}, {169, 246, 57, 18}, {185, 3, 81, 172}, {201, 3, 81, 172}, {217, 3, 81, 172}, {233, 3, 81, 172}, {42, 246, 57, 18}, {58, 255, 181, 107}, {74, 255, 181, 107}, {90, 92, 55, 8}, {106, 92, 55, 8}, {122, 255, 181, 107}, {154, 246, 57, 18}, {170, 246, 57, 18}, {186, 3, 81, 172}, {202, 3, 81, 172}, {218, 3, 81, 172}, {234, 3, 81, 172}, {43, 246, 57, 18}, {75, 243, 170, 98}, {91, 255, 181, 107}, {107, 92, 55, 8}, {123, 255, 181, 107}, {155, 246, 57, 18}, {171, 246, 57, 18}, {203, 140, 86, 16}, {219, 140, 86, 16}, {235, 140, 86, 16}, {44, 246, 57, 18}, {76, 240, 165, 90}, {92, 243, 170, 98}, {108, 92, 55, 8}, {156, 255, 181, 107}, {172, 255, 181, 107}, {188, 140, 86, 16}, {204, 140, 86, 16}, {220, 140, 86, 16}, {236, 140, 86, 16}, {93, 243, 170, 98}, {157, 255, 181, 107}, {173, 255, 181, 107}, {174, 255, 181, 107}}};
void setup() {
strip.begin();
strip.setBrightness(BRIGHTNESS);
strip.show(); // Inicializar todos los LEDs apagados
}
void displayFrame(const Frame* currentFrame, int size) {
strip.clear(); // Clear all LEDs
for (int i = 0; i < size; i++) {
Frame f;
// Leer el frame actual desde la memoria flash
memcpy_P(&f, ¤tFrame[i], sizeof(Frame));
uint32_t color = strip.Color(f.r, f.g, f.b); // Convertir RGB a color
strip.setPixelColor(f.index, color);
}
strip.show();
delay(150);
}
void loop() {
int frameCount = sizeof(frames) / sizeof(frames[0]);
bool reverse = false;
int i = 0; // Iniciar desde el primer frame afuera del bucle para evitar repetir el primer frame
while (true) {
if (!reverse) {
for (; i < frameCount; i++) {
displayFrame(frames[i], sizeof(frames[i]) / sizeof(frames[i][0]));
}
reverse = true; // Cambiar dirección al final
i -= 2; // Ajustar el índice para evitar repetir el último frame
} else {
for (; i >= 0; i--) {
displayFrame(frames[i], sizeof(frames[i]) / sizeof(frames[i][0]));
}
reverse = false; // Cambiar dirección al final
i += 2; // Ajustar el índice para evitar repetir el primer frame
}
}
}