/**
www.ArduinoNa.com
ในตัวอย่างนี้ใช้ Library ของคุณ Avishay Orpaz ซึ่งสามารถเพิ่มได้จาก
Arduino IDE -> Tools -> Manage Libraries -> พิมพ์ว่า TM1637
เลือก TM1637 by Avishay Orpaz
**/
#include <TM1637Display.h>
const int CLK = 2; // ขา CLK
const int DIO = 3; // ขา DIO
TM1637Display display(CLK, DIO);
void setup() {
Serial.begin(9600);
display.setBrightness(0x0f); // ความสว่างสูงสุด
}
void loop() {
// ดึงเวลาจาก millis() แล้วแปลงเป็นนาทีและวินาที
unsigned long currentMillis = millis();
int totalSeconds = currentMillis / 1000;
int minutes = (totalSeconds / 60) % 100; // จำกัดให้ไม่เกิน 99 นาที
int seconds = totalSeconds % 60;
char buffer[6]; // สร้างบัฟเฟอร์ที่มีขนาด 6 อักขระ จำกัดความยาวสูงสุด 5 อักขระ (เผื่อ \0)
snprintf(buffer, sizeof(buffer), "%02d:%02d", minutes, seconds);
Serial.println(buffer);
// สร้างตัวเลขแบบ MMSS
int timeToDisplay = minutes * 100 + seconds;
// แสดงเวลา พร้อมจุดคั่นกลาง
display.showNumberDecEx(timeToDisplay, 0b01000000, true);
delay(1000); // อัปเดตทุกวินาที
}