Hi, i'm starting to think mid 50's is a little late for an old dog to learn new tricks
, having failed badly with talent and understanding today, i hope you guys can set me back on track
. My 1st self learn project is to create a timer for boxing workouts. I have 2off 7 segment displays, one counting up rounds, the other displaying seconds left in each round and in the rest periods, in between. LED's identify the present mode (box or rest), a start button kicks off the timers.
I have a 12V supply and a 12V relay driving a buzzer loud enough to be heard over music.
All is working really well with exception to my desire to initiate the buzzer at the end of each box and rest period. Using delay() messes with the timings, I have tried numerous millis() attempts both in my project code and in stand alone code, and just don’t get it ![]()
I’m hoping somone can point me in the right direction, my code is below, I’ve read reread and read again the blink without delay example along with many many other googled examples, just cant seem to translate it / them to my requirements.
I've stripped out my failed attempts and hope my annotations give clarity, I’ve commented //BUZZ where i would like to initiate the buzzer. Many thanks in advance. ![]()
Also any other coding tips appreciatively received.
/***************************************************
Boxing timer project.
Karl Smith 28/08/2025
***************************************************/
//required libraries
#include <Wire.h>
#include <Adafruit_GFX.h>
#include "Adafruit_LEDBackpack.h"
Adafruit_7segment seconds_matrix = Adafruit_7segment(); //seconds count down 4x7 segment display
Adafruit_7segment rounds_matrix = Adafruit_7segment(); //rounds count up 4x7 segment display
int boxled = 13; //box LED output pin
int restled = 12; //rest LED output pin
int start = 3; //start button input
int startled = 11; //'press start' button LED
int buzzer = 10; //buzzer relay
//***************** Timing & rounds parameters:**********************************
int boxtime = 3; // Enter length of boxing rounds in seconds
int resttime = 3; // Enter rest time between rounds in seconds
int NumRounds = 3; // Enter number of rounds
//*******************************************************************************
void setup() {
#ifndef __AVR_ATtiny85__
Serial.begin(9600);
#endif
seconds_matrix.begin(0x70); //address for seconds count down display (no links shorted)
rounds_matrix.begin(0x71); //address for rounds count up display (A0 shorted)
//initialise digital pins
pinMode(boxled, OUTPUT);
pinMode(restled, OUTPUT);
pinMode(start, INPUT_PULLUP);
pinMode(startled, OUTPUT);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, LOW); //buzzer off
}
//Box function
int box(int round) {
for (uint16_t boxcounter = boxtime; boxcounter > 0; boxcounter--) {
digitalWrite(boxled, HIGH); // Box LED on
seconds_matrix.println(boxcounter); // write seconds left of round to seconds matrix
seconds_matrix.writeDisplay();
rounds_matrix.println(round); // Write round number to rounds matrix
rounds_matrix.writeDisplay();
delay(1000); // 1000mS = 1sec
}
digitalWrite(boxled, LOW); // Box LED off
//BUZZ
}
// Rest between rounds function
void rest() {
for (uint16_t restcounter = resttime; restcounter > 0; restcounter--) {
digitalWrite(restled, HIGH); // Rest LED on
seconds_matrix.println(restcounter); //write seconds left of rest to seconds matrix
seconds_matrix.writeDisplay();
delay(1000); //1000mS = 1sec
}
digitalWrite(restled, LOW); // Box LED off
//BUZZ
}
void loop() {
digitalWrite(buzzer, LOW); //start with buzzer off
rounds_matrix.println(" "); //Clear rounds display before start
rounds_matrix.writeDisplay();
digitalWrite(startled, HIGH); // Turn 'Press start' LED on
int startrounds = digitalRead(start); //read start button
if (startrounds == LOW) {
digitalWrite(startled, LOW); // Turn 'Press start' LED off
for (uint8_t rounds = 1; rounds < NumRounds + 1; rounds++) { // count rounds
if (rounds < NumRounds) {
box(rounds);
rest();
} else if (rounds = NumRounds) {
box(rounds);
seconds_matrix.println(" "); //clear display when rounds complete
seconds_matrix.writeDisplay();
//BUZZZ
}
}
}
}
