Hi all, so this project is a first for me and I'm a little bit stumped on getting it going, I've never dealt with proper countdown timers much, except for basic ones that use the length of the loop for timing. I've looked at quite a few projects but haven't seen anything that's easy to use the code from.
I have a 6 section 7 segment display that uses a tm1637 chip, and found a library that makes using that easy, and a matrix keypad that I salvaged and got working, and the goal is to have the user set the timer in hours, minutes and seconds, updating the display with each keypress.
Then it will wait for a key press, probably the # key, and once that happens it counts down constantly updating the 7 segment display.
I want to have it so that if the timer is set with something one hour or over, it's formatted as such:
HH MM SS
but then when it drops below one hour, it switches to
HH MM MS
so that you get a nicely animated countdown. From other projects I've read threads on, it's not necessarily possible to accurately count every single milisecond, but if it was 5 miliseconds at a time that would be plenty
In the main loop I'll monitor a switch input, and if it's triggered then pause the timer and switch to a different section that alternates the display on and off with the remaining time, that should be easy enough to set, the timer code itself is where I'm really stuck, and hopefully once I have a basic set up for that I can make progress quickly.
Here's my code , nothing much really but shows the structure I want.
#include <Keypad.h>
#include <Arduino.h>
#include <TM1637TinyDisplay6.h>
// Module connection pins (Digital Pins)
#define CLK 10
#define DIO 11
const byte ROWS = 4;
const byte COLS = 3;
char hexaKeys[ROWS][COLS] = {
{'1', '2', '3'},
{'4', '5', '6'},
{'7', '8', '9'},
{'*', '0', '#'}
};
byte rowPins[ROWS] = {2, 3, 4, 5};
byte colPins[COLS] = {6, 7, 8};
Keypad customKeypad = Keypad(makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
TM1637TinyDisplay6 display(CLK, DIO);
//timer stuff
int time_s = 0;
int time_m = 0;
int time_h = 0;
int set = 0;
int flag1=0, flag2=0;
//timer stuff
void setup(){
Serial.begin(9600);
display.setBrightness(BRIGHT_LOW);
display.clear();
display.showString("rEADY");
delay(1000);
settimer();
}
void loop(){
//update time on display
//check switch input, if low go to function that flashes remaining time.
}
void settimer(){
//set hours
//set minutes
//set seconds
//wait for keypress to go to loop
char customKey = customKeypad.getKey();
if (customKey == #){
Serial.println(customKey);
}
}
void timerstopped(){
//stop timer
//trigger output
//blink display on/off with a while statement
}
having it beep every 10 seconds with a peizo buzzer, and once per second when it's down to 30 seconds is also part of it but I think I should be able to figure that out once I have the timer set up and working.