Hello! I want to make a clock. It works but i dont know how to make the colon light up.. And yes, they work. This is where i bought the display Modul LED Display Ceas | Cleste.ro ( You might not undertand what written there bcz is in romanian)
I can give you my code too...
#include <TM1637Display.h>
#define CLK_PIN 8 // Pinul conectat la pinul CLK al afișajului
#define DIO_PIN 9 // Pinul conectat la pinul DIO al afișajului
const int DIN_PIN = 2;
const int DIN2_PIN = 3;
unsigned long previousTime = 0;
const unsigned long interval = 60000; // Intervalul de timp în milisecunde (60 de secunde)
int i = 0;
TM1637Display display(CLK_PIN, DIO_PIN);
void setup(){
display.setBrightness(7); // Setarea luminozității afișajului (0-7)
pinMode(DIN_PIN, INPUT_PULLUP);
pinMode(DIN2_PIN, INPUT_PULLUP);
Serial.begin( 9600 );
previousTime = millis(); // Salvează timpul de pornire
}
void loop(){
unsigned long currentTime = millis(); // Obține timpul curent
display.showNumberDec(i, true);
int value = digitalRead(DIN_PIN);
int value2 = digitalRead(DIN2_PIN);
if (value == 0) {
i++;
delay(200);
}
if (value2 == 0) {
i += 100;
delay(200);
}
if (i % 100 / 10 == 6) {
i = (i - i % 100) + 100;
}
if (currentTime - previousTime >= interval) {
i++;
previousTime = currentTime;
}
if (i>=2359) i=0;
}
//! 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);
//! Display a decimal number, with dot control
//!
//! Display the given argument as a decimal number. The dots between the digits (or colon)
//! can be individually controlled.
//!
//! @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);
of
display.showNumberDec(i, true);
so that would be
display.showNumberDecEx(i, 0b01000000, true); // 0b01000000 = 64 or 0x40, you can use either of those as well.
at a seconds interval i presume...
simplest solution is to take the elapsed time, take the modulo 1000 of that ( % 1000) resulting in a value that has just the milliseconds, and divide that by 500, so it will be either 0 or 1, and then execute conditionally the colon showing.