Soucis de scroll sur matrice WS2812

Bonjour à tous.
Nouveau sur le forum, j'en appel à vous pour m'aider (si cela est possible), afin de résoudre un problème, qui est LE dernier détail pour finaliser le projet.
Je suis sur une Matrice WS2812.
Sur un programme séparé, je fais bien défiler le texte. En revanche, avec le LCD et l'encodeur rotatif, le texte est bien affiché, mais ne défile pas.
Mon code se trouve ci-dessous.
D'après vous, ou est l'erreur SVP?

Je me suis basé sur des tutos et exemples trouvé un peu partout, en adaptant à mes besoins (de base, le code trouvé était valable pour le joystick et non l'encodeur rotatif).

Le menu, l'encodeur et les ordres d'affichages fonctionnent parfaitement.
Me reste juste à faire défiler le texte et ce sera good.
Merci à vous

#include <Wire.h>                  
#include <LiquidCrystal.h>     
#include <rotary.h>              
#include <Adafruit_GFX.h>
#include <Adafruit_NeoPixel.h>
#include <Adafruit_NeoMatrix.h>
#ifndef PSTR
#define PSTR
#endif
#define PIN 53
Rotary r = Rotary(34, 32, 30);
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(44, 11, PIN,  NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
int z    = matrix.width();
int pass = 0;
// Infos du menu
int maxNumber = 2; //Nombre de choix
char* matrice_aff[] = {"Ouvert","Ferme",};
int x = 0;
void setup() {
  Serial.begin(9600);
  while (!Serial) {}
  lcd.begin(16, 2);
  lcd.clear (); // go home
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(10);
  matrix.setTextColor(colors[0]);

  blinkLCD();

  char lcdline1[13];
  sprintf (lcdline1, " Ouvert / Ferme ", x + 1); 
  lcd.setCursor(0, 0);
  lcd.print (lcdline1);
  lcd.setCursor(0, 1);
  lcd.print("                ");             
  lcd.setCursor(0, 1);
  lcd.print(matrice_aff[x]);
}

void loop() {
  volatile unsigned char result = r.process();
  if (result) {
    result == DIR_CCW ? x = x - 1 : x = x + 1;

    if (x < 1) {             // no values < 0; later: use unsigned int
      blinkLCD();
      x = maxNumber - 1;    // roll over
    }

    if (x > maxNumber - 1) {           // no more strings
      // ------- Quick 3 blinks of backlight  -------------
      blinkLCD();
      x = 0;                 // roll over
    }

    char lcdline1[13];
    sprintf (lcdline1, " Ouvert / Ferme ", x + 1);
    lcd.setCursor(0, 0);
    lcd.print (lcdline1);
    lcd.setCursor(0, 1);
    lcd.print("                ");              // Suppression du contenu de ligne sur le LCD
    lcd.setCursor(0, 1);
    lcd.print(matrice_aff[x]);

  }

  if (r.buttonPressedReleased(25)) {

    switch (x) {
      case 0:
        lcdScreen1();
        Bandeau_1(); 
        break;                            // changement de l'affichage en OUVERT
      case 1:
        lcdScreen1();
        Bandeau_2();                      // changement de l'affichage en FERME
        break;
    }
    blinkLCD();
    lcd.clear ();
    lcd.print ("Changement :");
    lcd.setCursor(0, 1);
    lcd.print("OK");           
    delay(2000);

    // ------- Quick 3 blinks of backlight  -------------
    blinkLCD();
    x = 0;                                  // reset to start position
    lcd.clear();
    char lcdline1[13];
    sprintf (lcdline1, " Ouvert / Ferme ", x + 1);
    lcd.print (lcdline1);
    lcd.setCursor(0, 1);
    lcd.print(matrice_aff[x]);
  }
}
// ####################   Fonctions ###################

void blinkLCD() {
  for (int i = 0; i < 3; i++)
  {
//    lcd.noBacklight();
    delay(50);
//    lcd.backlight();
    delay(50);
  }
}

void lcdScreen1() {

  lcd.setCursor(0, 0);
  lcd.print("Changement :   ");
  // scroll 13 positions (string length) to the left
  // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 10; positionCounter++) {
    delay(250);
  }

  // scroll 29 positions (string length + display length) to the right
  // to move it offscreen right:
  for (int positionCounter = 0; positionCounter < 20; positionCounter++) {
    delay(250);
  }
}

void Bandeau_1() {
  const uint16_t colors[] = {matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
int z = matrix.width();
int pass = 0;
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(10);
  matrix.setTextColor(colors[1]);
  matrix.fillScreen(0);
  matrix.setCursor(5, 2);
  matrix.print(F("OUVERT"));
  if(--z < -100) {
  z = matrix.width();
  if(++pass >= 3) pass = 10;
  matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(50);
}
void Bandeau_2() {
int z = matrix.width();
int pass = 0;
  const uint16_t colors[] = {matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
  matrix.begin();
  matrix.setTextWrap(true);
  matrix.setBrightness(10);
  matrix.setTextColor(colors[0]);
  matrix.fillScreen(0);
  matrix.setCursor(7, 2);
  matrix.print(F("FERME"));
  if(--z < -200) {
  z = matrix.width();
  if(++pass >= 3) pass = 0;
  matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(50);
}

Essaye d'enlever les lignes suivantes de tes fonctions bandeau :

  matrix.begin();
  matrix.setBrightness(10);

lesept:
Essaye d'enlever les lignes suivantes de tes fonctions bandeau :

  matrix.begin();

matrix.setBrightness(10);

Merci :slight_smile:
Cela ne fonctionne pas non plus.

As-tu essayé sans le LCD ?

lesept:
As-tu essayé sans le LCD ?

Non, je vais tenter.
Mais le menu ne me seras plus accessible...

Bon, ben en désactivant le LCD, c'est tout le code qui fou le camp... grrrrr....

Commente toutes les lignes qui commencent par lcd.

Une remarque : ça

  // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 10; positionCounter++) {
    delay(250);
  }

  // scroll 29 positions (string length + display length) to the right
  // to move it offscreen right:
  for (int positionCounter = 0; positionCounter < 20; positionCounter++) {
    delay(250);
  }

C'est pas terminé ... ?

lesept:
Commente toutes les lignes qui commencent par lcd.

Une remarque : ça

  // to move it offscreen left:

for (int positionCounter = 0; positionCounter < 10; positionCounter++) {
   delay(250);
 }

// scroll 29 positions (string length + display length) to the right
 // to move it offscreen right:
 for (int positionCounter = 0; positionCounter < 20; positionCounter++) {
   delay(250);
 }




C'est pas terminé ... ?

C'est ce que j'ai fait :wink:
Si, enfin me semble.
Aurait-je oublié quelque chose? (Y avais des instruction, mais pas compatible avec mon LCD, donc dans un premier temps désactivées, tests, et supprimées). Par contre si je vire tout ce morceau de code, ça claque le programme par des belles erreurs

Je ne vois pas pourquoi ça provoquerait des erreurs de compilation d'ôter ces lignes puisqu'elles ne font que un délai en boucle.
Attente de 2.5 s :

 // to move it offscreen left:
  for (int positionCounter = 0; positionCounter < 10; positionCounter++) {
    delay(250);
  }

Attente de 5 s :

  // scroll 29 positions (string length + display length) to the right
  // to move it offscreen right:
  for (int positionCounter = 0; positionCounter < 20; positionCounter++) {
    delay(250);
  }

Mais ça ne résout pas ton problème...
Et si tu remets le LCD et que tu enlèves l'encodeur ?

C'est justement un bout de code qui contrôle l'encodeur.
Après, étant un méga gros débutant, ce n'est peut être pas dans l'ordre.
J'ai essayé d'utiliser le joystick à la place de l'encodeur, mais le JS ne marche pas correctement (2 JS, essayés sur 2 Mega 2560 et pas de réponse du "SW")

lesept:
Je ne vois pas pourquoi ça provoquerait des erreurs de compilation d'ôter ces lignes puisqu'elles ne font que un délai en boucle.
Attente de 2.5 s :

 // to move it offscreen left:

for (int positionCounter = 0; positionCounter < 10; positionCounter++) {
   delay(250);
 }




Attente de 5 s :


// scroll 29 positions (string length + display length) to the right
 // to move it offscreen right:
 for (int positionCounter = 0; positionCounter < 20; positionCounter++) {
   delay(250);
 }




Mais ça ne résout pas ton problème...
Et si tu remets le LCD et que tu enlèves l'encodeur ?

Sans encodeur, avec ce code, ça fonctionne (étape 2 du projet avant de tenter un assemblage des codes):

#include "LiquidCrystal.h"
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define PIN 53

const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(44, 11, PIN,  NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800);
 
const uint16_t colors[] = {
  matrix.Color(255, 0, 0), matrix.Color(0, 255, 0), matrix.Color(0, 0, 255) };
int x    = matrix.width();
int pass = 0;
void setup()
{
lcd.begin(16,2);
lcd.print("On avance un peu");
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(10);
  matrix.setTextColor(colors[0]);
}
void loop()
{
  matrix.fillScreen(0);
  matrix.setCursor(x, 2);
  matrix.print(F("TEST AFFICHAGE"));
  if(--x < -100) {
    x = matrix.width();
    if(++pass >= 3) pass = 0;
    matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(50);
}

OK, continue avec le code initial sans les instructions de l'encodeur. Si ça fonctionne, on saura d'où vient le problème

Merci à toi lesept de ton aide :slight_smile:
Je viens de finir de tester. Donc :
Sans le menu LCD mais un simple affichage "TEST" et réglages de la matrice, ça fonctionne.
Je suis en train de voir si il y a pas une erreur dans le code à un moment donné.
J'essaie maintenant d'intégrer le menu + encodeur

Code des SETUPS :

//INCLUDES
#include <rotary.h>             
#include "LiquidCrystal.h"
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define PIN 53

//SETUP ENCODEUR
Rotary r = Rotary(34, 32, 30);

// SETUP LCD : 
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
int columnsLCD = 16;
const char* MenuLine[] = {" OUVERT", " FERME"};
int MenuItems = 2;
int CursorLine = 0;
int fadeAmount = 5;
int x = 0;

//SETUP MATRICE
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(44, 11, PIN,  NEO_MATRIX_TOP + NEO_MATRIX_LEFT + NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG, NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {matrix.Color(255, 0, 0), matrix.Color(0, 255, 0)};
int z    = matrix.width();
int pass = 0;

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