Animations with max7219 led and md_parola

Hello, I am doing a job which consists of recognizing hand positions with the help of 2.2" flex sensors, to recognize the language of deaf-mute people, letter by letter until forming a word. To show this word I am using a MAX 7219 LED matrix , with the MD_Parola library, I cannot show animations for which I was using P.displayText() and each of the parameters. Additionally, I discovered that P.displayAnimate() must be used, before an animation within an if(), since this returns a true or false value, but so far I can't achieve anything with it and I only get bugs, what could I be doing wrong? If anyone knows about the subject, please comment with help or solutions on the matter, I have been investigating, but I can't find the solution. Thank you.

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4

#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

#define BUTTON_PIN 8 // Pin donde está conectado el botón

MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

int pulgar = A0;
int indice = A1;
int medio = A2;
int anular = A3;
int menique = A4;

// Variable para almacenar la palabra formada
String palabra = "";

// Función para reconocer letras a partir de los valores de los sensores flex
char reconocerLetra(int valor1, int valor2, int valor3, int valor4, int valor5) {
  // Definir rangos de valores para cada letra (ajustar según tus sensores)
  if (valor1 <= 640 && valor2 >= 545 && valor3 >= 820 && valor4 >= 510 && valor5 >= 500) {
    Serial.println("IMPRIME A");
    return 'A';
  } else if (valor1 >= 800 && valor2 <= 400 && valor3 >= 700 && valor4 <= 380 && valor5 <= 350) {
    Serial.println("IMPRIME B");
    return 'B';
  } else if (valor1 >= 800 && valor2 >= 500 && valor3 >= 800 && valor4 <= 500 && valor5 <= 500) {
    Serial.println("IMPRIME C");
    return 'C';
  }// ... (Añadir rangos para otras letras)
  else {
    return ' '; // Letra no reconocida
  }
}

// Función para mostrar la palabra en la pantalla
void mostrarPalabra(String palabra) {
  Serial.println("ENTRANDO A PALABRA");
  // Limpiar la pantalla
  P.displayClear();

  // Mostrar la palabra con los parámetros especificados
  P.displayText(palabra.c_str(), PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}

void mostrarLetra(char letra) {
  Serial.println("ENTRANDO EN MOSTRAR LETRA");
  // Limpiar la pantalla
  P.displayClear();

  // Mostrar la letra con los parámetros especificados
  P.displayText(letra, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);

  // Mostrar la letra durante 1 segundo
  delay(1000);

  // Limpiar la pantalla
  P.displayClear();

}

// Función para detectar la pulsación del botón
bool botonPresionado() {
  // Leer el estado del pin del botón
  int estadoBoton = digitalRead(BUTTON_PIN);

  // Si el botón está presionado (LOW), retornar true
  if (estadoBoton == LOW) {
    Serial.println("BOTON PRESIONADO");
    return true;
  }

  // Si el botón no está presionado (HIGH), retornar false
  return false;
}

void mostrarBienvenida() {
  Serial.println("ENTRANDO A BIENVENIDA");
  // Limpiar la pantalla
  P.displayClear();

  // Mostrar el mensaje de bienvenida
  if(P.displayAnimate()){
    P.displayText("BIENVENIDOS", PA_LEFT, 50, 1000, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  }

  // Esperar 2 segundos
  delay(2000);
}

void mostrarGuionesEspera() {
  Serial.println("ENTRANDO A GUIONES");
  // Limpiar la pantalla
  P.displayClear();

  // Mostrar la cadena de guiones
  P.displayText("---", PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
}

void setup() {
  Serial.begin(9600);
  
  // Definir pines
  pinMode(BUTTON_PIN, INPUT_PULLUP);

  //Inicializar Pantalla
  P.begin();
  P.displayClear();
  
  // Mostrar mensaje de bienvenida
  mostrarBienvenida();
}

void loop() {
  // Leer valores de los sensores
  int valorPulgar = analogRead(pulgar);
  int valorIndice = analogRead(indice);
  int valorMedio = analogRead(medio);
  int valorAnular = analogRead(anular);
  int valorMenique = analogRead(menique);

  // Reconocer letra
  char letra = reconocerLetra(valorPulgar, valorIndice, valorMedio, valorAnular, valorMenique);

  // Si no se está registrando ninguna letra, mostrar guiones de espera
  if (letra == ' ') {
    mostrarGuionesEspera();
  } else {
    // Mostrar la letra en la pantalla
    mostrarLetra(letra);
  }

  // Agregar letra a la palabra
  if (letra != ' ') {
    palabra += letra;
  }

  // Mostrar la palabra si se presiona el botón
  if (botonPresionado()) {
    mostrarPalabra(palabra);
    Serial.println(palabra);
    // Mostrar la palabra durante 5 segundos
    delay(5000);

    // Limpiar la pantalla
    P.displayClear();

    // Reiniciar la palabra
    palabra = "";
  }
}

Please do not post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

Your topic has been moved.

Thanks for using code tags in your first post :+1:

A part of an animations only happen when you call displayAnimate(). You should put this in your loop() function, like is shown in the example code supplied with the library.

You may find it easier to use P.print() if you just want to show something on the display with no scrolling or animation.

Also make sure that the text string you are giving the librray is fully in scope for the function of the animation. The string is not copied. If you are doing conversions from String then this may not be the case. You also seem to pass a single character for display. This is not possible, it must be a C string (nul terminated character array( to work correctly.

You should eliminate all delay() calls in your code as these will just slow down animations.

I would direct you to the library documentation in the docs subfolder of the MD_Parola folder.

I recently had a little 'pass the time' project doing similar things to what you are attempting here. It was a spin off project for a NTP clock display. It is possible to manipulate single characters with the MD_Parola library.
My approach was to put the characters into a char array, and then each character becomes
null terminated. Like so...

const char *letter [27] = {"SPACE","A","B","C","D","E","F",
                           "G","H","I","J","K","L","M","N",
                           "O","P","Q","R","S","T","U","V",
                           "W","X","Y","Z"};

You just need to refer to each, with an index number and away you go.
I have added some demo code to my project, which you should find useful and give you some ideas
of how to proceed.
Here

Following your advice on using displayAnimate(), I have used it in my showWelcome() function and also inside loop(), however, it did not work for the text animation. I also replaced in my code what I show statically and does not require animation using print(), write().
The point of using these animations is when I want to display large words longer than 5 characters, and I need the text to scroll on the screen so I can read it.
I still can't find the solution, what could I use?

#include <MD_Parola.h>
#include <MD_MAX72xx.h>
#include <SPI.h>

#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
#define MAX_DEVICES 4

#define CLK_PIN   13
#define DATA_PIN  11
#define CS_PIN    10

#define BUTTON_PIN 8 // Pin donde está conectado el botón

MD_Parola P = MD_Parola(HARDWARE_TYPE, CS_PIN, MAX_DEVICES);

int pulgar = A0;
int indice = A1;
int medio = A2;
int anular = A3;
int menique = A4;

// Variable para almacenar la palabra formada
String palabra = "";

// Función para reconocer letras a partir de los valores de los sensores flex
char reconocerLetra(int valor1, int valor2, int valor3, int valor4, int valor5) {
  // Definir rangos de valores para cada letra (ajustar según tus sensores)
  if (valor1 <= 640 && valor2 >= 545 && valor3 >= 820 && valor4 >= 510 && valor5 >= 500) {
    Serial.println("IMPRIME A");
    return 'A';
  } else if (valor1 >= 700 && valor2 <= 395 && valor3 >= 720 && valor4 <= 370 && valor5 <= 340) {
    Serial.println("IMPRIME B");
    return 'B';
  } else if (valor1 >= 778 && valor2 >= 493 && valor3 >= 767 && valor4 <= 449 && valor5 <= 372) {
    Serial.println("IMPRIME C");
    return 'C';
  } else if (valor1 >= 770 && valor2 >= 410 && valor3 >= 830 && valor4 <= 490 && valor5 <= 420) {
    Serial.println("IMPRIME D");
    return 'D';
  } else if (valor1 >= 730 && valor2 >= 520 && valor3 >= 830 && valor4 <= 495 && valor5 <= 510) {
    Serial.println("IMPRIME E");
    return 'E';
  } else if (valor1 >= 716 && valor2 >= 547 && valor3 >= 755 && valor4 <= 380 && valor5 <= 342) {
    Serial.println("IMPRIME F");
    return 'F';
  } else if (valor1 >= 710 && valor2 >= 420 && valor3 >= 820 && valor4 <= 510 && valor5 <= 445) {
    Serial.println("IMPRIME G");
    return 'G';
  
  }// ... (Añadir rangos para otras letras)
  else {
    return ' '; // Letra no reconocida
  }
}

// Función para mostrar la palabra en la pantalla
void mostrarPalabra(String palabra) {
  // Limpiar la pantalla
  P.displayClear();

  // Mostrar la palabra con los parámetros especificados
  P.print(palabra.c_str());
}

void mostrarLetra(char letra) {
  // Limpiar la pantalla
  P.displayClear();

  // Mostrar la letra con los parámetros especificados
  P.write(letra);

  // Mostrar la letra durante 1 segundo
  delay(1000);

  // Limpiar la pantalla
  P.displayClear();

}

// Función para detectar la pulsación del botón
bool botonPresionado() {
  // Leer el estado del pin del botón
  int estadoBoton = digitalRead(BUTTON_PIN);

  // Si el botón está presionado (LOW), retornar true
  if (estadoBoton == LOW) {
    return true;
  }

  // Si el botón no está presionado (HIGH), retornar false
  return false;
}

void mostrarBienvenida() {
  // Limpiar la pantalla
  P.displayClear();

  // Mostrar el mensaje de bienvenida
  if(P.displayAnimate()){
    P.displayText("BIENVENIDOS", PA_LEFT, 50, 1000, PA_SCROLL_LEFT, PA_SCROLL_LEFT);
  }

  // Esperar 2 segundos
  delay(2000);
}

void mostrarGuionesEspera() {
  // Limpiar la pantalla
  P.displayClear();

  // Mostrar la cadena de guiones
  P.print("   ---");
}

void setup() {
  Serial.begin(9600);
  
  // Definir pines
  pinMode(BUTTON_PIN, INPUT_PULLUP);

  //Inicializar Pantalla
  P.begin();
  P.displayClear();
  
  // Mostrar mensaje de bienvenida
  mostrarBienvenida();
}

void loop() {
  // Leer valores de los sensores
  int valorPulgar = analogRead(pulgar);
  int valorIndice = analogRead(indice);
  int valorMedio = analogRead(medio);
  int valorAnular = analogRead(anular);
  int valorMenique = analogRead(menique);

  // Imprimir valores de lectura analógica en la salida Serial
  Serial.print("Pulgar: ");
  Serial.print(valorPulgar);
  Serial.print(", Indice: ");
  Serial.print(valorIndice);
  Serial.print(", Medio: ");
  Serial.print(valorMedio);
  Serial.print(", Anular: ");
  Serial.print(valorAnular);
  Serial.print(", Menique: ");
  Serial.println(valorMenique);

  // Reconocer letra
  char letra = reconocerLetra(valorPulgar, valorIndice, valorMedio, valorAnular, valorMenique);

  // Si no se está registrando ninguna letra, mostrar guiones de espera
  if (letra == ' ') {
    mostrarGuionesEspera();
  } else {
    // Mostrar la letra en la pantalla
    mostrarLetra(letra);
  }

  // Agregar letra a la palabra
  if (letra != ' ') {
    palabra += letra;
  }

  // Mostrar la palabra si se presiona el botón
  if (botonPresionado()) {
    mostrarPalabra(palabra);
    Serial.println(palabra);
    // Mostrar la palabra durante 5 segundos
    delay(5000);

    // Limpiar la pantalla
    P.displayClear();

    // Reiniciar la palabra
    palabra = "";
  }
}

Your code is still wrong and you have noty followed what I said in the previous post.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.