/*
TM1637 CONTADOR + BOTÓN DE RESET
VERSIÓN: 1.0 (09 FEBRERO 2024)
[email protected] - https://github.com/carlymx
TINKERCAD: https://www.tinkercad.com/things/dzaGMlVHccC-temporizador-con-reset
*/
#include <TM1637Display.h> // LIB URL: https://github.com/avishorp/TM1637
#include <TimeLib.h> // LIB URL: https://github.com/PaulStoffregen/Time
#define PIN_CLK 2
#define PIN_DIO 3
#define PIN_BTN1 4
#define PAUSA 1000
uint8_t negro[] = { 0x00, 0x00, 0x00, 0x00 };
uint8_t blanco[] = { 0xff, 0xff, 0xff, 0xff };
TM1637Display display(PIN_CLK, PIN_DIO); // CREAR INSTACIA DISPLAY
void setup() {
pinMode(PIN_BTN1, INPUT);
display.setBrightness(5); // AJUSTAR BRILLO DE 0 A 7
// TEST FUNCIONAMIENTO:
for (byte i=0; i<4; i++){
display.setSegments(blanco);
delay(PAUSA/5);
display.setSegments(negro);
delay(PAUSA/5);
}
display.clear();
setTime(0,0,0,01,01,2000);
}
void loop() {
reset();
tiempo();
}
void reset() {
if (digitalRead(PIN_BTN1)==true){
display.clear();
setTime(0,0,0,01,01,2000);
}
}
void tiempo(){
time_t t = now(); // OBTIENE LA FECHA Y HORA ACTUAL
if (digitalRead(PIN_BTN1)==false){
display.showNumberDecEx(minute(t), 0b01000000, true, 2, 0); // MUESTRA LOS MINUTOS Y LOS :
display.showNumberDec(second(t), true, 2, 2); // MUESTRA LOS SEGUNDOS 01, 02... 14...
delay(PAUSA/10); // PARA NO ESCRIBIR CONSTANTEMENTE LA PANTALLA
}
}
// PRUEBAS
void contador1() {
display.showNumberDec(millis()/1000, true);
}