Having some code issues

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <FastLED.h>

#define RED_NUM_LEDS_PER_STRIP 161
#define GREEN_NUM_LEDS_PER_STRIP 105
#define BLUE_NUM_LEDS_PER_STRIP 63
#define SIGN_NUM_LEDS 121
#define BRIGHTNESS  128
#define PIN 6


Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(11, 11, PIN,
                            NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
                            NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
                            NEO_GRB            + NEO_KHZ800);
//GRB
const uint16_t colors[] = {
  matrix.Color(0, 255, 0), matrix.Color(255, 0, 0), matrix.Color(0, 0, 255)
};


CRGB redLeds[RED_NUM_LEDS_PER_STRIP];
CRGB greenLeds[GREEN_NUM_LEDS_PER_STRIP];
CRGB blueLeds[BLUE_NUM_LEDS_PER_STRIP];
CRGB signleds[SIGN_NUM_LEDS];

void setup() {
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(200);
  matrix.setTextColor(colors[0]);

  FastLED.addLeds<WS2811, 9>(redLeds, RED_NUM_LEDS_PER_STRIP);

  FastLED.addLeds<WS2811, 8>(greenLeds, GREEN_NUM_LEDS_PER_STRIP);

  FastLED.addLeds<WS2811, 7>(blueLeds, BLUE_NUM_LEDS_PER_STRIP);

  FastLED.addLeds<WS2811, 6>(signleds, SIGN_NUM_LEDS);

  FastLED.setBrightness( BRIGHTNESS );
}

int x    = matrix.width();
int pass = 0;

void sign_text() {
  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  matrix.print(F("Merry christmas"));

  if (--x < -135) {
    x = matrix.width();
    //if(++pass >= 3) pass = 0;
    //matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(80);
}

void led_show_1() {
  for (int i = 0; i < RED_NUM_LEDS_PER_STRIP; i++) {
    redLeds[i] = CRGB::Red;
    FastLED.show();
    delay(30);
  }

  for (int i = 0; i < GREEN_NUM_LEDS_PER_STRIP; i++) {
    greenLeds[i] = CRGB::Green;
    FastLED.show();
    delay(30);
  }

  for (int i = 0; i < BLUE_NUM_LEDS_PER_STRIP; i++) {
    blueLeds[i] = CRGB::Blue;
    FastLED.show();
    delay(30);
  }

  delay(3000);

  for (int i = BLUE_NUM_LEDS_PER_STRIP - 1; i >= 0; i--) {
    blueLeds[i] = CRGB::Blue;
    FastLED.show();
    blueLeds[i] = CRGB::Black;
    delay(30);
  }

  for (int i = GREEN_NUM_LEDS_PER_STRIP - 1; i >= 0; i--) {
    greenLeds[i] = CRGB::Green;
    FastLED.show();
    greenLeds[i] = CRGB::Black;
    delay(30);
  }

  for (int i = RED_NUM_LEDS_PER_STRIP - 1; i >= 0; i--) {
    redLeds[i] = CRGB::Red;
    FastLED.show();
    redLeds[i] = CRGB::Black;
    delay(30);
  }

}


void led_show_2() {

  for (int i = 0; i < 2; i++) {
    fill_solid( redLeds, RED_NUM_LEDS_PER_STRIP, CRGB(64, 0, 0));
    fill_solid( greenLeds, GREEN_NUM_LEDS_PER_STRIP, CRGB(0, 64, 0));
    fill_solid( blueLeds, BLUE_NUM_LEDS_PER_STRIP, CRGB(0, 0, 64));
    FastLED.show();
    delay(1500);
    fill_solid( redLeds, RED_NUM_LEDS_PER_STRIP, CRGB(0, 0, 0));
    fill_solid( greenLeds, GREEN_NUM_LEDS_PER_STRIP, CRGB(0, 0, 0));
    fill_solid( blueLeds, BLUE_NUM_LEDS_PER_STRIP, CRGB(0, 0, 0));
    FastLED.show();
    delay(1500);
  }
}



void loop() {

  sign_text();
  led_show_2();


}


Now sign_text and led show_2 run at the same time, with the letters in the sign_text moves ahead after led_show_2 have run two times.
Stuck in space....

Am I right that you expect things to happen at the same time? Synchronous?
In that case you need timers instead of delay.
Look at many available examples.
Search for 'blink without delay' and 'several things at the same time' (the latter title is basically a lie but who cares...).

10 points for proper code in code tags
Less points for explaining your actual problem

Will attempt to explain a little better.

Want the sign_text to run first, will display in the LED matrix 11x11, when sign_text is finished "printing" text then led_show_2 should run, then from start again.

Ok now it is clear what you want.
But to me it is not clear what you have now...
And what is the problem with what you have...

Ah, I have got it..
You need a for loop instead of an if in your sign_text function.
That way it will finish the whole text and then go to the ledshow...

What does this mean?

In my words:
First character appears
Ledshow
Next character
Ledshow
Next character
Etc.

Op wants:
Show all characters (one after another)
Then ledshow
Repeat

Might be that message gradually shifts left and not by character.

Instead of showing scrolling text first: Merry christmas, it now run at same time and text will appear with delay after led_show_2 run two times.
The message gradually shifts left and not by character..

Will attempt with some testing with timers.

You only need the for loop.

Timers could make this much nicer as it would allow you to have ledshow and moving text simultaneously.

Add a bool that will be true after sign_text completes, then execute led_show upon condition of this bool being true

Solved it, the solution was right in front of my nose....

Elucidate, what was the problem?

Tom... :smiley: :+1: :coffee: :australia:


#include <FastLED.h>
#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#include <arduino-timer.h>

#define RED_NUM_LEDS_PER_STRIP 161
#define GREEN_NUM_LEDS_PER_STRIP 105
#define BLUE_NUM_LEDS_PER_STRIP 63
#define SIGN_NUM_LEDS 121
#define BRIGHTNESS  160
#define PIN 6

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(11, 11, PIN,
                            NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
                            NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
                            NEO_GRB            + NEO_KHZ800);
//GRB
const uint16_t colors[] = {
  matrix.Color(0, 255, 0), matrix.Color(255, 0, 0), matrix.Color(0, 0, 255)
};


CRGB redLeds[RED_NUM_LEDS_PER_STRIP];
CRGB greenLeds[GREEN_NUM_LEDS_PER_STRIP];
CRGB blueLeds[BLUE_NUM_LEDS_PER_STRIP];
CRGB signleds[SIGN_NUM_LEDS];


void setup() {
  // tell FastLED there's 60 NEOPIXEL leds on pin 9
  FastLED.addLeds<WS2811, 9>(redLeds, RED_NUM_LEDS_PER_STRIP);
  FastLED.setBrightness( BRIGHTNESS );

  // tell FastLED there's 60 NEOPIXEL leds on pin 8
  FastLED.addLeds<WS2811, 8>(greenLeds, GREEN_NUM_LEDS_PER_STRIP);
  FastLED.setBrightness( BRIGHTNESS );

  // tell FastLED there's 60 NEOPIXEL leds on pin 7
  FastLED.addLeds<WS2811, 7>(blueLeds, BLUE_NUM_LEDS_PER_STRIP);
  FastLED.setBrightness( BRIGHTNESS );

  // tell FastLED there's 60 NEOPIXEL leds on pin 6
  FastLED.addLeds<WS2811, 6>(signleds, SIGN_NUM_LEDS);
  FastLED.setBrightness( BRIGHTNESS );

  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(200);
  matrix.setTextColor(colors[0]);

}

int x    = matrix.width();
int pass = 0;
auto timer = timer_create_default();


void led_show_1() {

  for (int i = 0; i < RED_NUM_LEDS_PER_STRIP; i++) {
    redLeds[i] = CRGB::Red;
    FastLED.show();
    delay(30);
  }

  for (int i = 0; i < GREEN_NUM_LEDS_PER_STRIP; i++) {
    greenLeds[i] = CRGB::Green;
    FastLED.show();
    delay(30);
  }

  for (int i = 0; i < BLUE_NUM_LEDS_PER_STRIP; i++) {
    blueLeds[i] = CRGB::Blue;
    FastLED.show();
    delay(30);
  }

  delay(3000);

  for (int i = BLUE_NUM_LEDS_PER_STRIP - 1; i >= 0; i--) {
    blueLeds[i] = CRGB::Blue;
    FastLED.show();
    blueLeds[i] = CRGB::Black;
    delay(30);
  }

  for (int i = GREEN_NUM_LEDS_PER_STRIP - 1; i >= 0; i--) {
    greenLeds[i] = CRGB::Green;
    FastLED.show();
    greenLeds[i] = CRGB::Black;
    delay(30);
  }

  for (int i = RED_NUM_LEDS_PER_STRIP - 1; i >= 0; i--) {
    redLeds[i] = CRGB::Red;
    FastLED.show();
    redLeds[i] = CRGB::Black;
    delay(30);
  }

  delay(250);
}



void led_show_2() {
  for (int i = 0; i < 3; i++) {
    fill_solid( redLeds, RED_NUM_LEDS_PER_STRIP, CRGB(64, 0, 0));
    fill_solid( greenLeds, GREEN_NUM_LEDS_PER_STRIP, CRGB(0, 64, 0));
    fill_solid( blueLeds, BLUE_NUM_LEDS_PER_STRIP, CRGB(0, 0, 64));
    FastLED.show();
    delay(1500);
    fill_solid( redLeds, RED_NUM_LEDS_PER_STRIP, CRGB(0, 0, 0));
    fill_solid( greenLeds, GREEN_NUM_LEDS_PER_STRIP, CRGB(0, 0, 0));
    fill_solid( blueLeds, BLUE_NUM_LEDS_PER_STRIP, CRGB(0, 0, 0));
    FastLED.show();
    delay(1500);
  }

}


void loop() {

  matrix.fillScreen(0);
  matrix.setCursor(x, 0);
  matrix.print(F("Merry Christmas"));
  if (--x < -135) {
    x = matrix.width();
    if (++pass >= 3) pass = 0;
    matrix.setTextColor(colors[pass]);
  }
  matrix.show();
  delay(100);

  if (--x < -135) {

    led_show_1();
    led_show_2();
  };

}

Problem was when "Merry Christmas" was scrolling first time at run, but when led_show_1 and led_show_2 startet, "Merry Christmas" was also running, but the the was gradually moving after led_show_1 and led_show_2 had run.

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