Glancy, flickering leds, Arduino & MAX7219 and CC-led array

Merry Christmas to all of you,

nevertheless I have a problem and need one hint.

With my Arduino R3 I'm driving an array of 14 leds, common cathode mounted.
MAX7219 should do the job, but the results are not sufficient.
In my sketch I habe two routines:
in Single() I have control of the chosen two leds, but only if I add a delay() in the program.
In Show() I see the 6th led = Display[0][5] bright, but all the other ones are flickering very dim.

How can I solve this problem? What am I doing wrong?

Here is my code:

/* test.ino an array with 14 leds

*/

#include <SPI.h>
#include <avr/pgmspace.h>
#include <stdbool.h>
//
const byte MAX7219_REG_NOOP        = 0x0;
const byte MAX7219_REG_DIGIT0      = 0x1;   //
const byte MAX7219_REG_DIGIT1      = 0x2;   //
const byte MAX7219_REG_DIGIT2      = 0x3;   //
const byte MAX7219_REG_DIGIT3      = 0x4;   //
const byte MAX7219_REG_DIGIT4      = 0x5;   //
const byte MAX7219_REG_DIGIT5      = 0x6;   //
const byte MAX7219_REG_DIGIT6      = 0x7;   //
const byte MAX7219_REG_DIGIT7      = 0x8;   //
const byte MAX7219_REG_DIGIT8      = 0x9;   //
const byte MAX7219_REG_DECODEMODE  = 0x9;   //
const byte MAX7219_REG_INTENSITY   = 0xA;
const byte MAX7219_REG_SCANLIMIT   = 0xB;
const byte MAX7219_REG_SHUTDOWN    = 0xC;
const byte MAX7219_REG_DISPLAYTEST = 0xF;

//                                                   values
uint8_t  ME1, ME2, ME4, ME8, MZ1, MZ2, MZ4, SE1, // 128 ... 1
         SE2, SE4, SE8, SZ1, SZ2, Sec_P;         // 128 ... 4
byte Display[2][8] {
  {  0,64,  0, 32, 0, 16, 0, 4},
  {128, 0, 32,  0, 8, 4,  0, 0}
};

bool ledState = LOW;
bool State;
uint32_t previousMillis_1, currentMillis_1;
const uint32_t Interval_1 = 400;

const byte ledPin  = 19;     //



void setup() {   //             =================== setup

  Serial.begin(115200);
  SPI.begin ();
  sendByte (MAX7219_REG_SCANLIMIT, 2);     // show 2 rows
  sendByte (MAX7219_REG_DECODEMODE, 0);    //
  sendByte (MAX7219_REG_DISPLAYTEST, 0);   // no display test
  sendByte (MAX7219_REG_INTENSITY, 10);    // range: 0 to 15
  sendByte (MAX7219_REG_SHUTDOWN, 1);      // 1 = KEIN shutdown mode

  for (byte col = 0; col < 8; col++)               // clear display
    sendByte (col + 1, 0);

  Serial.println(" ====================================== ");
  Serial.println(" ======== test.ino ==================== ");
  Serial.println(" ======================  25.12.21 ===== ");
  pinMode(ledPin, OUTPUT);
}                               //                ====== setup

void sendByte (const byte reg, const byte data)    {
  digitalWrite (SS, LOW);
  SPI.transfer (reg);
  SPI.transfer (data);
  digitalWrite (SS, HIGH);
}  // end of sendByte

void Show() {                          //     14 LED ===  display
  byte i, j;
  for   (i = 0; i < 2; i++) {                     // 2 rows
    for (j = 0; j < 8; j++)                       // 8 columns
    {
      sendByte(i+1,Display[i][j]);
    }
  }
}

void Single() {
  sendByte(1, Display[0][1]); delay(300);
  sendByte(1, 0); delay(300);
  sendByte(2, Display[1][5]); delay(300);
  sendByte(2, 0); delay(300);
}

void blink() {
  unsigned long currentMillis_1 = millis();
  if (currentMillis_1 - previousMillis_1 >= Interval_1)
  { previousMillis_1 = currentMillis_1;
    ledState == LOW ? ledState = HIGH :    ledState = LOW;
    digitalWrite(ledPin, ledState);
  }
}

void loop() {   //   ================================  loop ##2
  //Single();
  Show();
  blink();


  Serial.print("  array :"); Serial.print(Display[0][0]);
  Serial.print(" "); Serial.print(Display[0][1]);
  Serial.print(" "); Serial.print(Display[0][2]);
  Serial.print(" "); Serial.print(Display[0][3]);
  Serial.print(" "); Serial.print(Display[0][4]);
  Serial.print(" "); Serial.print(Display[0][5]);
  Serial.print(" "); Serial.print(Display[0][6]);
  Serial.print(" "); Serial.print(Display[0][7]);
  Serial.print(" "); Serial.print(Display[1][0]);
  Serial.print(" "); Serial.print(Display[1][1]);
  Serial.print(" "); Serial.print(Display[1][2]);
  Serial.print(" "); Serial.print(Display[1][3]);
  Serial.print(" "); Serial.print(Display[1][4]);
  Serial.print(" "); Serial.print(Display[1][5]);
  Serial.println();


}

You have control of the two LEDs whether you add the delay() or not. You can only see that you have control if you add delay() because without it, some LEDs are on for only a tiny amount of time, too short for the eye to see.

The LEDs are dim and flickering because they are being switched on and off at high speed, again, too fast for the eye to see, so they appear to be dim.

I won't tell you how to fix these problems, because you asked for one hint, so I don't want to spoil your fun figuring it out, unless you ask for more hints.

Dear PaulRB,

thank you for your reply, but my difficulties are not removed. I need at least one more hint?

Certainly I know, that the MAX-Chip flashes at around 800 Hz over my array and that is the reason of the flickering. There is no question that I have control about the array.
But I cannot see the leds "fully illuminated", and that is what I want.
Please explain me, why is the 6th led in row 1 of my array permanently on, when I run the
Show()-routine in my program.
May be, after that I get one more hint of you?

Cheers bolsak.

No. The reason you get flickering is that you are sending data to the MAX7219 every time through the loop. If you keep track of when your data changes and only send when it has, you will eliminate the flickering completely. While the MAX chip is communicating it is not refreshing the LEDs.

A good way to manage this flickering problem is to have a memory buffer that holds information on whether an LED is on or off (one bit is enough for this). Make any change to the display LEDs in the buffer and then send the display buffer to the hardware as one comms transmission.

/* test1.ino an array with 14 leds
                    Fehler:
*/
uint8_t ME1, ME2, ME4, ME8, MZ1, MZ2, MZ4, SE1, SE2, SE4, SE8, SZ1, SZ2, Sec_P;


uint8_t Display[2][8] { { ME1, ME2, ME4, ME8, MZ1, MZ2, MZ4, SE1 },
  { SE2, SE4, SE8, SZ1, SZ2, Sec_P}
};



#include <SPI.h>
#include <avr/pgmspace.h>
#include <stdbool.h>
//
const byte MAX7219_REG_NOOP        = 0x0;
const byte MAX7219_REG_DIGIT0      = 0x1;   //
const byte MAX7219_REG_DIGIT1      = 0x2;   //
const byte MAX7219_REG_DIGIT2      = 0x3;   //
const byte MAX7219_REG_DIGIT3      = 0x4;   //
const byte MAX7219_REG_DIGIT4      = 0x5;   //
const byte MAX7219_REG_DIGIT5      = 0x6;   //
const byte MAX7219_REG_DIGIT6      = 0x7;   //
const byte MAX7219_REG_DIGIT7      = 0x8;   //
const byte MAX7219_REG_DIGIT8      = 0x9;   //
const byte MAX7219_REG_DECODEMODE  = 0x9;   //
const byte MAX7219_REG_INTENSITY   = 0xA;
const byte MAX7219_REG_SCANLIMIT   = 0xB;
const byte MAX7219_REG_SHUTDOWN    = 0xC;
const byte MAX7219_REG_DISPLAYTEST = 0xF;

bool ledState = LOW;
bool State;
uint32_t previousMillis_1, currentMillis_1;
const uint32_t Interval_1 = 500;
const byte ledPin  = 19;     //

void setup() {   //       
  Serial.begin(115200);
  SPI.begin ();
  sendByte (MAX7219_REG_SCANLIMIT, 2);     // show 2 rows
  sendByte (MAX7219_REG_DECODEMODE, 0);    //
  sendByte (MAX7219_REG_DISPLAYTEST, 0);   // no display test
  sendByte (MAX7219_REG_INTENSITY, 10);    // range: 0 to 15
  sendByte (MAX7219_REG_SHUTDOWN, 1);      // 1 = KEIN shutdown mode

  Serial.println(" ====================================== ");
  Serial.println(" ======== test1.ino ==================== ");
  Serial.println(" ======================  28.12.21 ===== ");
  pinMode(ledPin, OUTPUT);
}                               //

void sendByte (const byte reg, const byte data)    {
  digitalWrite (SS, LOW);
  SPI.transfer (reg);
  SPI.transfer (data);
  digitalWrite (SS, HIGH);
}  // end of sendByte

void Single() {
  sendByte(1, 128); delay(300);
  sendByte(1, 0); delay(300);
  sendByte(2, 4); delay(300);
  sendByte(2, 0); delay(300);
}

void Show() {                          //     14 LED ===  display
  byte i, j;
  for   (i = 0; i < 2; i++) {                     // 2 rows
    for (j = 0; j < 8; j++)                       // 8 columns
    {
      sendByte(i, Display[i][j]);
    }
  }
}

void blink() {
  unsigned long currentMillis_1 = millis();
  if (currentMillis_1 - previousMillis_1 >= Interval_1)
  { previousMillis_1 = currentMillis_1;
    ledState == LOW ? ledState = HIGH :    ledState = LOW;
    digitalWrite(ledPin, ledState);
  }
}

void loop() {   //   ================================  loop ##2
  //Single();
  //  Show();
  blink();

  if (ledState == HIGH)  {
    (Display[0][0]) = 128;       // ME1
    sendByte(1, Display[0][0]);
  }
  else {
    (Display[0][0]) = 0;
    sendByte(1, 0);
  }

  if (ledState == HIGH)  {
    (Display[0][7]) = 1;        // SE1
    sendByte(1, Display[0][7]);
  }
  else {
    (Display[0][7]) = 0;
    sendByte(1, 0);
  }

  if (ledState == HIGH)  {
    (Display[1][6]) = 4;       // Sec_P
    sendByte(2, Display[1][6]);
  }
  else {
    (Display[1][6]) = 0;
    sendByte(2, 0);
  }

  Serial.print("  array :  "); Serial.print(Display[0][0]);
  Serial.print(" "); Serial.print(Display[0][1]);
  Serial.print(" "); Serial.print(Display[0][2]);
  Serial.print(" "); Serial.print(Display[0][3]);
  Serial.print(" "); Serial.print(Display[0][4]);
  Serial.print(" "); Serial.print(Display[0][5]);
  Serial.print(" "); Serial.print(Display[0][6]);
  Serial.print(" "); Serial.print(Display[0][7]);

  Serial.print("     "); Serial.print(Display[1][0]);
  Serial.print(" "); Serial.print(Display[1][1]);
  Serial.print(" "); Serial.print(Display[1][2]);
  Serial.print(" "); Serial.print(Display[1][3]);
  Serial.print(" "); Serial.print(Display[1][4]);
  Serial.print(" "); Serial.print(Display[1][5]);

  Serial.println();


}

Dear PaulRB and marco_c,

i made some tests, to get a sufficiently result for my 14 leds, but I had no success.
I don't know, how to "switch on" constantly more than two leds with my program. test1.ino shows the last led in row1 and the last in row2 "on" as long as my variable is HIGH. But the first led in row1 is glancy,
as well as I started my thread.
I do not know how to get a better result.
Please give me at least one advice.

Sincerely bolsak.

[

Hi @bolsak
Please, post a photo and/or the link that shows this array.

Hi, ruilviana,

my hand made array is arranged as in nick gammons example:
www.gammon.com.au/forum/?id=11516 on page 2.
I don't know, how to add a drawing of my smaller array to my post.

Sincerely bolsak.

Hi
so your matrix is 14x8?
Or 14 x 14?

@bolsak the above is still true, you did not fix it. Perhaps that will fix your "glancy" led? If not, please explain what you mean by "glancy", the word is not familiar to me.

My suspicion at the moment is that you have a misconception in your mind. For example you said

Do you think that each element in this 2-D array corresponds to a single led?

@ruilviana
Here is a drawing of my 14 led-array
led-array.PDF (78.8 KB)

Greetings bolsak.

Tks
I will try run your code using your LED array.

@PaulRB,
dear PaulRB due to the fact, that English is not my native language, I have to explan, what I mean, if I write glancy. The led is not "fully visible", in comparison to the two other in my program. They are "bright".

My array consists of 14 common cathode leds .

The first row are 8 leds = Display[0][0] ......... Display[0][7] .
The second row : 6 leds = Display[1][0] ........ Display[1][5] .

My problem is the fact, that in my program only the last led in one of my two rows is "fully visible", when the program is running.

How can I solve this problem?

Sincerely bolsak.

Hi @bolsak

I set up your project and I'm using the code you posted in #1.
It really occurs as you write.
I've read all subsequent posts and haven't found anything that says how your project should work properly.
Please tell me how it should work.
How the LEDs are expected to work.


Please do not post .PDFs to the forum unless it is a "genuine" PDF.

A PDF is not an image format - if you have an image, post it as an image and it can be viewed.

Read #4 very carefully.

and each led can be either on or off, correct? The value in each position of the array indicates if that led should be on or off?

So why do you assign different values like these?

    (Display[0][0]) = 128;       // ME1
    sendByte(1, Display[0][0]);
    ...
    (Display[0][7]) = 1;        // SE1
    sendByte(1, Display[0][7]);

If "128" means on, why use "1" in another place?

I believe I know the answer, but, as before, I am trying to give you enough hints for you to figure it out for yourself without giving you the whole answer.

Hi @bolsak

Since I don't know exactly what you want the LEDs to do, see if this code makes sense to you.

He is purposely slow.
To speed up change the delay of line 71

// https://forum.arduino.cc/t/glancy-flickering-leds-arduino-max7219-and-cc-led-array/939523
// test.ino an array with 14 leds
#include <SPI.h>
#include <avr/pgmspace.h>
#include <stdbool.h>
//
const byte MAX7219_REG_NOOP        = 0x0;
const byte MAX7219_REG_DIGIT0      = 0x1;   //
const byte MAX7219_REG_DIGIT1      = 0x2;   //
const byte MAX7219_REG_DIGIT2      = 0x3;   //
const byte MAX7219_REG_DIGIT3      = 0x4;   //
const byte MAX7219_REG_DIGIT4      = 0x5;   //
const byte MAX7219_REG_DIGIT5      = 0x6;   //
const byte MAX7219_REG_DIGIT6      = 0x7;   //
const byte MAX7219_REG_DIGIT7      = 0x8;   //
const byte MAX7219_REG_DIGIT8      = 0x9;   //
const byte MAX7219_REG_DECODEMODE  = 0x9;   //
const byte MAX7219_REG_INTENSITY   = 0xA;
const byte MAX7219_REG_SCANLIMIT   = 0xB;
const byte MAX7219_REG_SHUTDOWN    = 0xC;
const byte MAX7219_REG_DISPLAYTEST = 0xF;
//                                                   values
uint8_t  ME1, ME2, ME4, ME8, MZ1, MZ2, MZ4, SE1, // 128 ... 1
         SE2, SE4, SE8, SZ1, SZ2, Sec_P;         // 128 ... 4
byte Display[2][9] {
  {  0, 64,  0, 32, 0, 16, 0, 4, 0},
  {128, 0, 32,  0, 8, 4,  0, 0, 0}
  //  {128, 64, 32, 16, 8, 4, 2, 1, 0},
  //  {128, 64, 32, 16, 8, 4, 0, 0, 0}

};
bool ledState = LOW;
bool State;
uint32_t previousMillis_1, currentMillis_1;
const uint32_t Interval_1 = 400;
const byte ledPin  = 19;     //
//----------------------------------------------------------------------------------------
void setup() {   //             =================== setup
  Serial.begin(115200);
  SPI.begin ();
  sendByte (MAX7219_REG_SCANLIMIT, 2);     // show 2 rows
  sendByte (MAX7219_REG_DECODEMODE, 0);    //
  sendByte (MAX7219_REG_DISPLAYTEST, 0);   // no display test
  sendByte (MAX7219_REG_INTENSITY, 10);    // range: 0 to 15
  sendByte (MAX7219_REG_SHUTDOWN, 1);      // 1 = KEIN shutdown mode

  for (byte col = 0; col < 8; col++)               // clear display
    sendByte (col + 1, 0);

  Serial.println(" ====================================== ");
  Serial.println(" ======== test.ino ==================== ");
  Serial.println(" ======================  25.12.21 ===== ");
  pinMode(ledPin, OUTPUT);
}                               //                ====== setup
//----------------------------------------------------------------------------------------
void sendByte (const byte reg, const byte data)    {
  digitalWrite (SS, LOW);
  SPI.transfer (reg);
  SPI.transfer (data);
  digitalWrite (SS, HIGH);
}  // end of sendByte
//----------------------------------------------------------------------------------------
void Show() {                          //     14 LED ===  display
  byte i, j;
  for   (i = 0; i < 2; i++)                       // 2 rows
  {
    for (j = 0; j < 9; j++)                       // 8 columns
    {
      sendByte(i + 1 , Display[i][j]);
      //delayMicroseconds(500);
      delay(500);
    }
  }
  Serial.println(" ");
}
//----------------------------------------------------------------------------------------
void Single() {
  sendByte(1, Display[0][1]); delay(300);
  sendByte(1, 0); delay(300);
  sendByte(2, Display[1][5]); delay(300);
  sendByte(2, 0); delay(300);
}
//----------------------------------------------------------------------------------------
void blink() {
  unsigned long currentMillis_1 = millis();
  if (currentMillis_1 - previousMillis_1 >= Interval_1)
  { previousMillis_1 = currentMillis_1;
    ledState == LOW ? ledState = HIGH :    ledState = LOW;
    digitalWrite(ledPin, ledState);
  }
}
//----------------------------------------------------------------------------------------
void loop() {   //   ================================  loop ##2
  //Single();
  Show();
  blink();
  Serial.print("  array :"); Serial.print(Display[0][0]);
  Serial.print(" "); Serial.print(Display[0][1]);
  Serial.print(" "); Serial.print(Display[0][2]);
  Serial.print(" "); Serial.print(Display[0][3]);
  Serial.print(" "); Serial.print(Display[0][4]);
  Serial.print(" "); Serial.print(Display[0][5]);
  Serial.print(" "); Serial.print(Display[0][6]);
  Serial.print(" "); Serial.print(Display[0][7]);
  Serial.print(" "); Serial.print(Display[1][0]);
  Serial.print(" "); Serial.print(Display[1][1]);
  Serial.print(" "); Serial.print(Display[1][2]);
  Serial.print(" "); Serial.print(Display[1][3]);
  Serial.print(" "); Serial.print(Display[1][4]);
  Serial.print(" "); Serial.print(Display[1][5]);
  Serial.println();
}

@ruilviana
thank you for your proposal. I can't use any delay() in my program.
The 14 leds are used in a BCD-clock. Thirteen show the time in a 24 hour format and the 14th flashes up, when a second has passed.
I'm counting the 50-Hz-line-pulses.
Due to this problem, i have omitted the delay() and search for another method. I have an idea, proposed from PaulRB.

@PaulRB

thank you for your reply.
I'm sending different values to the MAX, to switch on different leds in my array, according to the current time.
if Display[0][0]=128 and I sendByte(1,128) to the MAX, then led one of the first row is on. ME1 is the led for minute one.
Accordingly sendByte(1,4) switches the sixth led in row 1. Then MZ2 is on, that is the led for 20 minutes. If I read the actual time, I have to add all lighting leds.
I will try a routine with a switch-case statement, to get off the high refresh time of the MAX. You'll see that later on.

Sincerely bolsak.

OK, here is another hint. In order to light more than one led, you must send the combination of the leds required to the MAX. For example

sendByte(1,128 + 4)

should light 2 leds.

A better way to think about this would be to think about the number sent to the MAX as a binary number where each bit controls a separate LED. The above could be rewritten

sendByte(1, 0b10000100)

I also think your 2-D array "Display" is causing confusion. Perhaps you could remove it. In its place you may be able to use a "uint16_t" type variable and use bit manipulation operations such as "&", "|", ">>", "<<" to set the required bits. Like this maybe:

uint16_t timeNow;
...
timeNow = ME1; //Manipulate bits to represent the current time
...
sendByte(1, highbyte(timeNow));
sendByte(2, lowbyte(timeNow));

However, I can see that your code never assigns any value to ME1, ME2... You need to assign the correct values to these.

Hi
I understand that you cannot use delay, but I only used delay to make it easier to see the sequence of LED lights.

Try my code without delay().

Hi @
I'm not sure I understand your need correctly,
but run this code and see the result.

// https://forum.arduino.cc/t/glancy-flickering-leds-arduino-max7219-and-cc-led-array/939523
// test.ino an array with 14 leds
#include <SPI.h>
#include <avr/pgmspace.h>
#include <stdbool.h>
//
const byte MAX7219_REG_NOOP        = 0x0;
const byte MAX7219_REG_DIGIT0      = 0x1;   //
const byte MAX7219_REG_DIGIT1      = 0x2;   //
const byte MAX7219_REG_DIGIT2      = 0x3;   //
const byte MAX7219_REG_DIGIT3      = 0x4;   //
const byte MAX7219_REG_DIGIT4      = 0x5;   //
const byte MAX7219_REG_DIGIT5      = 0x6;   //
const byte MAX7219_REG_DIGIT6      = 0x7;   //
const byte MAX7219_REG_DIGIT7      = 0x8;   //
const byte MAX7219_REG_DIGIT8      = 0x9;   //
const byte MAX7219_REG_DECODEMODE  = 0x9;   //
const byte MAX7219_REG_INTENSITY   = 0xA;
const byte MAX7219_REG_SCANLIMIT   = 0xB;
const byte MAX7219_REG_SHUTDOWN    = 0xC;
const byte MAX7219_REG_DISPLAYTEST = 0xF;
//                                                   values
uint8_t  ME1, ME2, ME4, ME8, MZ1, MZ2, MZ4, SE1, // 128 ... 1
         SE2, SE4, SE8, SZ1, SZ2, Sec_P;         // 128 ... 4
byte Display[8][8] {
  // {  0, 64,  0, 32, 0, 16, 0, 4, 0},
  // {128, 0, 32,  0, 8, 4,  0, 0, 0}
  {0, 0, 0, 0, 0, 0, 0, 0},
  {0, 0, 0, 0, 0, 0, 0, 0}

};
bool ledState = LOW;
bool State;
uint32_t previousMillis_1, currentMillis_1;
const uint32_t Interval_1 = 400;
const byte ledPin  = 19;     //
unsigned long myTime = millis();
int mySeg = 0;
int myMin = 0;
int myHour = 0;
//----------------------------------------------------------------------------------------
void setup() {   //             =================== setup
  Serial.begin(115200);
  SPI.begin ();
  sendByte (MAX7219_REG_SCANLIMIT, 2);     // show 2 rows
  sendByte (MAX7219_REG_DECODEMODE, 0);    //
  sendByte (MAX7219_REG_DISPLAYTEST, 0);   // no display test
  sendByte (MAX7219_REG_INTENSITY, 10);    // range: 0 to 15
  sendByte (MAX7219_REG_SHUTDOWN, 1);      // 1 = KEIN shutdown mode

  for (byte col = 0; col < 8; col++)               // clear display
    sendByte (col + 1, 0);

  Serial.println(" ====================================== ");
  Serial.println(" ======== test.ino ==================== ");
  Serial.println(" ======================  25.12.21 ===== ");
  pinMode(ledPin, OUTPUT);
}                               //                ====== setup
//----------------------------------------------------------------------------------------
void sendByte (const byte reg, const byte data)    {
  digitalWrite (SS, LOW);
  SPI.transfer (reg);
  SPI.transfer (data);
  digitalWrite (SS, HIGH);
}  // end of sendByte
//----------------------------------------------------------------------------------------
void Show() {                          //     14 LED ===  display
  for (int i = 0; i < 2; i++)                      // 2 rows
  {
    sendByte(i + 1 , Display[i][0]);
  }
}
//----------------------------------------------------------------------------------------
void Single() {
  sendByte(1, Display[0][1]); delay(300);
  sendByte(1, 0); delay(300);
  sendByte(2, Display[1][5]); delay(300);
  sendByte(2, 0); delay(300);
}
//----------------------------------------------------------------------------------------
void blink() {
  unsigned long currentMillis_1 = millis();
  if (currentMillis_1 - previousMillis_1 >= Interval_1)
  { previousMillis_1 = currentMillis_1;
    ledState == LOW ? ledState = HIGH :    ledState = LOW;
    digitalWrite(ledPin, ledState);
  }
}
//----------------------------------------------------------------------------------------
void loop() {   //   ================================  loop ##2
  if (millis() - myTime >= 1000)     // At each second
  {
    myTime = millis();            // Refresh myTime
    mySeg++;                      // Increase mySeg
    if (mySeg > 59)               // If Seg over
    {
      mySeg = 0;                  // Refresh seconds
      myMin++;                    // Increase myMin
      if (myMin >= 59)            // If pass 1 hour
      {
        myMin = 0;                // Refresh myMin
        myHour += 4;              // Increse hour count
        if (myHour > 95)          // If hour > 23
          myHour = 0;             // Refresh myHour
      }
    }
  }
  Display[0][0] = mySeg;            // Show seconds
  Display[1][0] = myHour;           // Show hour
  
  //Single();
  Show();
  //  blink();
  //  Serial.print("  array :"); Serial.print(Display[0][0]);
  //  Serial.print(" "); Serial.print(Display[0][1]);
  //  Serial.print(" "); Serial.print(Display[0][2]);
  //  Serial.print(" "); Serial.print(Display[0][3]);
  //  Serial.print(" "); Serial.print(Display[0][4]);
  //  Serial.print(" "); Serial.print(Display[0][5]);
  //  Serial.print(" "); Serial.print(Display[0][6]);
  //  Serial.print(" "); Serial.print(Display[0][7]);
  //  Serial.print(" "); Serial.print(Display[1][0]);
  //  Serial.print(" "); Serial.print(Display[1][1]);
  //  Serial.print(" "); Serial.print(Display[1][2]);
  //  Serial.print(" "); Serial.print(Display[1][3]);
  //  Serial.print(" "); Serial.print(Display[1][4]);
  //  Serial.print(" "); Serial.print(Display[1][5]);
  //  Serial.println();
}