Program skips to the end. How can I fix this?

Hi there. I am new to the Arduino world and looking to teach a short project to my students. I am using an Arduino Uno and AdaFruit NeoPixel Sheild (40 LED’s). The goal is for students to have their name scroll across followed by some flashing lights and repeat. Nothing hard, just an introduction to coding to gain their interest. Here is my code.

#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
// Which pin on the Arduino is connected to the NeoPixels?
#define PIN    6
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(5, 8, PIN,
  NEO_RGB            + NEO_KHZ800);
const uint16_t colors[] = {
  matrix.Color(150, 0, 0), matrix.Color(0, 150, 0), matrix.Color(0, 0, 150) };
void setup() {
int x    = matrix.width();
int pass = 0;
void loop() {
  rainbow(10); // Flowing rainbow cycle along the whole strip


void NAME (int wait) { 
  matrix.setCursor(x, 0);
  if(--x < -36) {
    x = matrix.width();
    if(++pass >= 3) pass = 0;
// Rainbow cycle along whole strip. Pass delay time (in ms) between frames.
void rainbow(int wait) {
  // Hue of first pixel runs 5 complete loops through the color wheel.
  // Color wheel has a range of 65536 but it's OK if we roll over, so
  // just count from 0 to 5*65536. Adding 256 to firstPixelHue each time
  // means we'll make 5*65536/256 = 1280 passes through this outer loop:
  for(long firstPixelHue = 0; firstPixelHue < 5*65536; firstPixelHue += 256) {
    for(int i=0; i<matrix.numPixels(); i++) { // For each pixel in strip...
      // Offset pixel hue by an amount to make one full revolution of the
      // color wheel (range of 65536) along the length of the strip
      // (strip.numPixels() steps):
      int pixelHue = firstPixelHue + (i * 65536L / matrix.numPixels());
      // strip.ColorHSV() can take 1 or 3 arguments: a hue (0 to 65535) or
      // optionally add saturation and value (brightness) (each 0 to 255).
      // Here we're using just the single-argument hue variant. The result
      // is passed through strip.gamma32() to provide 'truer' colors
      // before assigning to each pixel:
      matrix.setPixelColor(i, matrix.gamma32(matrix.ColorHSV(pixelHue)));
    }; // Update strip with new contents
    delay(wait);  // Pause for a moment

The NAME part of the code is skipped over and goes straight to the rainbow part. Any advice on how I can get the Name to show first then the rainbow?

Thanks much.

Karma for using code tags on first post. Most new members do not bother to read the guidelines.

It looks like your 'NAME()' function will scroll "NAME" from off-screen right (x = matrix.width()) to off-screen left (x=-35) but you have to call it matrix.width()+35 times. You only call it once so it only displays once, completely off the right side of the display.