countUpDownTimer.h > question

Hello Developers… :slight_smile:

I have a quastion about the library countupdowntimer.h

I will like to create an Egg timer with this

but how to set the “time” for example “6 minutes” with 3 buttons?

my code where I working on see below.

#include <CountUpDownTimer.h>
#include <Adafruit_SSD1306.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>

#define OLED_RESET 4
Adafruit_SSD1306 display(OLED_RESET);

CountUpDownTimer T(DOWN, LOW);
int down = 9;
int next = 8;
int up = 7;

unsigned long hrs = 0;
unsigned long mins = 0;
unsigned long secs = 0;

void setup() {
		display.begin(SSD1306_SWITCHCAPVCC, 0x3C);
		display.setTextSize(1);														// Set default font size to the smalles
		display.setTextColor(WHITE, BLACK);											// Set font to display color on black background
		display.dim(0);																// Set display to full brightness
		pinMode(down, INPUT_PULLUP);												// Set pin for time/date mode button to input
		pinMode(next, INPUT_PULLUP);												// Set pin for time/date mode button to input
		pinMode(up, INPUT_PULLUP);													// Set pin for time/date mode button to input

		T.SetTimer(0, 1, 0);

void loop() {
	T.Timer();																		// run the timer
	if (T.TimeHasChanged())															// this prevents the time from being constantly shown.
	if (T.ShowHours() == 0 && T.ShowMinutes() == 0 && T.ShowSeconds() == 0) {
		display.setCursor(10, 0);
		display.setCursor(20, 20);
		display.setTextColor(WHITE, BLACK);
		if (T.ShowHours() < 10) display.print('0');
		if (T.ShowMinutes() < 10) display.print('0');
		if (T.ShowSeconds() < 10) display.print('0');
	secs = T.ShowSeconds();

	if (digitalRead(next) == LOW)
		T.SetTimer(hrs, mins, secs);
	else if (digitalRead(up) == LOW)
	if (digitalRead(down) == LOW)
if (T.TimeHasChanged())     // are you missing a curly bracket here                        
  if (T.ShowHours() == 0 && T.ShowMinutes() == 0 && T.ShowSeconds() == 0) {
    display.setCursor(10, 0);
  {  //  this curly bracket seems misplaced
    display.setCursor(20, 20);

do you know how to set the minutes, seconds with 3 button my code does not.
and than start count down...

Have you tried the Examples of countupdowntimer Library?


They show you how to use the library.
Get that working with serial monitor before playing around with fancy displays.

Program in stages, getting each of those stages working before going onto the next.

Tom.... :slight_smile:

Yes I used the examples in the library and that works fine.

I see the time on my Oled and its working when I set this in my code: T.SetTimer(0, 1, 0);

its going from 59 to 0 but how to set the time with the 3 buttons? manualy.

sorry my last post is about my own code

but the examples in the library is working fine but there is no option about set the time manualy
with 3 buttons.


There are many many devices (e.g clocks in cars) that set times with small number of buttons. Some re easier to use than others. Have a play with some of them.
A simple-to-program solution would be to dedicate one button to 'mode change', one button to 'up' and one to 'down'. The mode change button would scroll through several states: e.g. change hours, change minutes, change seconds. Up down buttons would change each depending on the mode button. Then, perhaps, a long press on the mode button would set the clock running when the time has been correctly set.


nice story but now to make it in an Arduino sketch I ask a question how to.

my code is playing from 59 to 0 sec but I will like to set the sec/min with 3 buttons

have someone an example with the countupdowntimer.h lib.....

SOLVED it’s working now.

I can now set the time and start to countdown.