BCD clock

Dear Arduionists,

i have a problem with my new project, a binary clock in BCD-format.

13 leds display the 24 hours in 4 vertically columns: o o 8
o o o 4
o o o o 2
o o o o 1
--------------------|------------------------------------
tens ones | tens ones
hours | minutes
I hope, my drawing can explain you, how the leds are arranged and with a minimum of hardware the time will be displayed.
The led-array is common cathode and driven by a MAX7219 chip. It works well, in the display control mode all leds are lighting up.
So i can say, my circuit is ok.
But in running my program, <binary-clock.ino>, the leds are not switched in. Only a dim glowing shows me the time.
For example: the fixed time (in line 75), 13:57:39 h, is displayed with 6 leds.
The hour tens led, the hour twos led, all the minute leds are shiny, only the one minute led is “switched on”.

What is my fault?

Greetings bolsak.

[code]
/* binary_clock.ino
  SPI-pins: MOSI = D11,SCK = D13,SS = D10
  time-display with 13 led in BCD-format:

   8           0              0
   4           0      0       0
   2   0       0      0       0
   1   0       0      0       0
  -----------------------------------
      hour   hour   minute  minute
      ten     one    ten     one
  2 additional leds show that the clock in "running"

  it is a common-cathode-array as in
  playground-arduino.cc/LEDMatrix/MAX7219
 
*/
uint32_t runMillis;
uint32_t allSeconds, secsRemaining;
uint8_t hour, minute, second;
#include <SPI.h>
#include <binary.h>

const byte MAX7219_REG_NOOP         = 0x0;
const byte MAX7219_REG_DIGIT0       = 0x1; // 1. row
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; // 8. row
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;

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

char  buf[21];            // Serial.print
const byte Bell =  9;     // bell / loudspeaker

void GetTime() {
  runMillis = millis();
  allSeconds = millis() / 1000;
  hour = allSeconds / 3600;
  secsRemaining = allSeconds % 3600;
  minute = secsRemaining / 60;
  second = secsRemaining % 60;
}
void setup() {
  Serial.begin(115200);
  Serial.println(" =========== binary_clock.ino ==================== ");
  Serial.println(" =============================== 20.11.2020 ====== ");

  pinMode(Bell, OUTPUT);

  SPI.begin();
  sendByte (MAX7219_REG_SCANLIMIT, 2);   // 0 ... 7  2 rows
  sendByte (MAX7219_REG_DECODEMODE, 0);  // single LED=0
  sendByte (MAX7219_REG_DISPLAYTEST, 0); // display = 0, Test=1

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

    sendByte (MAX7219_REG_INTENSITY, 9);  // 0 .. 15
    sendByte (MAX7219_REG_SHUTDOWN, 1);  //
  }
  hour = 13; minute = 57; second = 39;    // fixed time for testing
} //                   ====== setup ===

void loop() {  //
  //GetTime();

  sprintf(buf, "   % 2d:%02d:%02d ", hour, minute, second);

  // ============================ output ============   minute-ones

  (minute % 10 == 1 || minute % 10 == 3 || minute % 10 == 5 || minute % 10 == 7 || minute % 10 == 9)
  ? sendByte(1, 128)    :   sendByte(1, 0);

  (minute % 10 == 2 || minute % 10 == 3 || minute % 10 == 6 || minute % 10 == 7)
  ? sendByte(1, 64)    :   sendByte(1, 0);

  (minute % 10 == 4 || minute % 10 == 5 || minute % 10 == 6 || minute % 10 == 7)
  ? sendByte(1, 32)    :   sendByte(1, 0);

  (minute % 10 == 8 || minute % 10 == 9)
  ? sendByte(1, 16)    :   sendByte(1, 0);
  // =============================================================   minute-tens

  (minute / 10 == 1 || minute / 10 == 3 || minute / 10 == 5 || minute / 10 == 7 || minute / 10 == 9)
  ? sendByte(1, 8)    :   sendByte(1, 0);

  (minute / 10 == 2 || minute / 10 == 3)   ? sendByte(1, 4)    :   sendByte(1, 0);

  (minute / 10 == 4 || minute / 10 == 5)   ? sendByte(1, 2)    :   sendByte(1, 0);

  //  ==============================================================  hour-ones

  (hour % 10 == 1 || hour % 10 == 3 || hour % 10 == 5 || hour % 10 == 7 || hour % 10 == 9)
               ? sendByte(1, 1)    :   sendByte(1, 0);

  (hour % 10 == 2 || hour % 10 == 3 || hour % 10 == 6 || hour % 10 == 7)
               ? sendByte(2, 128)    :   sendByte(2, 0);

  (hour % 10 == 4 || hour % 10 == 5 || hour % 10 == 6 || hour % 10 == 7)
               ? sendByte(2, 64)    :   sendByte(2, 0);

  (hour % 10 == 8 || hour % 10 == 9)   ? sendByte(2, 32)    :   sendByte(2, 0);

  // ==============================================================     hour-tens

  (hour / 10 == 1 || hour / 10 == 3)  ? sendByte(2, 16)   :   sendByte(2, 0);
  (hour / 10 == 2 )                   ? sendByte(2, 8)    :   sendByte(2, 0);

  Serial.print(buf);
  Serial.println();
}

[/code]

But my problem now is, i can’t work with SPI.
but using the SPI protocol gives me no equal and bright

@bolsak

TOPIC SPLIT
PLEASE DO NOT HIJACK / NECRO POST !

Could you take a few moments to Learn How To Use The Forum.

Other general help and troubleshooting advice can be found here.
It will help you get the best out of the forum in the future.