Problème d'affichage de police scrolle Texte Rainbow

Hello friends, my problem is that the display on a 7x42 matrix is not correct 
or there is an error in the code that I cannot locate the error. 
Thank you all & Happy New Year here is the link of the code https://justinnelsonsprojects.com/arduino/scrolly.zip

here is the project link
https://www.youtube.com/watch?v=HCQNyJWnmEA

#include "FastLED.h"
#include "fontstuff.h"	//https://github.com/ChuckM/bb-lcd/blob/master/font-5x7.c
#include "printfunctions.h"
#include <EEPROM.h>
#include <stdio.h>
#include <string.h>
// How many leds in your strip?
#define NUM_LEDS 295
#define DATA_PIN 8
#define Brightness 240
// Define the array of leds
CRGB leds[NUM_LEDS];
CRGB tmpleds[295];
//
char newText[128] = {0};
char theText[128] = {0};
int theStyle = 0;
int theColor = 1;
int busy = 0;
//
// For "random" fades:
int rndorder[NUM_LEDS] = {0};
int rsort(const void *a, const void *b) {
  return random(0,2);
}
//#####################################################
void setup() { 
  // Set up our dot matrix:
  int i;
  // Our matrix is zig-zagged bottom to top, starting
  // right-to-left :)
  // So each of 7 rows of 42 alternate direction.......
  for(i=0;i<42;i++) {
    matrix[0][i]   = 294 - i;// Top row    == 294 - 253
    matrix[1][i]   = 211 + i;// Second row == 211 - 252
    matrix[2][i]   = 210 - i;// Third row  == 169 - 210
    matrix[3][i]   = 127 + i;// Forth row  == 127 - 168
    matrix[4][i]   = 126 - i;// Fifth row  == 85  - 126
    matrix[5][i]   =  43 + i;// Sixth row  == 43  -  84
    matrix[6][i]   =  42 - i;// Last row   == 42  -   1
  }
  for(i=1;i<NUM_LEDS;i++) rndorder[i] = i;
  qsort(rndorder + 1, NUM_LEDS-1, sizeof(int), rsort);
  FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
  // Go blank while we get connected:
  //FastLED.setMaxPowerInVoltsAndMilliamps(5, 1800);
  FastLED.setCorrection(0xFF7F4F);
  FastLED.clear(true);
  FastLED.setBrightness(Brightness);
}
//
void loop() { 
  mPrint("Scrolling Texte", 7);delay(1000);
  mPrintHScroll("Bonjour Tous le monde", 4, 10, 1);delay(1000);
  mPrintVScroll("Matrix led 5x7", 2, 0, 0, 1);delay(1500);
}
//
void mPrint(char *inText, int color, int hOffset, int vOffset, int fadein, unsigned long bgcolor) {
  int n = 0;
  int rb = 0; // Rainbow
  int rc = 0; // Random Color
  int r, g, b;
  char *txt;
  int len = strlen(inText);
  if (len < 7) {
    txt = (char *) malloc(8);
    strcpy(txt, inText);
    while (len < 7) txt[len++] = ' ';
    txt[len] = 0;
  } else {
    txt = inText;
  }
  if (color <= 0 || color > 8) {
    color = -1;
  } else if (color == 7) {
    rb = 1;
    color = 0;
  } else if (color == 8) {
    rc = 1;
  } else {
    color = (color - 1) * 128;
  }
  // Wipe the buffer!
  if(fadein > 0) memset(tmpleds, 0, NUM_LEDS * sizeof(CRGB));
  while (txt[n]) {
    for (int i = n == 0 ? -1 : 0; i < 6; i++) {
      for (int k = 0; k < 7; k++) {
        // Shit-ton of validation:
        if (i + n * 6 + hOffset < 42 &&
            i + n * 6 + hOffset >= 0 &&
            k + vOffset >= 0 &&
            k + vOffset < 7) {
          if (i >= 0 && FONT_BIT((int)txt[n], i, 7 - k)) {
            // Trying something different (and maybe cool!):
            if (rc) color = random(0, 768);
            if (color == -1 && !rb) {
              r = g = b = 85;
            } else {
              r = (color + 255) % 768;
              if (r > 511) r = 0;
              if (r > 255) r = 511 - r;
              g = (color +   0) % 768;
              if (g > 511) g = 0;
              if (g > 255) g = 511 - g;
              b = (color + 511) % 768;
              if (b > 511) b = 0;
              if (b > 255) b = 511 - b;
            }
          } else {
            r = (bgcolor >> 16) & 0xFF;
            g = (bgcolor >>  8) & 0xFF;
            b = bgcolor & 0xFF;
          }
          if (fadein > 0) {
            tmpleds[matrix[k + vOffset][i + n * 6 + hOffset]].r = r;
            tmpleds[matrix[k + vOffset][i + n * 6 + hOffset]].g = g;
            tmpleds[matrix[k + vOffset][i + n * 6 + hOffset]].b = b;
          } else {
            leds[matrix[k + vOffset][i + n * 6 + hOffset]].r = r;
            leds[matrix[k + vOffset][i + n * 6 + hOffset]].g = g;
            leds[matrix[k + vOffset][i + n * 6 + hOffset]].b = b;
          }
        }
      }
      if (rb) color += 16;
    }
    n++;
  }
  if (fadein == 2) {
    // Re-sort (randomize) the random numbers each time:
    qsort(rndorder + 1, 294, sizeof(int), rsort);
    for (int f = 1; f < NUM_LEDS; f++) {
      leds[rndorder[f]].r = tmpleds[rndorder[f]].r;
      leds[rndorder[f]].g = tmpleds[rndorder[f]].g;
      leds[rndorder[f]].b = tmpleds[rndorder[f]].b;
      if (f % 8 == 0) {
        FastLED.show();
        delay(5);
      }
    }
    memcpy(leds, tmpleds, NUM_LEDS * sizeof(CRGB));
  } else if (fadein == 1) {
    // Crossfade:
    for (int i = 0; i < 30; i++) {
      for (int f = 1; f < NUM_LEDS; f++) {
        leds[f].r = leds[f].r * 7 / 8 + tmpleds[f].r / 8;
        leds[f].g = leds[f].g * 7 / 8 + tmpleds[f].g / 8;
        leds[f].b = leds[f].b * 7 / 8 + tmpleds[f].b / 8;
      }
      FastLED.show();
      delay(20);
    }
    memcpy(leds, tmpleds, NUM_LEDS * sizeof(CRGB));
  }
  FastLED.show();
}
//#####################################################
void mPrintHScroll(char *txt, int color, int dtime, int onscreen, int fadein, int blinkout, unsigned long bgcolor) {
  int i;
  int len = strlen(txt);
  int st, en;
  if (onscreen == 0 || onscreen > 2) {
    st = 42;
    en = len * 6;
    fadein = 0;
    blinkout = 0;
  } else if (onscreen == 1) {
    // Start off screen, end at last 7 chars:
    st = 42;
    en = len * 6 - 42;
    fadein = 0;
  } else if (onscreen == 2) {
    // Start on screen, end on screen
    st = 0;
    en = len * 6 - 42;
  }
  mPrint(txt, color, st, 0, fadein, bgcolor);
  if (!fadein && onscreen == 2) delay(500);
  // Deal with leading spaces at the end:
  while(onscreen > 0 && len > en/6 && txt[en/6] == ' ') en += 6;
  for (i = st - 1; i > -en; i--) {
    mPrint(txt, color, i, 0, 0, bgcolor);
    delay(dtime);
  }
  // Blink:
  if (blinkout) {
    for (int k = 0; k < 4; k++) {
      delay(250);
      FastLED.clear(true);
      delay(250);
      mPrint(txt, color, i, 0, 0, bgcolor);
    }
  } else if (onscreen == 0) {
    FastLED.clear(true);
  }
}
//#####################################################
void mPrintVScroll(char *inText, int color, int down, int dtime, int stayon, unsigned long bgcolor) {
  int i, f;
  char txt[8] = {0};
  int len = strlen(inText);
  if (len > 7) len = 7;
  strncpy(txt, inText, len);
  // Space pad:
  while (len < 7) {
    txt[len] = ' ';
    txt[++len] = 0;
  }
  if (down > 0) {
    for (i = -7; i <= 0; i++) {
      // First shift up existing dots:
      for(f = NUM_LEDS-43; f > 42; f--) {
        leds[matrix[f/42][f%42]] = leds[matrix[f/42-1][f%42]];
      }
      for(;f>=0;f--) {leds[matrix[f/42][f%42]] = 0;}
      mPrint(txt, color, 0, i, 0, bgcolor);
      delay(40);
    }
    if (stayon == 0) {
      if (dtime) delay(dtime);
      for (i = 1; i < 7; i++) {
        FastLED.clear();
        mPrint(txt, color, 0, i, 0, bgcolor);
        delay(40);
      }
    }
  } else {
    for (i = 7; i >= 0; i--) {
      // First shift up existing dots:
      for(f = 0; f < NUM_LEDS-43; f++) {
        leds[matrix[f/42][f%42]] = leds[matrix[f/42+1][f%42]];
      }
      for(;f<NUM_LEDS-1;f++) {leds[matrix[f/42][f%42]] = 0;}
      mPrint(txt, color, 0, i, 0, bgcolor);
      delay(40);
    }
    if (stayon == 0) {
      if (dtime) delay(dtime);
      for (i = -1; i > -7; i--) {
        FastLED.clear();
        mPrint(txt, color, 0, i, 0, bgcolor);
        delay(40);
      }
    }
  }
  if (stayon == 0) FastLED.clear(true);
}

Bonjour @HannahiSamir

:raised_hand: Un petit détour s'impose pour découvrir comment présenter sa demande d'aide et en particulier comment poster le code :

A par que ton code n'est pas indenté, sinon il me parait sympa :slight_smile:

Bonsoir

Après le code il manque une description du problème rencontré et une description du montage, toutes informations demandées dans les 'Bonnes Pratique du Forum Francophone' déjà cité.

1 Like

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