Skip to main content
1 of 2

You can set up an array containing the bit patterns to turn on different digits, and then use code that sends (for example) a high digit of now.hour()/12 and a low digit of now.hour()%12. For example:

const byte digiBits[] = { B0000, B0001, 
// and so forth for all the digits ...
};

void send1Digit(byte digiVal, byte whichDigit) {
  // somehow use whichDigit to direct the bits someplace...

  // To send the bits:
  byte bits = digiBits[digiVal];
  for (byte i=4; i<8; ++i) {
    sr.set(i, bits & 1);  // Set a bit in SR to 0 or 1
    bits >>= 1; // shift out the used bit
  }
}

void send2Digits(byte numVal, byte whichDigit) {
  send1Digit(numVal/10, whichDigit);
  send1Digit(numVal%10, whichDigit+1);
}

void loop() {
  // other stuff, then:
  send2Digits(now.hour(), HourSpot);
  send2Digits(now.minute(), MinuteSpot);
  send2Digits(now.second(), SecondSpot);
  // other stuff ...
}

Note, if your sr.set() routine is doing any complicated masking or shifting, you may be able to avoid some of that by ORing digiBits[digiVal] with whatever number sr.set() might be building up to shift out.