For a project I want to make a countdown timer with a 4 digit 7 segments display, so I found this tutorial on Youtube. The timer is working, but the two colon dots aren't working. Anyone who knows how to fix this?
#include <Arduino.h>
#include <TM1637Display.h>
#define CLK 2
#define DIO 3
#define numberOfSeconds(time) ((time / 1000) %60)
#define numberOfMinutes(time) (((time / 1000) / 60) % 60)
TM1637Display display(CLK, DIO);
const uint8_t OFF[] = {0, 0, 0, 0};
const uint8_t PLAY[] = {B01110011, B00111000, B01011111, B01101110};
// 1000ms in 1sec, 60secs in 1 min, 60mins in 1hr. So, 1000x60x60 = 3600000ms = 1hr
unsigned long timeLimit = 1800000;
void setup() {
- Serial.begin(9600);*
- display.setBrightness(0x0A);*
- display.setSegments(OFF);*
}
void loop() {
- //displayText();*
- countdown();*
}
void displayText() {
- display.setSegments(PLAY);*
- delay(2000);*
}
void countdown() {
- unsigned long timeRemaining = timeLimit - millis();*
- while (timeRemaining > 0) {*
- int seconds = numberOfSeconds(timeRemaining);*
- int minutes = numberOfMinutes(timeRemaining);*
- display.showNumberDecEx(seconds, 0, true, 2, 2);*
- display.showNumberDecEx(minutes, 0x80 >> 3, true, 2, 0);*
- timeRemaining = timeLimit - millis();*
- }*
}
Everywhere on the internet I read that these lines of code can fix it:
uint8_t segto;
int value = 1244;
segto = 0x80 | display.encodeDigit((value / 100)%10);
display.setSegments(&segto, 1, 1);
But I really don't know what to do with it and how that code works...
Who can help me?
I'm using this display from Aliexpress: https://www.aliexpress.com/item/Free-shipping-4-digital-display-with-adjustable-brightness-LED-module-clock-Point-Accessories-Blocks-for-arduino/1961805015.html?spm=a2g0s.9042311.0.0.3da24c4dj4MuW5
From the TM1637Display.h file showing the syntax for the showNumberDecEx function.
@param num The number to be shown
//! @param dots Dot/Colon enable. The argument is a bitmask, with each bit corresponding to a dot
//! between the digits (or colon mark, as implemented by each module). i.e.
//! For displays with dots between each digit:
//! * 0.000 (0b10000000)
//! * 00.00 (0b01000000)
//! * 000.0 (0b00100000)
//! * 0.0.0.0 (0b11100000)
//! For displays with just a colon:
//! * 00:00 (0b01000000)
//! For displays with dots and colons colon:
//! * 0.0:0.0 (0b11100000)
//! @param leading_zero When true, leading zeros are displayed. Otherwise unnecessary digits are
//! blank. NOTE: leading zero is not supported with negative numbers.
//! @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 of the most significant digit (0 - leftmost, 3 - rightmost)
void showNumberDecEx(int num, uint8_t dots = 0, bool leading_zero = false, uint8_t length = 4, uint8_t pos = 0);
I think that a value of 0x40 in the dots parameter will turn the colon on.
Read the how to use this forum-please read sticky to see how to post code.
Thanks a lot, it works!
I indeed need to change the 0x80 >> 3 to 0x40
display.showNumberDecEx(seconds, 0, true, 2, 2);
display.showNumberDecEx(minutes, 0x40, true, 2, 0);
PS. Sorry for not showing the code correctly 
1 Like
ilssee95:
PS. Sorry for not showing the code correctly 
OK, you figured it out now, so go back to the first post and use the "More ==> Modify" option at the bottom right corner to fix that as well.
Note that the TM1637 clock displays have only the colon attached to the third digit IIRC, no decimals.