#include "SevenSegmentTM1637.h"
// #include "SevenSegmentExtended.h"
#include "OneButton.h"
#define PIN_INPUT 9
#define PIN_LED 13
const byte PIN_CLK = 2; // define CLK pin (any digital pin)
const byte PIN_DIO = 3; // define DIO pin (any digital pin)
int hours, minutes, seconds;
bool db = true;
bool timeEdit = false;
char time[5] = "0000";
int ledState = LOW;
SevenSegmentTM1637 display(PIN_CLK, PIN_DIO);
OneButton button(PIN_INPUT, true, true);
unsigned long prevMillis = 0;
const unsigned long interval = 1000;
void setup() {
Serial.begin(9600); // initializes the Serial connection @ 9600 baud
display.init(); // initializes the display
display.setBacklight(100); // set the brightness to 100 %
sscanf(__TIME__, "%d:%d:%d", &hours, &minutes, &seconds);
pinMode(PIN_LED, OUTPUT); // sets the digital pin as output
digitalWrite(PIN_LED, ledState);
// setup OneButton
button.attachDoubleClick(doubleClick);
button.isLongPressed();
button.attachClick(oneClick);
}
void loop() {
unsigned long currentMillis = millis();
button.tick(); // Kontrola tlačidla
if (currentMillis - prevMillis >= interval) {
prevMillis = currentMillis;
db = !db;
display.setColonOn(db);
sprintf(time, "%02d%02d", hours, minutes);
display.print(String(time)); // display time
Serial.println(time);
seconds++;
if (seconds >= 60) {
seconds = 0;
minutes++;
if (minutes >= 60) {
minutes = 0;
hours++;
if (hours >= 24) {
hours = 0;
}
}
}
}
}
void doubleClick() {
timeEdit = !timeEdit;
Serial.println(timeEdit);
display.blink(100, 3);
ledState = !ledState; // reverse the LED
digitalWrite(PIN_LED, ledState);
Serial.println("x2");
}
void oneClick() {
Serial.println("x1");
ledState = !ledState; // reverse the LED
digitalWrite(PIN_LED, ledState);
if (timeEdit == true) {
seconds = 0;
minutes++;
if (minutes >= 60) {
minutes = 0;
hours++;
if (hours >= 24) {
hours = 0;
}
}
}
}
void LongPress() {
Serial.println("x1");
ledState = !ledState; // reverse the LED
digitalWrite(PIN_LED, ledState);
if (timeEdit == true) {
seconds = 0;
minutes++;
if (minutes >= 60) {
minutes = 0;
hours++;
if (hours >= 24) {
hours = 0;
}
}
}
}