Trying to copy and past code to make something new

Just started to get into Arduino to give my projects more life.

I'm working on making a portable digital pocket watch, using an Arduino, RTC and a TM1637

using this code from the project hub, I got it all working.

// Reloj digital mostrado a través de un display de 4 dígitos (digitaltube), y con el tiempo
// proporcionado por un Tiny RTC de Catalex.

// Software programado por PentiumCadiz 7-1-17, basado en el ejemplo de la librería DS1307RTC 
// y en el ejemplo de uso del display de Prometec  http://www.prometec.net/display-con-interface/ 

#include <TM1637.h>

#include <Wire.h>
#include <Time.h>
#include <DS1307RTC.h>

#define CLK 9
#define DIO 8

TM1637 Display1(CLK, DIO);
  int8_t Digitos[] = {0,1,2,3};
  int horas;
  int minutos;
  boolean alterna;

void setup() {
  Serial.begin(9600);
  while (!Serial) ; // wait for serial
  delay(200);
  Serial.println("DS1307RTC Read Test");
  Serial.println("-------------------");

  Display1.set();
  Display1.init();
  
}

void loop() {
  tmElements_t tm;

  if (RTC.read(tm)) {
    Serial.print("Ok, Time = ");
    print2digits(tm.Hour);
    Serial.write(':');
    print2digits(tm.Minute);
    Serial.write(':');
    print2digits(tm.Second);
    Serial.print(", Date (D/M/Y) = ");
    Serial.print(tm.Day);
    Serial.write('/');
    Serial.print(tm.Month);
    Serial.write('/');
    Serial.print(tmYearToCalendar(tm.Year));
    Serial.println();

    horas = tm.Hour;
    minutos = tm.Minute;
    CalculaDigitos(horas, minutos);
    if (alterna)
      {
        Display1.point(POINT_OFF);
        alterna = false;
      }
      else
      {
        Display1.point(POINT_ON);
        alterna = true;
      }
    
  } else {
    if (RTC.chipPresent()) {
      Serial.println("The DS1307 is stopped.  Please run the SetTime");
      Serial.println("example to initialize the time and begin running.");
      Serial.println();
    } else {
      Serial.println("DS1307 read error!  Please check the circuitry.");
      Serial.println();
    }
    delay(9000);
  }
  delay(1000);
}

void print2digits(int number) {
  if (number >= 0 && number < 10) {
    Serial.write('0');
  }
  Serial.print(number);
}

void CalculaDigitos( int hor, int minu)
   {
      int8_t Digit0 = minu %10 ;
      int8_t Digit1 = (minu % 100) / 10 ;
      int8_t Digit2 = hor % 10 ;
      int8_t Digit3 = (hor % 100) / 10 ;

      Digitos[3] = Digit0 ;
      Digitos[2] = Digit1 ;
      Digitos[1] = Digit2 ;
      Digitos[0] = Digit3 ;

      Display1.display(Digitos);
   }

What I would like to do if possible, is to control the brightness of the TM1637 using two switches to increase and decrease the brightness. I believe this ranges from 1 to 7 with 7 being max.

I found some code in another project for a 7 segment display and tried to copy it into the working code.
this does not work. I am new to programming and read a book, but that was not much more then copy typing into the IDE.

My code below and then the faults.

#include <TM1637.h>
#include <Bounce2.h>
#include <Wire.h>
#include <TimeLib.h>
#include <DS1307RTC.h>

#define CLK 9
#define DIO 8

TM1637 display(CLK, DIO);
int8_t Digitos[] = {0, 1, 2, 3};
int horas;
int minutos;
boolean alterna;

const int Switch = 4;
const int Switch2 = 5;
Bounce brightnessUp  (   4, 25 );
Bounce brightnessDown( 5, 25 );
int BRIGHTEST = 7;      // starting brightness

void setup()
{
  Serial.begin(9600);
  while (!Serial) ; // wait for serial
  delay(200);
  Serial.println("DS1307RTC Read Test");
  Serial.println("-------------------");

  display.set();
  display.init();

  // Use the Bounce2 library for the brightness switch|
  brightnessUp.attach( Switch, INPUT_PULLUP );
  brightnessDown.attach( Switch2, INPUT_PULLUP );
  brightnessUp.interval( 25 ); // how quickly to sample
  brightnessDown.interval( 25 ); // how quickly to sample

}

void loop()

{
  // Process button presses
  if (brightnessUp.update()) {
    if (BRIGHTEST < 7) {
      BRIGHTEST == 1;
    }
    display.BRIGHTEST( BRIGHTEST );
  }
  if (brightnessDown.update()) {
    if (BRIGHTEST > 0) {
      BRIGHTEST == 1;
    }
    display.BRIGHTEST( BRIGHTEST );
  }
  tmElements_t tm;
}
{ if (RTC.read(tm)) {
    Serial.print("Ok, Time = ");
    print2digits(tm.Hour);
    Serial.write(':');
    print2digits(tm.Minute);
    Serial.write(':');
    print2digits(tm.Second);
    Serial.print(", Date (D/M/Y) = ");
    Serial.print(tm.Day);
    Serial.write('/');
    Serial.print(tm.Month);
    Serial.write('/');
    Serial.print(tmYearToCalendar(tm.Year));
    Serial.println();

    horas = tm.Hour;
    minutos = tm.Minute;
    CalculaDigitos(horas, minutos);
    if (alterna)
    {
      display.point(POINT_OFF);
      alterna = false;
    }
    else
    {
      display.point(POINT_ON);
      alterna = true;
    }

  } else {
    if (RTC.chipPresent()) {
      Serial.println("The DS1307 is stopped.  Please run the SetTime");
      Serial.println("example to initialize the time and begin running.");
      Serial.println();
    } else {
      Serial.println("DS1307 read error!  Please check the circuitry.");
      Serial.println();
    }
    delay(9000);
  }
  delay(1000);
}

void print2digits(int number) {
  if (number >= 0 && number < 10) {
    Serial.write('0');
  }
  Serial.print(number);
}

void CalculaDigitos( int hor, int minu)
{
  int8_t Digit0 = minu % 10 ;
  int8_t Digit1 = (minu % 100) / 10 ;
  int8_t Digit2 = hor % 10 ;
  int8_t Digit3 = (hor % 100) / 10 ;

  Digitos[3] = Digit0 ;
  Digitos[2] = Digit1 ;
  Digitos[1] = Digit2 ;
  Digitos[0] = Digit3 ;

  display.display(Digitos);
Arduino: 1.8.7 (Windows 10), Board: "Arduino/Genuino Uno"

In file included from F:\Arduino_Bits\Colck1mod\Colck1mod.ino:2:0:

F:\Arduino_Bits\libraries\Grove_4-Digit_Display/TM1637.h:47:25: error: expected unqualified-id before numeric constant

 #define  BRIGHTEST      7

                         ^

F:\Arduino_Bits\Colck1mod\Colck1mod.ino:21:5: note: in expansion of macro 'BRIGHTEST'

 int BRIGHTEST = 7;      // starting brightness

     ^

F:\Arduino_Bits\Colck1mod\Colck1mod.ino: In function 'void loop()':

F:\Arduino_Bits\libraries\Grove_4-Digit_Display/TM1637.h:47:25: error: expected unqualified-id before numeric constant

 #define  BRIGHTEST      7

                         ^

F:\Arduino_Bits\Colck1mod\Colck1mod.ino:50:13: note: in expansion of macro 'BRIGHTEST'

     display.BRIGHTEST( BRIGHTEST );

             ^

F:\Arduino_Bits\libraries\Grove_4-Digit_Display/TM1637.h:47:25: error: expected unqualified-id before numeric constant

 #define  BRIGHTEST      7

                         ^

F:\Arduino_Bits\Colck1mod\Colck1mod.ino:56:13: note: in expansion of macro 'BRIGHTEST'

     display.BRIGHTEST( BRIGHTEST );

             ^

F:\Arduino_Bits\Colck1mod\Colck1mod.ino: At global scope:

Colck1mod:60:1: error: expected unqualified-id before '{' token

 { if (RTC.read(tm)) {

 ^

exit status 1
expected unqualified-id before '{' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

int BRIGHTEST = 7;  ``#define  BRIGHTEST      7Oops

int BRIGHTEST = 7; Yep change this variable name, BRIGHTEST is already defined in one of the libraries

Hi, HERE IS a general approach to merging two (+?) Arduino sketches.

Thanks for the replies.

To be honest I'm unsure what to do with the information provided by AWOL and Deva_Rishi I have no context or reference to refer to.

I think I will take terryking228 advice and rewrite the code after a lot more study.

Feeling at the moment, I have just turned up to compete in the mountain stage of the Tour De France on a skateboard.

In file included from F:\Arduino_Bits\Colck1mod\Colck1mod.ino:2:0:

F:\Arduino_Bits\libraries\Grove_4-Digit_Display/TM1637.h:47:25: error: expected unqualified-id before numeric constant

 #define  BRIGHTEST      7

That is what it says in your error msg. Actually you define BRIGHTEST as an 'int' but in TM1637.h it says "#define BRIGHTEST 7" there is a conflict there, your error msg's are usually quite specific about where the compiler can not make sense of the code. Since changing the library is probably not what we want to do if we can change the '.ino' file. Read through your error msg's and try to fix them, look at where the error occurs according to the compiler and look for double definitions if you've merged code.

ASIDE: If you're making a pocket watch - choose your RTC carefully, as the tempeature variation between your pocket and the nightstand will cause medium term drift in your timekeeping if the temperature changes aren't accouunted for.
e.g. read up on the DS323x series RTC for a good example.

Delta_G:
Sure you do. Let's say you work in an office in a bunch of cubicles. Everyone there has a unique name. The boss runs in and shouts "Bob" and Bob stands up. He runs in and shouts "Dave" and Dave answers.

Now imagine that there are two guys named Steve in this office. Suddenly things get more complicated.

The Arduino can't handle it at all. It needs to know exactly what you are talking about, so things can't have the same name.

Ah, If I understand right. I'm trying to program what is already defined in the library?

Thanks for the tip about learning the basics of C++ there are quote a few abbreviations and other things.

lastchancename:
ASIDE: If you're making a pocket watch - choose your RTC carefully, as the tempeature variation between your pocket and the nightstand will cause medium term drift in your timekeeping if the temperature changes aren't accouunted for.
e.g. read up on the DS323x series RTC for a good example.

Plan to encase the build in a small windowed tin, with a stripped down 18650 single cell battery bank powering it.

I build one already using the common C51 clock kit, but there was not much I could do to hack it.

E_Lovelace:
Ah, If I understand right. I'm trying to program what is already defined in the library?

more or less.. You are using a name which in one of the libraries that you included is already in use for something else (something very similar actually, it is used to indicate the maximum brightness that can be set)

E_Lovelace:
Ah, If I understand right. I'm trying to program what is already defined in the library?

Not quite.

Things in a #define are macros.

Macros are handled before the compiler is called.

So, the header file contains the macro#define BRIGHTEST 7.

This tells the macro preprocessor "every time you see the string "BRIGHTEST", replace it with "7" ".

Later in your code, you have writtenint BRIGHTEST = 7; so the preprocessor replaces BRIGHTEST with 7, and the compiler sees int 7 = 7;.

Now, after "int" in this context, the compiler expects to see a variable name.
But a variable name cannot start with a digit, so the compiler decides it is an invalid construct.

I have been reading a C++ guide.

With a lot more playing around.

At the moment I have two buttons working to control the display.

I added the code for this to a modified test code for the TM1637Display library. Which has 'setBrightnes'

The clock code uses just a library called TM1637

I believe the TM1637 does not have brightness controls and the TM1637Display does not have the code needed for the clock.

So I'm a bit confused into what to do, I know I can not add both libraries.

Code below is for the button test.

#include <Bounce2.h>
#include <Wire.h>
#include <Arduino.h>
#include <TM1637Display.h>

// Module connection pins (Digital Pins)
#define CLK 9
#define DIO 8

TM1637Display display(CLK, DIO);
int Brightness = 3;      // starting brightness

const int IncreaseSwitch = 4;
const int DecreaseSwitch = 5;
Bounce brightnessUp  (   4, 50 );
Bounce brightnessDown( 5, 50 );


// Displays all number 8 
const uint8_t SEG_8888[] = {
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G,        // 8
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G,        // 8
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G,        // 8
  SEG_A | SEG_B | SEG_C | SEG_D | SEG_E | SEG_F | SEG_G,        // 8
};

void setup()
{
  
  // Use the Bounce2 library for the brightness switch|
  brightnessUp.attach( IncreaseSwitch, INPUT_PULLUP );
  brightnessDown.attach( DecreaseSwitch, INPUT_PULLUP );
  brightnessUp.interval( 25 ); // how quickly to sample
  brightnessDown.interval( 25 ); // how quickly to sample

  display.setBrightness( Brightness );  // uses the initial value from above
}

void loop()
{
  // Process button presses
  if (brightnessUp.update()) {
    if (Brightness < 7) {
      Brightness += 1;
    }
    display.setBrightness( Brightness );
  }
  if (brightnessDown.update()) {
    if (Brightness > 0) {
      Brightness -= 1;
    }    
    display.setBrightness( Brightness );
  }
      display.setSegments(SEG_8888);
    }

E_Lovelace:
So I'm a bit confused into what to do, I know I can not add both libraries.

But adding one of the functions of the one library to the other might not be beyond your capabilities.

Deva_Rishi:
But adding one of the functions of the one library to the other might not be beyond your capabilities.

I just been trying to move across parts from one .h file to the other, that deal with brightness.

Under just the working clock code, I'm now getting the errors.

Arduino: 1.8.7 (Windows 10), Board: "Arduino Nano, ATmega328P (Old Bootloader)"

F:\Arduino_Bits\sketch_dec14b\sketch_dec14b.ino: In function 'void setup()':

sketch_dec14b:23:12: error: 'class TM1637' has no member named 'set'

   Display1.set();

            ^

exit status 1
'class TM1637' has no member named 'set'

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

hmm it is a bit more elaborate then that i am afraid.. first of all copy from library folder #1 both the .cpp and the .h file to a new folder with a different name. Now rename the the .cpp and the .h file to the new library's name, and in the .h file change the Header names to the new name and in the .cpp file change the #include statement to the new name hmm.. if you've done it once it very do-able but now comes the tricky bit. Now you have to transplant the function that is missing in the library from the other one. Ok it may be a bit beyond your current abilities, how about you post both .h & .cpp files and i'll have a look and see if i can make it work.

.cpp from file Grove TM1637

/*

#include "TM1637.h"
#include <Arduino.h>
static int8_t TubeTab[] = {0x3f,0x06,0x5b,0x4f,
                           0x66,0x6d,0x7d,0x07,
                           0x7f,0x6f,0x77,0x7c,
                           0x39,0x5e,0x79,0x71};//0~9,A,b,C,d,E,F
TM1637::TM1637(uint8_t Clk, uint8_t Data)
{
  Clkpin = Clk;
  Datapin = Data;
  pinMode(Clkpin,OUTPUT);
  pinMode(Datapin,OUTPUT);
}

void TM1637::init(void)
{
  clearDisplay();
}

int TM1637::writeByte(int8_t wr_data)
{
  uint8_t i,count1;
  for(i=0;i<8;i++)        //sent 8bit data
  {
    digitalWrite(Clkpin,LOW);
    if(wr_data & 0x01)digitalWrite(Datapin,HIGH);//LSB first
    else digitalWrite(Datapin,LOW);
    wr_data >>= 1;
    digitalWrite(Clkpin,HIGH);

  }
  digitalWrite(Clkpin,LOW); //wait for the ACK
  digitalWrite(Datapin,HIGH);
  digitalWrite(Clkpin,HIGH);
  pinMode(Datapin,INPUT);

  bitDelay();
  uint8_t ack = digitalRead(Datapin);
  if (ack == 0) 
  {
     pinMode(Datapin,OUTPUT);
     digitalWrite(Datapin,LOW);
  }
  bitDelay();
  pinMode(Datapin,OUTPUT);
  bitDelay();
  
  return ack;
}
//send start signal to TM1637
void TM1637::start(void)
{
  digitalWrite(Clkpin,HIGH);//send start signal to TM1637
  digitalWrite(Datapin,HIGH);
  digitalWrite(Datapin,LOW);
  digitalWrite(Clkpin,LOW);
}
//End of transmission
void TM1637::stop(void)
{
  digitalWrite(Clkpin,LOW);
  digitalWrite(Datapin,LOW);
  digitalWrite(Clkpin,HIGH);
  digitalWrite(Datapin,HIGH);
}
//display function.Write to full-screen.
void TM1637::display(int8_t DispData[])
{
  int8_t SegData[4];
  uint8_t i;
  for(i = 0;i < 4;i ++)
  {
    SegData[i] = DispData[i];
  }
  coding(SegData);
  start();          //start signal sent to TM1637 from MCU
  writeByte(ADDR_AUTO);//
  stop();           //
  start();          //
  writeByte(Cmd_SetAddr);//
  for(i=0;i < 4;i ++)
  {
    writeByte(SegData[i]);        //
  }
  stop();           //
  start();          //
  writeByte(Cmd_DispCtrl);//
  stop();           //
}
//******************************************
void TM1637::display(uint8_t BitAddr,int8_t DispData)
{
  int8_t SegData;
  SegData = coding(DispData);
  start();          //start signal sent to TM1637 from MCU
  writeByte(ADDR_FIXED);//
  stop();           //
  start();          //
  writeByte(BitAddr|0xc0);//
  writeByte(SegData);//
  stop();            //
  start();          //
  writeByte(Cmd_DispCtrl);//
  stop();           //
}

void TM1637::clearDisplay(void)
{
  display(0x00,0x7f);
  display(0x01,0x7f);
  display(0x02,0x7f);
  display(0x03,0x7f);
}
//To take effect the next time it displays.
void TM1637::set(uint8_t brightness,uint8_t SetData,uint8_t SetAddr)
{
  Cmd_SetData = SetData;
  Cmd_SetAddr = SetAddr;
  Cmd_DispCtrl = 0x88 + brightness;//Set the brightness and it takes effect the next time it displays.
}

//Whether to light the clock point ":".
//To take effect the next time it displays.
void TM1637::point(boolean PointFlag)
{
  _PointFlag = PointFlag;
}
void TM1637::coding(int8_t DispData[])
{
  uint8_t PointData;
  if(_PointFlag == POINT_ON)PointData = 0x80;
  else PointData = 0;
  for(uint8_t i = 0;i < 4;i ++)
  {
    if(DispData[i] == 0x7f)DispData[i] = 0x00;
    else DispData[i] = TubeTab[DispData[i]] + PointData;
  }
}
int8_t TM1637::coding(int8_t DispData)
{
  uint8_t PointData;
  if(_PointFlag == POINT_ON)PointData = 0x80;
  else PointData = 0;
  if(DispData == 0x7f) DispData = 0x00 + PointData;//The bit digital tube off
  else DispData = TubeTab[DispData] + PointData;
  return DispData;
}
void TM1637::bitDelay(void)
{
 delayMicroseconds(50);
}

.h file

#ifndef TM1637_h
#define TM1637_h
#include <inttypes.h>
#include <Arduino.h>
//************definitions for TM1637*********************
#define ADDR_AUTO  0x40
#define ADDR_FIXED 0x44

#define STARTADDR  0xc0
/**** definitions for the clock point of the digit tube *******/
#define POINT_ON   1
#define POINT_OFF  0
/**************definitions for brightness***********************/
#define  BRIGHT_DARKEST 0
#define  BRIGHT_TYPICAL 2


class TM1637
{
  public:
    uint8_t Cmd_SetData;
    uint8_t Cmd_SetAddr;
    uint8_t Cmd_DispCtrl;
    boolean _PointFlag;     //_PointFlag=1:the clock point on
    TM1637(uint8_t, uint8_t);
    void init(void);        //To clear the display
    int  writeByte(int8_t wr_data);//write 8bit data to tm1637
    void start(void);//send start bits
    void stop(void); //send stop bits
    void display(int8_t DispData[]);
    void display(uint8_t BitAddr,int8_t DispData);
    void clearDisplay(void);
    void set(uint8_t = BRIGHT_TYPICAL,uint8_t = 0x40,uint8_t = 0xc0);//To take effect the next time it displays.
    void point(boolean PointFlag);//whether to light the clock point ":".To take effect the next time it displays.
    void coding(int8_t DispData[]);
    int8_t coding(int8_t DispData);
    void bitDelay(void);
  private:
    uint8_t Clkpin;
    uint8_t Datapin;
};
#endif

// The top two files work with the clock.

and the other library ? the one with .setBrightness() ?

// Had to wait 5 minutes between posts and had to split into two posts as it went over 9000 characters.
// The bottom two files contain the needed setBrightness

.cpp

extern "C" {
  #include <stdlib.h>
  #include <string.h>
  #include <inttypes.h>
}

#include <TM1637Display.h>
#include <Arduino.h>

#define TM1637_I2C_COMM1    0x40
#define TM1637_I2C_COMM2    0xC0
#define TM1637_I2C_COMM3    0x80

//
//      A
//     ---
//  F |   | B
//     -G-
//  E |   | C
//     ---
//      D
const uint8_t digitToSegment[] = {
 // XGFEDCBA
  0b00111111,    // 0
  0b00000110,    // 1
  0b01011011,    // 2
  0b01001111,    // 3
  0b01100110,    // 4
  0b01101101,    // 5
  0b01111101,    // 6
  0b00000111,    // 7
  0b01111111,    // 8
  0b01101111,    // 9
  0b01110111,    // A
  0b01111100,    // b
  0b00111001,    // C
  0b01011110,    // d
  0b01111001,    // E
  0b01110001     // F
  };

static const uint8_t minusSegments = 0b01000000;

TM1637Display::TM1637Display(uint8_t pinClk, uint8_t pinDIO, unsigned int bitDelay)
{
 // Copy the pin numbers
 m_pinClk = pinClk;
 m_pinDIO = pinDIO;
 m_bitDelay = bitDelay;

 // Set the pin direction and default value.
 // Both pins are set as inputs, allowing the pull-up resistors to pull them up
    pinMode(m_pinClk, INPUT);
    pinMode(m_pinDIO,INPUT);
 digitalWrite(m_pinClk, LOW);
 digitalWrite(m_pinDIO, LOW);
}

void TM1637Display::setBrightness(uint8_t brightness, bool on)
{
 m_brightness = (brightness & 0x7) | (on? 0x08 : 0x00);
}

void TM1637Display::setSegments(const uint8_t segments[], uint8_t length, uint8_t pos)
{
    // Write COMM1
 start();
 writeByte(TM1637_I2C_COMM1);
 stop();

 // Write COMM2 + first digit address
 start();
 writeByte(TM1637_I2C_COMM2 + (pos & 0x03));

 // Write the data bytes
 for (uint8_t k=0; k < length; k++)
  writeByte(segments[k]);

 stop();

 // Write COMM3 + brightness
 start();
 writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f));
 stop();
}

void TM1637Display::clear()
{
    uint8_t data[] = { 0, 0, 0, 0 };
 setSegments(data);
}

void TM1637Display::showNumberDec(int num, bool leading_zero, uint8_t length, uint8_t pos)
{
  showNumberDecEx(num, 0, leading_zero, length, pos);
}

void TM1637Display::showNumberDecEx(int num, uint8_t dots, bool leading_zero,
                                    uint8_t length, uint8_t pos)
{
  showNumberBaseEx(num < 0? -10 : 10, num < 0? -num : num, dots, leading_zero, length, pos);
}

void TM1637Display::showNumberHexEx(uint16_t num, uint8_t dots, bool leading_zero,
                                    uint8_t length, uint8_t pos)
{
  showNumberBaseEx(16, num, dots, leading_zero, length, pos);
}

void TM1637Display::showNumberBaseEx(int8_t base, uint16_t num, uint8_t dots, bool leading_zero,
                                    uint8_t length, uint8_t pos)
{
    bool negative = false;
 if (base < 0) {
    base = -base;
 negative = true;
 }


    uint8_t digits[4];

 if (num == 0 && !leading_zero) {
 // Singular case - take care separately
 for(uint8_t i = 0; i < (length-1); i++)
 digits[i] = 0;
 digits[length-1] = encodeDigit(0);
 }
 else {
 //uint8_t i = length-1;
 //if (negative) {
 // // Negative number, show the minus sign
 //    digits[i] = minusSegments;
 // i--;
 //}
 
 for(int i = length-1; i >= 0; --i)
 {
    uint8_t digit = num % base;
 
 if (digit == 0 && num == 0 && leading_zero == false)
    // Leading zero is blank
 digits[i] = 0;
 else
    digits[i] = encodeDigit(digit);
 
 if (digit == 0 && num == 0 && negative) {
    digits[i] = minusSegments;
 negative = false;
 }

 num /= base;
 }

 if(dots != 0)
 {
 showDots(dots, digits);
 }
    }
    setSegments(digits, length, pos);
}

void TM1637Display::bitDelay()
{
 delayMicroseconds(m_bitDelay);
}

void TM1637Display::start()
{
  pinMode(m_pinDIO, OUTPUT);
  bitDelay();
}

void TM1637Display::stop()
{
 pinMode(m_pinDIO, OUTPUT);
 bitDelay();
 pinMode(m_pinClk, INPUT);
 bitDelay();
 pinMode(m_pinDIO, INPUT);
 bitDelay();
}

bool TM1637Display::writeByte(uint8_t b)
{
  uint8_t data = b;

  // 8 Data Bits
  for(uint8_t i = 0; i < 8; i++) {
    // CLK low
    pinMode(m_pinClk, OUTPUT);
    bitDelay();

 // Set data bit
    if (data & 0x01)
      pinMode(m_pinDIO, INPUT);
    else
      pinMode(m_pinDIO, OUTPUT);

    bitDelay();

 // CLK high
    pinMode(m_pinClk, INPUT);
    bitDelay();
    data = data >> 1;
  }

  // Wait for acknowledge
  // CLK to zero
  pinMode(m_pinClk, OUTPUT);
  pinMode(m_pinDIO, INPUT);
  bitDelay();

  // CLK to high
  pinMode(m_pinClk, INPUT);
  bitDelay();
  uint8_t ack = digitalRead(m_pinDIO);
  if (ack == 0)
    pinMode(m_pinDIO, OUTPUT);


  bitDelay();
  pinMode(m_pinClk, OUTPUT);
  bitDelay();

  return ack;
}

void TM1637Display::showDots(uint8_t dots, uint8_t* digits)
{
    for(int i = 0; i < 4; ++i)
    {
        digits[i] |= (dots & 0x80);
        dots <<= 1;
    }
}

uint8_t TM1637Display::encodeDigit(uint8_t digit)
{
 return digitToSegment[digit & 0x0f];
}

.h

//  Author: avishorp@gmail.com
#ifndef __TM1637DISPLAY__
#define __TM1637DISPLAY__

#include <inttypes.h>

#define SEG_A   0b00000001
#define SEG_B   0b00000010
#define SEG_C   0b00000100
#define SEG_D   0b00001000
#define SEG_E   0b00010000
#define SEG_F   0b00100000
#define SEG_G   0b01000000

class TM1637Display {

public:
  //! Initialize a TM1637Display object, setting the clock and
  //! data pins.
  //!
  //! @param pinClk - The number of the digital pin connected to the clock pin of the module
  //! @param pinDIO - The number of the digital pin connected to the DIO pin of the module
  TM1637Display(uint8_t pinClk, uint8_t pinDIO);
  
  //! Sets the brightness of the display.
  //!
  //! The setting takes effect when a command is given to change the data being
  //! displayed.
  //!
  //! @param brightness A number from 0 (lowes brightness) to 7 (highest brightness)
  void setBrightness(uint8_t brightness);
 
  void setColon ( bool colon);
  //! Display arbitrary data on the module
  //!
  //! This function receives raw segment values as input and displays them. The segment data
  //! is given as a byte array, each byte corresponding to a single digit. Within each byte,
  //! bit 0 is segment A, bit 1 is segment B etc.
  //! The function may either set the entire display or any desirable part on its own. The first
  //! digit is given by the @ref pos argument with 0 being the leftmost digit. The @ref length
  //! argument is the number of digits to be set. Other digits are not affected.
  //!
  //! @param segments An array of size @ref length containing the raw segment values
  //! @param length The number of digits to be modified
  //! @param pos The position from which to start the modification (0 - leftmost, 3 - rightmost)
  void setSegments(const uint8_t segments[], uint8_t length = 4, uint8_t pos = 0);
  
  //! Displayes a decimal number
  //!
  //! Dispalyes the given argument as a decimal number
  //!
  //! @param num The number to be shown
  //! @param leading_zero When true, leading zeros are displayed. Otherwise unnecessary digits are
  //!        blank
  //! @param length The number of digits to set. The user must ensure that the number to be shown
  //!        fits to the number of digits requested (for example, if two digits are to be displayed,
  //!        the number must be between 0 to 99)
  //! @param pos The position least significant digit (0 - leftmost, 3 - rightmost)
  void showNumberDec(int num, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);
  
  //! Translate a single digit into 7 segment code
  //!
  //! The method accepts a number between 0 - 15 and converts it to the
  //! code required to display the number on a 7 segment display.
  //! Numbers between 10-15 are converted to hexadecimal digits (A-F)
  //!
  //! @param digit A number between 0 to 15
  //! @return A code representing the 7 segment image of the digit (LSB - segment A;
  //!         bit 6 - segment G; bit 7 - always zero)
  uint8_t encodeDigit(uint8_t digit);

protected:
   void bitDelay();
   
   void start();
   
   void stop();
   
   bool writeByte(uint8_t b);
   
private:
 uint8_t m_pinClk;
 uint8_t m_pinDIO;
 uint8_t m_brightness;
 bool m_colon;
};

#endif // __TM1637DISPLAY__

E_Lovelace:
// Had to wait 5 minutes between posts and had to split into two posts as it went over 9000 characters.
// The bottom two files contain the needed setBrightness

Only another 92 posts to go.. Anyway i think tomorrow morning i can have go. I don't have the hardware, but i can see if it will compile. You'll have to do the final testing.

Actually i think i have a solution for you today. in the TM1637.cpp i found the following function

void TM1637::set(uint8_t brightness,uint8_t SetData,uint8_t SetAddr)
{
  Cmd_SetData = SetData;
  Cmd_SetAddr = SetAddr;
  Cmd_DispCtrl = 0x88 + brightness;//Set the brightness and it takes effect the next time it displays.
}

now i think i we create a function like this in there

void TM1637::setBrightness(uint8_t brightness, bool on)
{
  brightness=brightness & 0x07;  // limit the value
  if (on) brightness | 0x08;  // on sets bit 3
  Cmd_DispCtrl = 0x80 + brightness;//Set the brightness and it takes effect the next time it displays.
}

bit 0-2 are the value bit 3 is the on off switch

and then add to TM1637.h the prototypevoid setBrightness(uint8_t brightness, bool on);

now you can call .setBrightness(value 0-7, on true/false);