Buen día con todos del foro.
Tengo un módulo de matriz MAX7219 (4 en 1) controlado con un arduino nano, lo que necesito realizar es que me muestre una serie de textos con distintos efectos y luego mostrar varios tipos de animaciones.
Texto: puede ser una palabra o una oración
Animación: distintos tipos de dibujos que pueda mostrar la matriz
Objetivo: Después de un determinado texto quiero que se muestre una animación que yo elija y luego que siga mostrando los textos que continúen y volver a mostrar otra animación distinta.
Problema: No puedo hacer que muestre una animación distinta que yo elija en cualquier momento. solo pude hacer que salga la misma animación
Uso el IDE Arduino 1.8.9
Librerias:
- MD_MAX72XX by majicDesigns Versión 3.1.0
- MD_Parola by majicDesigns Versión 3.1.1
En cada
"#if ENA_SPRITE
{ PA_SPRITE, "FUERZA", 5, 5 },
#endif"
quiero que salga una animación distinta
Código:
#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>
#include <MD_UISwitch.h>
// Define the number of devices we have in the chain and the hardware interface
// NOTE: These pin numbers will probably not work with your hardware and may
// need to be adapted
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4
#define CLK_PIN 13
#define DATA_PIN 11
#define CS_PIN 10
// Hardware SPI connection
MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);
// Arbitrary output pins
// MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
#define ARRAY_SIZE(x) (sizeof(x)/sizeof(x[0]))
// Global data
struct sCatalog
{
textEffect_t effect; // text effect to display
char * psz; // text string nul terminated
uint16_t speed; // speed multiplier of library default
uint16_t pause; // pause multiplier for library default
};
sCatalog catalog[] =
{
{ PA_PRINT, "DE:", 2, 3 },
{ PA_SCROLL_LEFT, "POPEYE", 8, 0 },
{ PA_PRINT, "PARA:", 2, 3 },
{ PA_SCROLL_DOWN, "OLIVA", 6, 5 },
#if ENA_SPRITE //
{ PA_SPRITE, "FELIZ", 5, 5 },
#endif
{ PA_SCROLL_LEFT, "TODO ES POSIBLE", 7, 0 },
{ PA_SCROLL_LEFT, "", 7, 0 },
{ PA_SCROLL_LEFT, "EXITOS EN TODOS LOS NUEVOS RETOS", 7, 0 },
#if ENA_SPRITE
{ PA_SPRITE, "FUERZA", 5, 5 },
#endif
{ PA_PRINT, "Y", 1, 1 },
#if ENA_SPRITE
{ PA_SPRITE, "FELICES", 5, 5 },
#endif
};// Sprite Definitions
const uint8_t F_PMAN1 = 6;
const uint8_t W_PMAN1 = 8;
static const uint8_t PROGMEM pacman1[F_PMAN1 * W_PMAN1] = // gobbling pacman animation
{
0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
};
const uint8_t F_PMAN2 = 6;
const uint8_t W_PMAN2 = 18;
static const uint8_t PROGMEM pacman2[F_PMAN2 * W_PMAN2] = // ghost pursued by a pacman
{
0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x73, 0xfb, 0x7f, 0xf3, 0x7b, 0xfe,
};
void setup(void)
{
P.begin();
#if ENA_SPRITE
P.setSpriteData(pacman1, W_PMAN1, F_PMAN1, pacman2, W_PMAN2, F_PMAN2);
#endif
for (uint8_t i=0; i<ARRAY_SIZE(catalog); i++)
{
catalog[i].speed *= P.getSpeed();
catalog[i].pause *= 500;
}
}
void loop(void)
{
static textPosition_t just = PA_LEFT;
static uint8_t i = 0;
static uint8_t j = 0;
if (P.displayAnimate()) // animates and returns true when an animation is completed
{
// rotate the justification if needed
if (i == ARRAY_SIZE(catalog))
{
j++;
if (j == 3) j = 0;
switch (j)
{
case 0: just = PA_LEFT; break;
case 1: just = PA_CENTER; break;
case 2: just = PA_RIGHT; break;
}
i = 0; // reset loop index
}
// set up new animation
P.displayText(catalog[i].psz, just, catalog[i].speed, catalog[i].pause, catalog[i].effect, catalog[i].effect);
delay(catalog[i].pause); // wait a while to show the text ...
i++; // ... then set up for next text effect
}
}
Lista de animaciones que quiero agregar con posibilidad de agregar más:
const uint8_t F_PMAN1 = 6;
const uint8_t W_PMAN1 = 8;
const uint8_t PROGMEM pacman1[F_PMAN1 * W_PMAN1] = // gobbling pacman animation
{
0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c,
};
const uint8_t F_PMAN2 = 6;
const uint8_t W_PMAN2 = 18;
const uint8_t PROGMEM pacman2[F_PMAN2 * W_PMAN2] = // ghost pursued by a pacman
{
0x00, 0x81, 0xc3, 0xe7, 0xff, 0x7e, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x3c, 0x7e, 0xff, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x24, 0x66, 0xe7, 0xff, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
0x00, 0x42, 0xe7, 0xe7, 0xff, 0xff, 0x7e, 0x3c, 0x00, 0x00, 0x00, 0xfe, 0x7b, 0xf3, 0x7f, 0xfb, 0x73, 0xfe,
};
const uint8_t F_ROLL1 = 4;
const uint8_t W_ROLL1 = 8;
const uint8_t PROGMEM roll1[F_ROLL1 * W_ROLL1] = // rolling square
{
0xff, 0x8f, 0x8f, 0x8f, 0x81, 0x81, 0x81, 0xff,
0xff, 0xf1, 0xf1, 0xf1, 0x81, 0x81, 0x81, 0xff,
0xff, 0x81, 0x81, 0x81, 0xf1, 0xf1, 0xf1, 0xff,
0xff, 0x81, 0x81, 0x81, 0x8f, 0x8f, 0x8f, 0xff,
};
const uint8_t F_ROLL2 = 4;
const uint8_t W_ROLL2 = 8;
const uint8_t PROGMEM roll2[F_ROLL2 * W_ROLL2] = // rolling octagon
{
0x3c, 0x4e, 0x8f, 0x8f, 0x81, 0x81, 0x42, 0x3c,
0x3c, 0x72, 0xf1, 0xf1, 0x81, 0x81, 0x42, 0x3c,
0x3c, 0x42, 0x81, 0x81, 0xf1, 0xf1, 0x72, 0x3c,
0x3c, 0x42, 0x81, 0x81, 0x8f, 0x8f, 0x4e, 0x3c,
};
const uint8_t F_LINES = 3;
const uint8_t W_LINES = 8;
const uint8_t PROGMEM lines[F_LINES * W_LINES] = // spaced lines
{
0xff, 0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00,
0xff, 0xff, 0x00, 0xff, 0x00, 0x00, 0xff, 0x00,
0xff, 0xff, 0x00, 0x00, 0xff, 0x00, 0x00, 0xff,
};
const uint8_t F_ARROW1 = 3;
const uint8_t W_ARROW1 = 10;
const uint8_t PROGMEM arrow1[F_ARROW1 * W_ARROW1] = // arrow fading to center
{
0x18, 0x3c, 0x7e, 0xff, 0x7e, 0x00, 0x00, 0x3c, 0x00, 0x00,
0x18, 0x3c, 0x7e, 0xff, 0x00, 0x7e, 0x00, 0x00, 0x18, 0x00,
0x18, 0x3c, 0x7e, 0xff, 0x00, 0x00, 0x3c, 0x00, 0x00, 0x18,
};
const uint8_t F_ARROW2 = 3;
const uint8_t W_ARROW2 = 9;
const uint8_t PROGMEM arrow2[F_ARROW2 * W_ARROW2] = // arrow fading to outside
{
0x18, 0x3c, 0x7e, 0xe7, 0x00, 0x00, 0xc3, 0x00, 0x00,
0x18, 0x3c, 0x7e, 0xe7, 0xe7, 0x00, 0x00, 0x81, 0x00,
0x18, 0x3c, 0x7e, 0xe7, 0x00, 0xc3, 0x00, 0x00, 0x81,
};
const uint8_t F_SAILBOAT = 1;
const uint8_t W_SAILBOAT = 11;
const uint8_t PROGMEM sailboat[F_SAILBOAT * W_SAILBOAT] = // sail boat
{
0x10, 0x30, 0x58, 0x94, 0x92, 0x9f, 0x92, 0x94, 0x98, 0x50, 0x30,
};
const uint8_t F_STEAMBOAT = 2;
const uint8_t W_STEAMBOAT = 11;
const uint8_t PROGMEM steamboat[F_STEAMBOAT * W_STEAMBOAT] = // steam boat
{
0x10, 0x30, 0x50, 0x9c, 0x9e, 0x90, 0x91, 0x9c, 0x9d, 0x90, 0x71,
0x10, 0x30, 0x50, 0x9c, 0x9c, 0x91, 0x90, 0x9d, 0x9e, 0x91, 0x70,
};
const uint8_t F_HEART = 5;
const uint8_t W_HEART = 9;
const uint8_t PROGMEM heart[F_HEART * W_HEART] = // beating heart
{
0x0e, 0x11, 0x21, 0x42, 0x84, 0x42, 0x21, 0x11, 0x0e,
0x0e, 0x1f, 0x33, 0x66, 0xcc, 0x66, 0x33, 0x1f, 0x0e,
0x0e, 0x1f, 0x3f, 0x7e, 0xfc, 0x7e, 0x3f, 0x1f, 0x0e,
0x0e, 0x1f, 0x33, 0x66, 0xcc, 0x66, 0x33, 0x1f, 0x0e,
0x0e, 0x11, 0x21, 0x42, 0x84, 0x42, 0x21, 0x11, 0x0e,
};
Soy novato en programar Arduino y lo poco que voy aprendiendo lo hago empíricamente.
Gracias por la ayuda.