Converting LCD prints to TM1637 7 Segment outputs

Hi there,

Im repurposing an older sketch for a new project, Its basically is a timer that activates a servo at regular intervals during the timer and prints the timer and other information on a standard 20x4 ic2 lcd.

In the new project I would like to use a 7 segment display (4 digit) for the timer, in addition to having it on the LCD screen.

What I'm struggling with though is what commands to put to update the 7segment display with the time. Obviously its a little bit more involved than typing lcd.print lol.

Im using the tm1637 library, and in test countdown scripts its working fine, but I cant get the timer to output on the 7segment as well as the lcd, just the LCD.

Ive included the timer section of my script. It is self contained as I didnt want to use the loop function for the timer. Ive excluded my earlier attempts at adding the 7segment sections as it was turning into a right mess.

void c41DevCycle() {
  uint8_t c41Devcountdown = 180;
  uint8_t c41relayCountdown = 15;

  bool runningc41Dev = true;
  bool updateDisplayc41Dev = true;
  uint32_t countdownTimec41Dev = millis();
  uint32_t relayOnTimec41Dev = 5;
  uint32_t relayOffTimec41Dev = 25;
  bool relayStatec41Dev = true;

  functionOn();
  while (runningc41Dev) {
    if (updateDisplayc41Dev) {
      updateDisplayc41Dev = false;
      lcd.setCursor(0, 2);
      char m[3];
      char s[3];
      sprintf(m, "%02d", int(c41Devcountdown / 60));
      sprintf(s, "%02d", c41Devcountdown % 60);
      lcd.print(m);
      lcd.print(":");
      lcd.print(s);

      if (relayStatec41Dev) {
        lcd.print("  Agitating");
      }
      else {
        lcd.print("   Standing");
      }

      lcd.setCursor(0, 4);
      if (relayStatec41Dev) {
        lcd.print("AGI stops in ");
      }
      else {
        lcd.print("Next AGI in  ");
      }
      sprintf(s, "%02d", c41relayCountdown);
      lcd.print(s);
    }

    // Every second: count down.
    if (millis() - countdownTimec41Dev > 1000) {
      if (c41Devcountdown == 0) { // Finished! (this happens after the last second has passed).
        runningc41Dev = false;
      }
      c41Devcountdown--;
      c41relayCountdown--;
      countdownTimec41Dev += 1000;
      updateDisplayc41Dev = true;
      if (c41relayCountdown == 0) { // Switch the relay.
        if (relayStatec41Dev) {
          functionOff();
          relayStatec41Dev = false;
          c41relayCountdown = relayOffTimec41Dev;
        }
        else {
          functionOn();
          relayStatec41Dev = true;
          c41relayCountdown = relayOnTimec41Dev;
        }
      }
    }
  }
  lcd.clear();
}

functionOn and Off are my servo scripts.

Any idea what commands I can use to output to the 7segment?, or any starters?, Its only the overall timer Im trying to output to the 7segment

You might try:
At top of pgm, add:

#include <TM1637Display.h>
#define CLK 6  // or your CLK / DIO pins
#define DIO 5

TM1637Display display(CLK, DIO);

const byte blank = 0;

In setup(), add:

for(byte i = 0;i < 4;i++)
   display.setSegments(blank,1,i);
 display.setBrightness(0x08); // dimmest = 0x01, brightest = 0x0F
 // To turn on the center colon 00:00, execute the following code.
uint8_t segto;
int value = 1244;
segto = 0x80 | display.encodeDigit((value / 100)%10);
display.setSegments(&segto, 1, 1);
functionOn();
while (runningc41Dev) {
  if (updateDisplayc41Dev) {
    updateDisplayc41Dev = false;
    lcd.setCursor(0, 2);
    char m[3];
    char s[3];
    sprintf(m, "%02d", int(c41Devcountdown / 60));
    sprintf(s, "%02d", c41Devcountdown % 60);
    lcd.print(m);
    lcd.print(":");
    lcd.print(s);
    display.showNumberDec((c41Devcountdown / 60), true, 2, 1);
    display.showNumberDec((c41Devcountdown % 60), true, 2 , 3);

User guide for TM1637 4 digits display.pdf (318 KB)

Thanks for your reply. It actually put me in the right direction,

However in the end, I used the bremme 7 segment library, which made things a lot simpler.

I then just made the minutes and seconds as bytes then printed the bytes on the display.