immediate text change with button help

so i have been working on this project (led marquee fanny pack for my wife) and cant seem to get it figured out and would love to get some coding help i am very very new to this and only have until 5/15/17 to make this work

i have a ws2812b matrix 24w x 7h starting in top left serpentine layout which i can get to scroll text.

what i am trying to accomplish is be able to change the message at any time by pressing the button currently it will only change messaged if i catch it at the right time at the end of the current cycle.

below is my full code and i would love some help in getting it right and working as desired.

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

// MATRIX DECLARATION:
// Parameter 1 = width of NeoPixel matrix
// Parameter 2 = height of matrix
// Parameter 3 = pin number (most are valid)
// Parameter 4 = matrix layout flags, add together as needed:
//   NEO_MATRIX_TOP, NEO_MATRIX_BOTTOM, NEO_MATRIX_LEFT, NEO_MATRIX_RIGHT:
//     Position of the FIRST LED in the matrix; pick two, e.g.
//     NEO_MATRIX_TOP + NEO_MATRIX_LEFT for the top-left corner.
//   NEO_MATRIX_ROWS, NEO_MATRIX_COLUMNS: LEDs are arranged in horizontal
//     rows or in vertical columns, respectively; pick one or the other.
//   NEO_MATRIX_PROGRESSIVE, NEO_MATRIX_ZIGZAG: all rows/columns proceed
//     in the same order, or alternate lines reverse direction; pick one.
//   See example below for these values in action.
// Parameter 5 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)

int matrixW = 24;
int matrixH = 7;
#define PIN 1 // OUTPUT PIN FROM ARDUINO TO MATRIX D-In
#define BUTTON_PIN 2


Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(matrixW, matrixH, PIN,
                            NEO_MATRIX_TOP     + NEO_MATRIX_LEFT +
                            NEO_MATRIX_ROWS + NEO_MATRIX_ZIGZAG,
                            NEO_GRB            + NEO_KHZ800);

bool oldState = HIGH;
int showType = 0;


const uint16_t colors[] = {
  matrix.Color(255, 0, 0), matrix.Color(0, 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)
};


#define arr_len( x )  ( sizeof( x ) / sizeof( *x ) ) // Calculation of Array Size;


int pixelPerChar = 5; // Width of Standard Font Characters is 8X6 Pixels
int x = matrix.width(); // Width of the Display
int pass = 0; // Counter
int i = 0; // Counter
int clr = 0; // Counter for Indexing Array of Colors

char msg[] = "-------------------"; // BLANK Message of Your Choice;


void setup() {
  pinMode(BUTTON_PIN, INPUT_PULLUP);
  matrix.begin();
  matrix.setTextWrap(false);
  matrix.setBrightness(5);
  matrix.setTextColor(colors[0]);
  matrix.show();
}


void loop() {
  // Get current button state.
  bool newState = digitalRead(BUTTON_PIN);

  // Check if state changed from high to low (button press).
  if (newState == LOW && oldState == HIGH) {
    // Short delay to debounce button.
    delay(20);
    // Check if button is still low after debounce.
    newState = digitalRead(BUTTON_PIN);
    if (newState == LOW) {
      showType++;
      if (showType > 2)
        showType = 0;
        startShow(showType);
   }

  }

startShow(showType);
  // Set the last button state to the old state.
  oldState = newState;
}


void startShow(int i) {
  switch (i) {
    case 0: Text();
      break;
    case 1: Text1();
      break;
    case 2: Text2();
      break;
  }

}

void Text() {
  writeText("Happy");
}

void Text1() {
  writeText("Sad");
}

void Text2() {
  writeText("Fine"); // SCROLLING Message of Your Choice;
}


void writeText(String msg) {
  int arrSize = arr_len( colors ); // Array of Text Colors;
  int msgSize = (msg.length() * pixelPerChar) + (2 * pixelPerChar); // CACULATE message length;
  int scrollingMax = (msgSize) + matrix.width(); // ADJUST Displacement for message length;

  x = matrix.width(); // RESET Cursor Position and Start Text String at New Position on the Far Right;
  clr = 0; // RESET Color/Repeat Index;

  while (clr <= arrSize) {
    /* Change Color with Each Pass of Complete Message */
    matrix.setTextColor(colors[clr]);

    matrix.fillScreen(0); // BLANK the Entire Screen;
    matrix.setCursor(x, 0); // Set Starting Point for Text String;
    matrix.print(msg); // Set the Message String;

    /* SCROLL TEXT FROM RIGHT TO LEFT BY MOVING THE CURSOR POSITION */
    if (--x < -scrollingMax ) {
      /*  ADJUST FOR MESSAGE LENGTH  */
      // Decrement x by One AND Compare New Value of x to -scrollingMax;
      // This Animates (moves) the text by one pixel to the Left;

      x = matrix.width(); // After Scrolling by scrollingMax pixels, RESET Cursor Position and Start String at New Position on the Far Right;
      ++clr; // INCREMENT COLOR/REPEAT LOOP COUNTER AFTER MESSAGE COMPLETED;
    }
    matrix.show(); // DISPLAY the Text/Image
    delay(30); // SPEED OF SCROLLING or FRAME RATE;
  }
  clr = 0; // Reset Color/Loop Counter;
}

Give this a try:

  while (clr <= arrSize && digitalRead(BUTTON_PIN) == HIGH) {

This is an international forum and

led marquee fanny pack for my wife

Means something altogether much more adult in English English.

vajazzLED?

PaulRB:
vajazzLED?

Yes but where is the battery to go?

Since you're using a library to do what you do so far, it may be more involved to make a button interrupt the sequence at any time. I'm imagining having to edit the library code and add in more frequent checks on the state of your button in order to respond to it in the midst of carrying out those blocks of code within the library.

Quick and dirty way- make the button hardware reset the whole shebang. Keep a counter variable stored in eeprom. Every startup, it will do the next message and cycle that counter variable.

Grumpy_Mike:
This is an international forum andMeans something altogether much more adult in English English.

I knew somebody was going to say that.

Unfortunately, that's what these things are called in the USA. Otherwise, people don't know what you are talking about.

What are these things called in the UK?

.

I knew somebody was going to say that.

Hey never give up on a feed line.

I remember at work one large meeting of my team with a big boss from another part of the organisation. He started by saying:- "Does anyone know who I am?" - I couldn't resist replying by saying "Why? Can't you remember". My immediate manager later described this as a career shortening remark, but it was a once in a lifetime opportunity. :slight_smile:

What are these things called in the UK?

Well I have no idea what the "marquee" bit means but I would hazard a guess at the rest as "bum bag". With any luck it should sound appalling to you.

I've heard the term marquee used to refer to chasing flashing lights before. One of the demo effects in either the AdaFruit or fastLED libraries is described as that.

"bum" is yet another word that has a confusingly different meaning between UK and US!

Anyway, where is the OP? I want to know if my suggested code change helped.