I wish to program timer alarm every 800,1200,2000,2400 Hrs but my code count all 24 Hrs and reset.
My code
#include <LiquidCrystal.h>
int second=0, minute=0, hour=0;
int x=0;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup(){
lcd.print("load...");
delay(1000);
lcd.begin(16, 2);
lcd.setCursor(0, 1);
lcd.print(" Timer ");
}
void loop(){
static unsigned long lastTick = 0;
if (millis() - lastTick >= 1000) {
lastTick = millis();
second++;
}
// Move forward one minute every 60 seconds
if (second >= 60) {
minute++;
second = 0; // Reset seconds to zero
}
// Move forward one hour every 60 minutes
if (minute >=60) {
hour++;
minute = 0; // Reset minutes to zero
}
if (hour >=24) {
hour=0;
minute = 0;
// Reset minutes to zero
}
if (second >= 20)
{
lcd.setCursor(0, 1);
lcd.print(" MOTOR ");
}
digitalClockDisplay();
}
void printDigits(byte digits){
if(digits < 10)
lcd.print('0');
lcd.print(digits);
}
char sep()
{
x = millis()/500;
if(x%2==0)
{
lcd.print(":");
}
else{
lcd.print(" ");
}
}
void digitalClockDisplay(){
lcd.setCursor(4,0);
printDigits(hour);
sep();
printDigits(minute);
sep();
printDigits(second);
}
I try to solve program on sec to 150 but can not work
:::::::::::::::::::::::::::
// Move forward one minute every 60 seconds
if (second >= 150) {
minute++;
second = 0; // Reset seconds to zero
:::::::::::::::::::::::::;:
it 100 and than not to 150
minute++;
second = 0
Have a look at this from the readme for TimeAlarms
"Alarm.timerRepeat(Period, TimerFunction);
Description: Continuously calls user provided TimerFunction after the given period in seconds has elapsed.
Alarm.timerRepeat(Hour, Minute, Second, TimerFunction);
Description: As timerRepeat above, but period is the number of seconds in the given Hour, Minute and Second parameters"
Alarm.timerRepeat(10, 0, 0, TimerFunction); would seem to be what you want but I have not tested it.
The TimeAlarms Alarm.timerRepeat() function sets how far ahead the alarm should be triggered, not what time the alarm should be triggered. Subtle difference.
#include <LiquidCrystal.h>
int second=0, minute=0, hour=0;
int x=0;
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
void setup(){
lcd.print("load...");
delay(1000);
lcd.begin(16, 2);
lcd.setCursor(0, 1);
lcd.print(" Timer ");
}
void loop(){
static unsigned long lastTick = 0;
if (millis() - lastTick >= 1000) {
lastTick = millis();
second++;
}
// Move forward one minute every 60 seconds
if (second >= 60) {
minute++;
second = 0; // Reset seconds to zero
}
// Move forward one hour every 60 minutes
if (minute >=60) {
hour++;
minute = 0; // Reset minutes to zero
}
if (hour >=24) {
hour=0;
minute = 0;
// Reset minutes to zero
}
if (second >= 20)
{
lcd.setCursor(0, 1);
lcd.print(" MOTOR ");
}
digitalClockDisplay();
}
void printDigits(byte digits){
if(digits < 10)
lcd.print('0');
lcd.print(digits);
}
char sep()
{
x = millis()/500;
if(x%2==0)
{
lcd.print(":");
}
else{
lcd.print(" ");
}
}
void digitalClockDisplay(){
lcd.setCursor(4,0);
printDigits(hour);
sep();
printDigits(minute);
sep();
printDigits(second);
}
I edited my progeam
if (second >= 199) {
minute++;
second = 0; // Reset seconds to zero
}
it's work when count unit 199 and minute++ well done but position third is still stay but no problem because i will use it on Hrs
btw now i use arduino board model UNO R3
in my code
if (second >= 20)
{
lcd.setCursor(0, 1);
lcd.print(" MOTOR ");
}
when second >= 20 my lcd will show MOTOR but i dont know how to... use button on board for code program such
when sec > = 20 show MOTOR but when push button on board show GEAR
if (second >= 199) {
minute++;
second = 0; // Reset seconds to zero
}
Earlier in the thread you seemed to have 4 digit hours, now you have minutes with 200 seconds in them.
Do you want to
(a) display "MOTOR" after 20 seconds then wait for a button press before displaying "GEAR"
(b) display "GEAR" after 20 seconds only if the button is pressed, otherwise display "MOTOR" and ignore the button
(c) show "GEAR" at any time the button is pressed
(d) something else
You can learn to read buttons by looking at the Button example in the IDE.
if (second >= 60) {
minute++;
second = 0; // Reset seconds to zero
}
// Move forward one hour every 60 minutes
if (minute >=60) {
hour++;
minute = 0; // Reset minutes to zero
}
if (hour >=2400) {
hour=0;
minute = 0;
// Reset minutes to zero
}
i use int for this it can count to -32768 to 32767 so i count to 2400 it can ?? then my clock can count XXXX:XX:XX right?
btw
now i use arduino board model UNO R3 it has 6 buttons ,select,left,up,down,right,rst
i will use these buttons for change ALARM display
example
when time 20 sec alarm "MOTOR" but if sec > 20 and press button such as left button alarm change "GEAR"
I don't know what kind of clock you have but, you could maybe do a nested loop to give you those hours you want. But any chance does it log Days as well? instead of doing it by hours, do it by days.
We won't know until the OP replies, but I can't help feeling that there is some confusion between 2400 hours (ie midnight) and the need to allow for 24 hours in the day.
UKHeliBob:
We won't know until the OP replies, but I can't help feeling that there is some confusion between 2400 hours (ie midnight) and the need to allow for 24 hours in the day.
Yeah, the initial mention of 800,1200,2000,2400 Hrs does sound more like times in a 24-hour period rather than a 2400 hour period, but the code does definitely allow for 2400 hours rather than 24 hours. Perhaps the OP is confused about the distinction.
Hi all
I want to add code ..is
i want to use 5v from pin3, pin3=HIGH for count
if(pin3==1){
static unsigned long lastTick = 0;
if (millis() - lastTick >= 1000)
{
lastTick = millis();
second++;
}
// Move forward one minute every 60 seconds
if (second >= 60) {
minute++;
second = 0; // Reset seconds to zero
}
// Move forward one hour every 60 minutes
if (minute >=60) {
hour++;
minute = 0; // Reset minutes to zero
}
if (hour >=2500) {
hour=0;
minute = 0;
// Reset minutes to zero
}
}
it is not working my display is no counting 00:00:00 always
My goal is use 5V from pin3 order for couning if pin3 = 0v , pin3 is stop counting and if pin3 = 5V is counting.