Hi, I am working on to make a count-up stopwatch for my physical experiment. This is my first arduino project which is so exciting but also nervous about it. My research experiment is going to be more than 400 hours, and I would like to make "HHH:MM:SS" format stopwatch. It would be great if I can control this stopwatch through "Serial Monitor" & "Bluetooth" + "64X16 doubled height display" since it will be difficult to access to stopwatch during my experiment.
But since I am new to this Arduino world, I would like to start with a simple and easy timer project and move forward from there.
I'm currently dealing with Arduino UNO controller, MAX7219 display, Parola library. A simple counter practice was successful only with seconds. However, I'm having trouble with HHH:MM:SS format timer and would like to have suggestion for this code. I tried this but code is not stable and timer seems off by few seconds.
I would like to hear any suggestion with this code! Thanks in advace!
Here is my code:
#include <MD_MAX72xx.h>
#include <MD_Parola.h>
#include <SPI.h>
//#include "Font_Data.h"
//#include <LibPrintf.h>
#define MAX_DEVICES 8
#define CS_PIN 10
#define CLK_PIN 13
#define DATA_PIN 11
#define HARDWARE_TYPE MD_MAX72XX::FC16_HW
MD_Parola P = MD_Parola(HARDWARE_TYPE, DATA_PIN, CLK_PIN, CS_PIN, MAX_DEVICES);
char Buffer[3] = " "; // create a buffer to hold the numbers
int seconds = 00; // the counter will start from 0 you can set any value
int minutes = 00;
int hours = 00;
//unsigned long startTime = 0;
//unsigned long elapsedTime = 0;
void setup() {
Serial.begin(9600);
P.begin();
P.setIntensity(4);
}
void loop() {
if (P.displayAnimate()) {
sprintf(Buffer, "%03u:%02u:%02u", hours, minutes, seconds);
P.displayText(Buffer, PA_RIGHT, 0, 0, PA_PRINT, PA_NO_EFFECT);
seconds++;
delay(1000);
}
if (seconds == 61) {
seconds = 00;
minutes++;
seconds++;
}
if (minutes >= 60) {
minutes = 0;
hours++;
seconds++;
}
if (hours == 400) {
hours = 0;
}
if (P.displayAnimate()) {
sprintf(Buffer, "%03u:%02u:%02u", hours, minutes, seconds);
P.displayText(Buffer, PA_CENTER, 0, 0, PA_PRINT, PA_NO_EFFECT);
delay(1000);
}
}





