@jobi-Wan: yes, mine is the same. Brightness is 0,8-15 where 11/12-14 are not distinguishable so enough is 0,8,9,10,12,15 in total.
@Sand_r: I made similarly but more flexible (I think). Your solution works only if You use showNumberDec which means You can not independently switch colon on/off and You need to write at least 2 chars to module.
To allow colon behave independent requires remembering segment layout for digit #2.
Chages:
TM1637Display.h:
private:
uint8_t m_pinClk;
uint8_t m_pinDIO;
uint8_t m_brightness=0x0f; // max default
bool m_colon=false; // colon flag
// === mod by Ramotny
uint8_t m_digit[1]; // 1 element array to store 2nd digit segments layout for colon on/off
/* colon can be toggled without storing 2nd digit somewhere in main sketch and rewriting digit by main loop */
TM1637Display.cpp
void TM1637Display::setColon(bool colon)
{
m_colon = colon;
// === mod by Ramotny
// force immediate effect of colon state
setSegments(m_digit,1,1); // m_digit stores segment layout from last write
}
and
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++)
{
// === mod by Ramotny
if (k+pos==1) //second digit access
{
m_digit[0]=segments[k]; //store segment #2 layout
if (m_colon) // detect colon on/off
{
writeByte(segments[k] | 0x80); // set MSB = colon ON
}
else
{
writeByte(segments[k] & 0x7f); // reset MSB = colon OFF
}
}
else
{
// === end of mod by Ramotny
writeByte(segments[k]); //original version, normal write as-is
}
}
stop();
// Write COMM3 + brightness
start();
writeByte(TM1637_I2C_COMM3 + (m_brightness & 0x0f));
stop();
}
example: TM1637_stopwatch
//at 500ms setting internal "clock" arduino error: circa 3'40" late per 8 hours (0.5 sec/min)
#include <Arduino.h>
#include <TM1637Display.h>
/*
simple stopwatch to demonstrate colon toggle without explicitly rewriting digit #2
digits of minutes and second are written only when changed
colon changes independently
*/
// Module connection pins (Digital Pins)
#define CLK 2
#define DIO 3
byte dummy0 = 0; //error elimination "collect2.exe: error: ld returned 5 exit status"
byte dummy1 = 0;
byte dummy2 = 0;
byte dummy3 = 0;
byte dummy4 = 0;
byte dummy5 = 0;
byte dummy6 = 0;
byte dummy7 = 0;
byte dummy8 = 0;
byte dummy9 = 0;
TM1637Display display(CLK, DIO);
unsigned long czas; // milliseconds holder
unsigned long czasold; // old milliseconds holder
int sek = 0; // second holder
int mins = 0; // minutes holder
bool tick = false; // colon flag
void setup()
{
display.setBrightness(0x0a); // set medium
czasold = millis(); // store start "time"
display.showNumberDec(mins, true, 2, 0); // initialize mins display
display.showNumberDec(sek, true, 2, 2); // initialize sec display
}
void loop()
{
czas = millis(); // get current "time"
if (czas - czasold > 496) // tic-tac each 1/2 sec
{
czasold = czas; // store new "time"
display.setColon(tick); // display colon
if (tick) // colon ON = increment seconds
{
sek++;
if (sek > 59) // if 60 sec, increment minutes
{
sek = 0;
mins++;
if (mins > 59) // if 60 minutes, increment hours
{
mins = 0; // start from 00:00 again. May add here hour counter
}
display.showNumberDec(mins, true, 2, 0);
}
display.showNumberDec(sek, true, 2, 2);
}
tick = !tick; // toggle colon on/off
}
}
All files attached (ZIP has .h and .cpp)
TM1637Display.zip (3.88 KB)
TM1637_stopwatch.ino (1.76 KB)