Trying to copy and past code to make something new

I think I copied and pasted the right parts into the right files.

Getting the error,

C:\Users\E___\AppData\Local\Temp\ccT4C1be.ltrans0.ltrans.o: In function `setup':

F:\Arduino_Bits\sketch_dec14b/sketch_dec14b.ino:25: undefined reference to `TM1637::set(unsigned char, unsigned char, unsigned char)'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Nano.

so all together the new library will come to this, with a new name and update reference to the .h file with it's new header. Test it please.

TM1637wb.zip (2.12 KB)

E_Lovelace:
I think I copied and pasted the right parts into the right files.

Getting the error,

C:\Users\E___\AppData\Local\Temp\ccT4C1be.ltrans0.ltrans.o: In function `setup':

F:\Arduino_Bits\sketch_dec14b/sketch_dec14b.ino:25: undefined reference to `TM1637::set(unsigned char, unsigned char, unsigned char)'

collect2.exe: error: ld returned 1 exit status

exit status 1
Error compiling for board Arduino Nano.

No i think you've changed the .set() into the .setBrightness(), you should leave the .set() as it is.

Deva_Rishi:
so all together the new library will come to this, with a new name and update reference to the .h file with it's new header. Test it please.

How many levels of brightness will this new lib give? At the moment I can get 7 different levels from the display with my test code.

I need to get to bed now, but will add the brightness control code tomorrow and let you know how we get on.

E_Lovelace:
How many levels of brightness will this new lib give? At the moment I can get 7 different levels from the display with my test code.

The same or actually you could get 8 levels, from 0-7, and now you should be able to turn it on & off as well

I'm not sure if I have integrated the code correctly of it is a limitation with the library used.

#include <TM1637wb.h>

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

#define CLK 9
#define DIO 8

TM1637 Display1(CLK, DIO);
int Brightness = 2;      // starting brightness

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

  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();

    // 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
  
}

void loop() {
  // Process button presses
  if (brightnessUp.update()) {
    if (Brightness < 7) {
      Brightness += 1;
    }
    Display1.Brightness( Brightness );
  }
  if (brightnessDown.update()) {
    if (Brightness > 0) {
      Brightness -= 1;
    }    
    Display1.setBrightness( Brightness );
  }  
  
  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);
   }

Error:

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

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

Clock_Forum:48:14: error: 'class TM1637' has no member named 'Brightness'

     Display1.Brightness( Brightness );

              ^

Clock_Forum:54:40: error: no matching function for call to 'TM1637::setBrightness(int&)'

     Display1.setBrightness( Brightness );

                                        ^

In file included from F:\Arduino_Bits\Clock_Forum\Clock_Forum.ino:1:0:

F:\Arduino_Bits\libraries\TM1637wb/TM1637wb.h:33:10: note: candidate: void TM1637::setBrightness(uint8_t, bool)

     void setBrightness(uint8_t brightness, bool on);

          ^

F:\Arduino_Bits\libraries\TM1637wb/TM1637wb.h:33:10: note:   candidate expects 2 arguments, 1 provided

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

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

E_Lovelace:
Error:

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

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

Clock_Forum:48:14: error: 'class TM1637' has no member named 'Brightness'

Display1.Brightness( Brightness );

^

Clock_Forum:54:40: error: no matching function for call to 'TM1637::setBrightness(int&)'

Display1.setBrightness( Brightness );

^

In file included from F:\Arduino_Bits\Clock_Forum\Clock_Forum.ino:1:0:

F:\Arduino_Bits\libraries\TM1637wb/TM1637wb.h:33:10: note: candidate: void TM1637::setBrightness(uint8_t, bool)

void setBrightness(uint8_t brightness, bool on);

^

F:\Arduino_Bits\libraries\TM1637wb/TM1637wb.h:33:10: note:  candidate expects 2 arguments, 1 provided

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

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

Well darn, hey please pay attention, I called it .setBrightness() and i gave it 2 ! arguments, first the Brightness as a byte and second a bool for turning it on or off... so: Display1.setBrightness( Brightness ,true); the on-off thing is a function of the display that was previously not there stumbled on it by accident and though it did have merit.

I got this code to compile and uploaded it to the board but the display is just off and the buttons are unresponsive?

I'm sorry if I am not understanding correctly.

#include <TM1637wb.h>

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

#define CLK 9
#define DIO 8

TM1637 Display1(CLK, DIO);
int Brightness = 2;      // starting brightness

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

  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();

    // 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

  Display1.setBrightness( Brightness ,true);
}

void loop() {
  // Process button presses
  if (brightnessUp.update()) {
    if (Brightness < 7) {
      Brightness += 1;
    }
    Display1.setBrightness( Brightness ,true);
  }
  if (brightnessDown.update()) {
    if (Brightness > 0) {
      Brightness -= 1;
    }    
    Display1.setBrightness( Brightness ,true);
  }  
  
  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);
   }

hmm not sure what's going on, I'm fairly sure the setBrighness() function is correct, but what does it do when you have the calls to .setBrightness() commented out, and what does it say on your serial monitor ?

Serial monitor returns the normal RTC output

DS1307RTC Read Test
-------------------
Ok, Time = 15:16:13, Date (D/M/Y) = 15/12/2018
Ok, Time = 15:16:14, Date (D/M/Y) = 15/12/2018
Ok, Time = 15:16:15, Date (D/M/Y) = 15/12/2018

Commenting out the calls makes the clock work, without the brightness controls.

I was able to get the display working by moving the line "Display1.setBrightness( Brightness , true);" to the up of setup. When it is last, the display does not work?

 Display1.setBrightness( Brightness , true);

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

  Display1.set();
  Display1.init();
  // 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

Ah Sorry, my fault !! !! this line in the library

if (on) brightness | 0x08;  // on sets bit 3

should be

if (on) brightness=brightness | 0x08;  // on sets bit 3

i'll add the updated version (in a tick) what a goof... really after that it should work i just never turn the 'on' bit on.

TM1637wb.zip (2.12 KB)

Thank you for the help you have given me Deva_Rishi I think this project would have not got very far with out the higher help.

One small issue is the buttons are not working as they did in my test code. I have retested them with that code to make sure it was not a wiring issue.

You need to press the buttons many times to get a small increase or decrease.

This is probably down to my coding, a bracket wrong here or a line too many type of thing..

If you have the time to look over the code and any feedback or ideas are as always most welcome.

#include <TM1637wb.h>

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

#define CLK 9
#define DIO 8

TM1637 Display1(CLK, DIO);
int Brightness = 2;      // starting brightness

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

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();
  
 // 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
  
  Display1.setBrightness( Brightness ,true);
  
}

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

  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);
}

Hey the TM1637wb lib works now ? pff.. anyway i have never used the Bouce2 library, hut just looking through your main loop i see at the very end.

    }
    delay(9000);
  }
  delay(1000);
}

and for sure the last delay() gets executed every time around the loop and that should hold your button reading up a bit (1000ms to be exact) i can't really tell when the other delay(9000) get executed, i think it is part of an if-else, but the else is on a line with the closing curly-brace, so i'm not sure (just don't put anything on a line with a closing curly-brace) remove the delay(1000) i don't think it has a purpose. Also once it's working i think it is really time to clean the code up and make some functions that can be called from the main loop() to do certain things, so your main loop() will not have much more than 10 lines of code. Like this you create overview.