Changing sketch

Great program! Worked perfectly the first time. how do I slow down the part where it shows letters in sequence to spell "arduino."

```
[code]
//We always have to include the library
#include "LedControl.h"

/*
 Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
 pin 12 is connected to the DataIn 
 pin 11 is connected to the CLK 
 pin 10 is connected to LOAD 
 We have only a single MAX72XX.
 */
LedControl lc=LedControl(12,11,10,1);

/* we always wait a bit between updates of the display */
unsigned long delaytime=100;

void setup() {
  /*
   The MAX72XX is in power-saving mode on startup,
   we have to do a wakeup call
   */
  lc.shutdown(0,false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0,8);
  /* and clear the display */
  lc.clearDisplay(0);
}

/*
 This method will display the characters for the
 word "Arduino" one after the other on the matrix. 
 (you need at least 5x7 leds to see the whole chars)
 */
void writeArduinoOnMatrix() {
  /* here is the data for the characters */
  byte a[5]={B01111110,B10001000,B10001000,B10001000,B01111110};
  byte r[5]={B00111110,B00010000,B00100000,B00100000,B00010000};
  byte d[5]={B00011100,B00100010,B00100010,B00010010,B11111110};
  byte u[5]={B00111100,B00000010,B00000010,B00000100,B00111110};
  byte i[5]={B00000000,B00100010,B10111110,B00000010,B00000000};
  byte n[5]={B00111110,B00010000,B00100000,B00100000,B00011110};
  byte o[5]={B00011100,B00100010,B00100010,B00100010,B00011100};

  /* now display them one by one with a small delay */
  lc.setRow(0,0,a[0]);
  lc.setRow(0,1,a[1]);
  lc.setRow(0,2,a[2]);
  lc.setRow(0,3,a[3]);
  lc.setRow(0,4,a[4]);
  delay(delaytime);
  lc.setRow(0,0,r[0]);
  lc.setRow(0,1,r[1]);
  lc.setRow(0,2,r[2]);
  lc.setRow(0,3,r[3]);
  lc.setRow(0,4,r[4]);
  delay(delaytime);
  lc.setRow(0,0,d[0]);
  lc.setRow(0,1,d[1]);
  lc.setRow(0,2,d[2]);
  lc.setRow(0,3,d[3]);
  lc.setRow(0,4,d[4]);
  delay(delaytime);
  lc.setRow(0,0,u[0]);
  lc.setRow(0,1,u[1]);
  lc.setRow(0,2,u[2]);
  lc.setRow(0,3,u[3]);
  lc.setRow(0,4,u[4]);
  delay(delaytime);
  lc.setRow(0,0,i[0]);
  lc.setRow(0,1,i[1]);
  lc.setRow(0,2,i[2]);
  lc.setRow(0,3,i[3]);
  lc.setRow(0,4,i[4]);
  delay(delaytime);
  lc.setRow(0,0,n[0]);
  lc.setRow(0,1,n[1]);
  lc.setRow(0,2,n[2]);
  lc.setRow(0,3,n[3]);
  lc.setRow(0,4,n[4]);
  delay(delaytime);
  lc.setRow(0,0,o[0]);
  lc.setRow(0,1,o[1]);
  lc.setRow(0,2,o[2]);
  lc.setRow(0,3,o[3]);
  lc.setRow(0,4,o[4]);
  delay(delaytime);
  lc.setRow(0,0,0);
  lc.setRow(0,1,0);
  lc.setRow(0,2,0);
  lc.setRow(0,3,0);
  lc.setRow(0,4,0);
  delay(delaytime);
}

/*
  This function lights up a some Leds in a row.
 The pattern will be repeated on every row.
 The pattern will blink along with the row-number.
 row number 4 (index==3) will blink 4 times etc.
 */
void rows() {
  for(int row=0;row<8;row++) {
    delay(delaytime);
    lc.setRow(0,row,B10100000);
    delay(delaytime);
    lc.setRow(0,row,(byte)0);
    for(int i=0;i<row;i++) {
      delay(delaytime);
      lc.setRow(0,row,B10100000);
      delay(delaytime);
      lc.setRow(0,row,(byte)0);
    }
  }
}

/*
  This function lights up a some Leds in a column.
 The pattern will be repeated on every column.
 The pattern will blink along with the column-number.
 column number 4 (index==3) will blink 4 times etc.
 */
void columns() {
  for(int col=0;col<8;col++) {
    delay(delaytime);
    lc.setColumn(0,col,B10100000);
    delay(delaytime);
    lc.setColumn(0,col,(byte)0);
    for(int i=0;i<col;i++) {
      delay(delaytime);
      lc.setColumn(0,col,B10100000);
      delay(delaytime);
      lc.setColumn(0,col,(byte)0);
    }
  }
}

/* 
 This function will light up every Led on the matrix.
 The led will blink along with the row-number.
 row number 4 (index==3) will blink 4 times etc.
 */
void single() {
  for(int row=0;row<8;row++) {
    for(int col=0;col<8;col++) {
      delay(delaytime);
      lc.setLed(0,row,col,true);
      delay(delaytime);
      for(int i=0;i<col;i++) {
        lc.setLed(0,row,col,false);
        delay(delaytime);
        lc.setLed(0,row,col,true);
        delay(delaytime);
      }
    }
  }
}

void loop() { 
  writeArduinoOnMatrix();
  rows();
  columns();
  single();
}
[/code]`Preformatted text`
```

Increase the number 100 here:

unsigned long delaytime=100;

but this will slow down the other animations too.

Being a beginner, you could not know that this is really pretty terrible code. When you understand why, you will no longer be a beginner.

1 Like

Hi @crossbolt

try this code:


//We always have to include the library
#include "LedControl.h"

/*
  Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
  pin 12 is connected to the DataIn
  pin 11 is connected to the CLK
  pin 10 is connected to LOAD
  We have only a single MAX72XX.
*/
LedControl lc = LedControl(12, 11, 10, 1);

/* we always wait a bit between updates of the display */
unsigned long delaytime = 100;

void setup() {
  //Serial.begin(115200);
  /*
    The MAX72XX is in power-saving mode on startup,
    we have to do a wakeup call
  */
  lc.shutdown(0, false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0, 8);
  /* and clear the display */
  lc.clearDisplay(0);
}

void list(byte  *mt)
{
  for (int i = 0; i < 5; i++)
  {
    lc.setRow(0, i, mt[i]);
   // Serial.println(mt[i], BIN);
  }
  delay(delaytime);
}



/*
  This method will display the characters for the
  word "Arduino" one after the other on the matrix.
  (you need at least 5x7 leds to see the whole chars)
*/
void writeArduinoOnMatrix() {
  /* here is the data for the characters */
  byte a[5] = {B01111110, B10001000, B10001000, B10001000, B01111110};
  byte r[5] = {B00111110, B00010000, B00100000, B00100000, B00010000};
  byte d[5] = {B00011100, B00100010, B00100010, B00010010, B11111110};
  byte u[5] = {B00111100, B00000010, B00000010, B00000100, B00111110};
  byte i[5] = {B00000000, B00100010, B10111110, B00000010, B00000000};
  byte n[5] = {B00111110, B00010000, B00100000, B00100000, B00011110};
  byte o[5] = {B00011100, B00100010, B00100010, B00100010, B00011100};

  list(a);
  list(r);
  list(d);
  list(u);
  list(i);
  list(n);
  list(o);


 for (int i = 0; i < 5; i++)
  {
    lc.setRow(0, i, 0);
  }
  delay(delaytime);

  //  /* now display them one by one with a small delay */
  //  lc.setRow(0, 0, a[0]);
  //  lc.setRow(0, 1, a[1]);
  //  lc.setRow(0, 2, a[2]);
  //  lc.setRow(0, 3, a[3]);
  //  lc.setRow(0, 4, a[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, r[0]);
  //  lc.setRow(0, 1, r[1]);
  //  lc.setRow(0, 2, r[2]);
  //  lc.setRow(0, 3, r[3]);
  //  lc.setRow(0, 4, r[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, d[0]);
  //  lc.setRow(0, 1, d[1]);
  //  lc.setRow(0, 2, d[2]);
  //  lc.setRow(0, 3, d[3]);
  //  lc.setRow(0, 4, d[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, u[0]);
  //  lc.setRow(0, 1, u[1]);
  //  lc.setRow(0, 2, u[2]);
  //  lc.setRow(0, 3, u[3]);
  //  lc.setRow(0, 4, u[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, i[0]);
  //  lc.setRow(0, 1, i[1]);
  //  lc.setRow(0, 2, i[2]);
  //  lc.setRow(0, 3, i[3]);
  //  lc.setRow(0, 4, i[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, n[0]);
  //  lc.setRow(0, 1, n[1]);
  //  lc.setRow(0, 2, n[2]);
  //  lc.setRow(0, 3, n[3]);
  //  lc.setRow(0, 4, n[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, o[0]);
  //  lc.setRow(0, 1, o[1]);
  //  lc.setRow(0, 2, o[2]);
  //  lc.setRow(0, 3, o[3]);
  //  lc.setRow(0, 4, o[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, 0);
  //  lc.setRow(0, 1, 0);
  //  lc.setRow(0, 2, 0);
  //  lc.setRow(0, 3, 0);
  //  lc.setRow(0, 4, 0);
  //  delay(delaytime);
}

/*
  This function lights up a some Leds in a row.
  The pattern will be repeated on every row.
  The pattern will blink along with the row-number.
  row number 4 (index==3) will blink 4 times etc.
*/
void rows() {
  for (int row = 0; row < 8; row++) {
    delay(delaytime);
    lc.setRow(0, row, B10100000);
    delay(delaytime);
    lc.setRow(0, row, (byte)0);
    for (int i = 0; i < row; i++) {
      delay(delaytime);
      lc.setRow(0, row, B10100000);
      delay(delaytime);
      lc.setRow(0, row, (byte)0);
    }
  }
}

/*
  This function lights up a some Leds in a column.
  The pattern will be repeated on every column.
  The pattern will blink along with the column-number.
  column number 4 (index==3) will blink 4 times etc.
*/
void columns() {
  for (int col = 0; col < 8; col++) {
    delay(delaytime);
    lc.setColumn(0, col, B10100000);
    delay(delaytime);
    lc.setColumn(0, col, (byte)0);
    for (int i = 0; i < col; i++) {
      delay(delaytime);
      lc.setColumn(0, col, B10100000);
      delay(delaytime);
      lc.setColumn(0, col, (byte)0);
    }
  }
}

/*
  This function will light up every Led on the matrix.
  The led will blink along with the row-number.
  row number 4 (index==3) will blink 4 times etc.
*/
void single() {
  for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
      delay(delaytime);
      lc.setLed(0, row, col, true);
      delay(delaytime);
      for (int i = 0; i < col; i++) {
        lc.setLed(0, row, col, false);
        delay(delaytime);
        lc.setLed(0, row, col, true);
        delay(delaytime);
      }
    }
  }
}

void loop() {
  writeArduinoOnMatrix();
  rows();
  columns();
  single();
}

Nice job, @ruilviana ! I could not resist to add a Serial display of the characters (including a separate delay variable for list() :wink:

//We always have to include the library
#include "LedControl.h"

/*
  Now we need a LedControl to work with.
 ***** These pin numbers will probably not work with your hardware *****
  pin 12 is connected to the DataIn
  pin 11 is connected to the CLK
  pin 10 is connected to LOAD
  We have only a single MAX72XX.
*/
LedControl lc = LedControl(12, 11, 10, 1);

/* we always wait a bit between updates of the display */
unsigned long delaytime = 100;




void setup() {
  Serial.begin(115200);
  /*
    The MAX72XX is in power-saving mode on startup,
    we have to do a wakeup call
  */
  lc.shutdown(0, false);
  /* Set the brightness to a medium values */
  lc.setIntensity(0, 8);
  /* and clear the display */
  lc.clearDisplay(0);
}

/* 
 *  Some ammendments just for the fun of it
 *  Using Serial to print the characters  
 *  in sequence
 *    
 */

unsigned long listDelay = 1000;
byte CharacterUpright[8];  

void PrintCharacterUpright(){
    for (int i = 0; i < 8;i++){
      for (int j = 7; j >= 0;j--) {
        Serial.print(bitRead(CharacterUpright[i],j)? "X" : " ");
      };
     Serial.println();  
    }  
  }

void InsertBitsUpright(byte b,byte col){
    for (int j = 0; j < 8;j++) { 
      if (bitRead(b,j)) {bitSet(CharacterUpright[7-j],4-col); }
                  else  {bitClear(CharacterUpright[7-j],4-col); }
    } 
 }

void list(byte  *mt)
{
  for (int i = 0; i < 5; i++)
  {
    lc.setRow(0, i, mt[i]);
    InsertBitsUpright(mt[i],i);  // Set the appropriate bits in CharacterUpright[]
  }
  PrintCharacterUpright();       // Print the character to Serial 
  delay(listDelay);
}


/*
  This method will display the characters for the
  word "Arduino" one after the other on the matrix.
  (you need at least 5x7 leds to see the whole chars)
*/
void writeArduinoOnMatrix() {
  /* here is the data for the characters */
  byte a[5] = {B01111110, B10001000, B10001000, B10001000, B01111110};
  byte r[5] = {B00111110, B00010000, B00100000, B00100000, B00010000};
  byte d[5] = {B00011100, B00100010, B00100010, B00010010, B11111110};
  byte u[5] = {B00111100, B00000010, B00000010, B00000100, B00111110};
  byte i[5] = {B00000000, B00100010, B10111110, B00000010, B00000000};
  byte n[5] = {B00111110, B00010000, B00100000, B00100000, B00011110};
  byte o[5] = {B00011100, B00100010, B00100010, B00100010, B00011100};
  
  list(a);
  list(r);
  list(d);
  list(u);
  list(i);
  list(n);
  list(o);

  //  /* now display them one by one with a small delay */
  //  lc.setRow(0, 0, a[0]);
  //  lc.setRow(0, 1, a[1]);
  //  lc.setRow(0, 2, a[2]);
  //  lc.setRow(0, 3, a[3]);
  //  lc.setRow(0, 4, a[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, r[0]);
  //  lc.setRow(0, 1, r[1]);
  //  lc.setRow(0, 2, r[2]);
  //  lc.setRow(0, 3, r[3]);
  //  lc.setRow(0, 4, r[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, d[0]);
  //  lc.setRow(0, 1, d[1]);
  //  lc.setRow(0, 2, d[2]);
  //  lc.setRow(0, 3, d[3]);
  //  lc.setRow(0, 4, d[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, u[0]);
  //  lc.setRow(0, 1, u[1]);
  //  lc.setRow(0, 2, u[2]);
  //  lc.setRow(0, 3, u[3]);
  //  lc.setRow(0, 4, u[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, i[0]);
  //  lc.setRow(0, 1, i[1]);
  //  lc.setRow(0, 2, i[2]);
  //  lc.setRow(0, 3, i[3]);
  //  lc.setRow(0, 4, i[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, n[0]);
  //  lc.setRow(0, 1, n[1]);
  //  lc.setRow(0, 2, n[2]);
  //  lc.setRow(0, 3, n[3]);
  //  lc.setRow(0, 4, n[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, o[0]);
  //  lc.setRow(0, 1, o[1]);
  //  lc.setRow(0, 2, o[2]);
  //  lc.setRow(0, 3, o[3]);
  //  lc.setRow(0, 4, o[4]);
  //  delay(delaytime);
  //  lc.setRow(0, 0, 0);
  //  lc.setRow(0, 1, 0);
  //  lc.setRow(0, 2, 0);
  //  lc.setRow(0, 3, 0);
  //  lc.setRow(0, 4, 0);
  //  delay(delaytime);
}

/*
  This function lights up a some Leds in a row.
  The pattern will be repeated on every row.
  The pattern will blink along with the row-number.
  row number 4 (index==3) will blink 4 times etc.
*/
void rows() {
  for (int row = 0; row < 8; row++) {
    delay(delaytime);
    lc.setRow(0, row, B10100000);
    delay(delaytime);
    lc.setRow(0, row, (byte)0);
    for (int i = 0; i < row; i++) {
      delay(delaytime);
      lc.setRow(0, row, B10100000);
      delay(delaytime);
      lc.setRow(0, row, (byte)0);
    }
  }
}

/*
  This function lights up a some Leds in a column.
  The pattern will be repeated on every column.
  The pattern will blink along with the column-number.
  column number 4 (index==3) will blink 4 times etc.
*/
void columns() {
  for (int col = 0; col < 8; col++) {
    delay(delaytime);
    lc.setColumn(0, col, B10100000);
    delay(delaytime);
    lc.setColumn(0, col, (byte)0);
    for (int i = 0; i < col; i++) {
      delay(delaytime);
      lc.setColumn(0, col, B10100000);
      delay(delaytime);
      lc.setColumn(0, col, (byte)0);
    }
  }
}

/*
  This function will light up every Led on the matrix.
  The led will blink along with the row-number.
  row number 4 (index==3) will blink 4 times etc.
*/
void single() {
  for (int row = 0; row < 8; row++) {
    for (int col = 0; col < 8; col++) {
      delay(delaytime);
      lc.setLed(0, row, col, true);
      delay(delaytime);
      for (int i = 0; i < col; i++) {
        lc.setLed(0, row, col, false);
        delay(delaytime);
        lc.setLed(0, row, col, true);
        delay(delaytime);
      }
    }
  }
}

void loop() {
  writeArduinoOnMatrix();
  rows();
  columns();
  single();
}

PaulRB, Thank you for the tip on time. Will try soonest.
Yes, I am a beginner. Also an experienced flight instructor. As an instructor, I would be eager to give a hint as to why I thought a particular aircraft, component or pilot procedure was a bad idea or had been replaced by a truly better version. But then such hands on activity is not understood well by some groups. Thank you for your wisdom. Maybe someday I will understand just exactly what you are saying.

I think there are two major criticisms I would make about that code. It is only a "fun" piece of demo code, so these faults are not serious in themselves. But people do learn from such code, and might think these faults are normal or inevitable or acceptable, and repeat them in other projects where these faults can cause real problems.

Firstly, there is quite a lot of repetition. It's almost always true that less code is better. It takes less effort to change or fix it when required.

Secondly, it uses the delay() function a lot and relies on it for sequencing and timing. People are used to PCs/laptops/smartphones appearing to do many things at once with ease without appreciating the complexity going on behind the scenes that make that possible. But most Arduino have only a single CPU core and no operating system to enable multi-tasking. The time wasted by delay() cannot be used for other tasks. Even something as simple as monitoring an ordinary push button to check if it gets pressed cannot be done with that code. The button presses would be missed because chances are they would happen during one of those delays.

That is outstanding! I agree with your assesment. Additionally, once that demo was slowed down, Arduino graphic was mirror image! My raving was more for it actually WORKED in some coherent way after uploading. Further, the wiring in most of the Elegoo Arduino kit differ from the sketches in the library. Just because the library sketch is tagged "Installed" does not mean the sketch is any good because most of them do NOT work.
Where is a good place to start learning this language to be able to write my own stuff....for better or worse!

Take a look into this tutorial:

Arduino Programming Course

It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

best regards Stefan

This link is working great! Thank you!

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