#include <QuadDisplay.h>
#define BUTTON_PIN 2
#define LED_PIN 3
#define DISPLAY_PIN 4
int s = 0;
unsigned long t = 0;
void setup() {
Serial.begin(9600);
pinMode(BUTTON_PIN, INPUT_PULLUP);
pinMode(LED_PIN, OUTPUT);
displayInt(DISPLAY_PIN, 0);
}
void loop() {
if (digitalRead(BUTTON_PIN) == LOW || Serial.read() == 'R') {
s = 0;
Serial.println(s);
displayInt(DISPLAY_PIN, 0);
digitalWrite(LED_PIN, LOW);
delay(500);
t = millis();
}
if (s > 0) digitalWrite(LED_PIN, HIGH);
if (millis() - t >= 1000) {
t = millis();
s++;
Serial.println(s);
displayInt(DISPLAY_PIN, (s / 60) * 100 + (s % 60));
}
}
ХУЙ
import serial
import tkinter as tk
try:
ser = serial.Serial('COM4', 9600, timeout=0.1)
except:
exit()
def update():
if ser.in_waiting:
line = ser.readline().decode().strip()
if line.isdigit():
v = int(line)
lbl.config(text=f"{v//60:02d}:{v%60:02d}")
root.after(50, update)
root = tk.Tk()
root.title("Timer")
lbl = tk.Label(root, text="00:00", font=("Arial", 60))
lbl.pack(pady=20)
tk.Button(root, text="RESET", command=lambda: ser.write(b'R'), bg="red", font=("Arial", 20)).pack()
update()
root.mainloop()