Hello Developers…
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() {
Wire.begin();
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
display.invertDisplay(0);
display.clearDisplay();
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);
T.StartTimer();
}
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) {
T.StopTimer();
display.setCursor(10, 0);
display.clearDisplay();
display.print("STOP");
}
{
display.setCursor(20, 20);
display.setTextSize(2);
display.setTextColor(WHITE, BLACK);
if (T.ShowHours() < 10) display.print('0');
display.print(T.ShowHours());
display.print(":");
if (T.ShowMinutes() < 10) display.print('0');
display.print(T.ShowMinutes());
display.print(":");
if (T.ShowSeconds() < 10) display.print('0');
display.print(T.ShowSeconds());
display.display();
}
secs = T.ShowSeconds();
if (digitalRead(next) == LOW)
{
T.SetTimer(hrs, mins, secs);
T.StartTimer();
}
else if (digitalRead(up) == LOW)
{
secs++;
}
if (digitalRead(down) == LOW)
{
secs--;
}
}