Button to run scrollin text on RGB matrix

Hi - I added a button to this code to run a scrolling text sequence on my RGB LED Matrix. I want the scrolling text to start when I push a button (ButtonPIN 9). I allways get this error when I put all the command into a foor loop: “scroll was not declared in this scope”…but the "scroll is declared. The code works untill I put everything that was in the void loop into the button for-loop. Any ideas?

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

#define DATA_PIN 3 //For Matrix
#define arr_len( x ) ( sizeof( x ) / sizeof( *x ) )

#define ButtonPIN 9 // To start seqvence!!!
int ButtonState = 0;

// Matrix setup params
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(17, 8, DATA_PIN,
NEO_MATRIX_LEFT +
NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);

//Matrix
char* Text= {“Dadi Freyr”,“Dadi Freyr”,“Dadi Freyr”,“Dadi Freyr”,“Dadi Freyr”,“Dadi Freyr”};
const uint16_t colors = {
matrix.Color(255, 0, 255), matrix.Color(100, 255, 0), matrix.Color(255, 255, 0),matrix.Color(0, 0, 255), matrix.Color(255, 0, 255), matrix.Color(0, 255, 255), matrix.Color(255, 255, 255)};
int brightness = 80;

int numMode = arr_len(Text)-1;
int numColor = arr_len(colors)-1;
int pixelPerChar = 4;
int maxDisplacement;
int mode = 0;

void setup() {

pinMode(ButtonPIN,INPUT_PULLUP); //SET INPUT FOR Button

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

int y = matrix.height();
int x = matrix.width();
int pass = 0;
int line_pass = 0;

void loop() {

ButtonState = digitalRead(ButtonPIN); //READ BUTTOM PIN

if (ButtonState == 1) //IF I PRESS BUTTON THE FOLLOWING CAMMAND RUNS!

{

if (mode > numMode) { mode = 0; } // if mode greater than numMode reset

matrix.fillScreen(0);
matrix.setCursor(x, 0);
scroll(Text[mode],15);
}

// this does the magic of scrolling
void scroll(char* message,int delays) {
maxDisplacement = strlen(message) * pixelPerChar + matrix.width();
if(++line_pass > matrix.width()) line_pass = 0;
matrix.print(String(message));
if(–x < -maxDisplacement) {
x = matrix.width();
if(++pass >= numColor) { pass = 0; };
matrix.setTextColor(colors[pass]);
mode++;
}
matrix.show();
delay(100);
}

else ()

{}

}

When you post code, use the code tags. Read up about that in the sticky post named How to use this forum, please read.

When you code, periodically auto-format. CTRL-T

This is very handy for finding mismatched curly brackets, which you are suffering from.

Thank you I will...

You have defined the scroll() function inside the loop() function. Hasn't worked for anyone else. Won't work for you.

It works here before I start to add the button to the code…or the for-loop function for the button.

It does not work to move this line " scroll(Text[mode],15); " out of the loop function.

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

#define DATA_PIN 3

#define arr_len( x ) ( sizeof( x ) / sizeof( *x ) )

Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(17, 8, DATA_PIN,
NEO_MATRIX_LEFT +
NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);

char* Text= {“Dadi Freyr”,“Dadi Freyr”,“Dadi Freyr”,“Dadi Freyr”,“Dadi Freyr”,“Dadi Freyr”};
const uint16_t colors = {
matrix.Color(255, 0, 255), matrix.Color(100, 255, 0), matrix.Color(255, 255, 0),matrix.Color(0, 0, 255), matrix.Color(255, 0, 255), matrix.Color(0, 255, 255), matrix.Color(255, 255, 255)};
int brightness = 80;
// End Edit

int numMode = arr_len(Text)-1;
int numColor = arr_len(colors)-1;
int pixelPerChar = 4;
int maxDisplacement;
int mode = 0;

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

int y = matrix.height();
int x = matrix.width();
int pass = 0;
int line_pass = 0;

void loop() {

if (mode > numMode) { mode = 0; }

matrix.fillScreen(0);
matrix.setCursor(x, 0);
scroll(Text[mode],15); //ITS INSIDE THE LOOP FUNTION
}

void scroll(char* message,int delays) {
maxDisplacement = strlen(message) * pixelPerChar + matrix.width();
if(++line_pass > matrix.width()) line_pass = 0;
matrix.print(String(message));
if(–x < -maxDisplacement) {
x = matrix.width();
if(++pass >= numColor) { pass = 0; };
matrix.setTextColor(colors[pass]);
mode++;
}
matrix.show();
delay(100);
}

villivm:
Thank you I will...

So do ! please correct your previous posts.

It works here before I start to add the button to the code

Please post the code that does not work and remember to use code tags when you do as you promised that you would

  matrix.print(String(message));

If the print() method of the class that matrix is an instance of only accepts Strings, find a better class.

What does your code actually do? How does that differ from what you want?