Excellent!
Does this also work?
#define SIZEOF_ARRAY(ARRAY) (sizeof(ARRAY) / sizeof(ARRAY[0]))
// CONSTANTS
const uint8_t pinBUTTON_LIGHTS = 0; // SYNONYM ENHANCES READABILITY
const uint8_t pinBUTTON_MINUTES = 19; // SYNONYM ENHANCES READABILITY
const uint8_t pinBUTTON_HOURS = 14; // SYNONYM ENHANCES READABILITY
const uint8_t LED_OFF = LOW; // SYNONYM ENHANCES READABILITY
const uint8_t LED_ON = HIGH; // SYNONYM ENHANCES READABILITY
const uint8_t BUTTON_UP = LOW; // SYNONYM ENHANCES READABILITY
const uint8_t BUTTON_DOWN = HIGH; // SYNONYM ENHANCES READABILITY
const uint8_t pinsLED[] = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 };
const uint8_t pinsMinutesOnesLEDS[] = { 1, 2, 3, 4 };
const uint8_t pinsMinutesTensLEDS[] = { 5, 6, 7 };
const uint8_t pinsHoursOnesLEDS[] = { 8, 9, 10, 11 };
const uint8_t pinsHoursTensLEDS[] = { 12, 13 };
int second; // GLOBAL ZERO'D BY COMPILER <-uint8_t to int
int minute; // GLOBAL ZERO'D BY COMPILER <-uint8_t to int
int hour; // GLOBAL ZERO'D BY COMPILER <-uint8_t to int
void setDigits(uint8_t digit, const uint8_t pinsLED[], uint8_t lengthArray)
{
for ( int i = lengthArray; i--; )
{
digitalWrite(pinsLED[i], ((digit & (1 << i)) ? LED_ON : LED_OFF));
}
}
void loop()
{
// static variables are initialized once and keep their values between function calls
// set up a local variable to hold the last time we moved forward one second
static unsigned long lastTick = 0UL;
if ( (millis() - lastTick) >= 1000UL )
{
lastTick = millis();
if ( 0 == (second = ((++second) % 60)) )
{
if ( 0 == (minute = ((++minute) % 60)) )
{
hour = ((++hour) % 24);
}
}
}
if ( BUTTON_DOWN == digitalRead(pinBUTTON_LIGHTS) )
{
for ( int i = SIZEOF_ARRAY(pinsLED); i--; )
{
digitalWrite(pinsLED[i], LED_OFF);
}
}
else
{
setDigits((minute / 10), pinsMinutesOnesLEDS, SIZEOF_ARRAY(pinsMinutesOnesLEDS)); // minutes ones
setDigits((minute % 10), pinsMinutesTensLEDS, SIZEOF_ARRAY(pinsMinutesTensLEDS)); // minutes tens
setDigits((hour / 10), pinsHoursOnesLEDS, SIZEOF_ARRAY(pinsHoursOnesLEDS)); // hours ones
setDigits((hour % 10), pinsHoursTensLEDS, SIZEOF_ARRAY(pinsHoursTensLEDS)); // hours tens
}
if ( BUTTON_DOWN == digitalRead(pinBUTTON_MINUTES) )
{
minute++;
second = 0;
delay(250);
}
if ( BUTTON_DOWN == digitalRead(pinBUTTON_HOURS) )
{
hour++;
second = 0;
delay(250);
}
}
void setup()
{
pinMode(pinBUTTON_MINUTES, INPUT);
pinMode(pinBUTTON_HOURS, INPUT);
for ( int i = SIZEOF_ARRAY(pinsLED); i--; )
{
pinMode(pinsLED[i], OUTPUT);
}
}
EDIT: Changed data type of 'second', 'minute' and 'hour'