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);
}