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.
It seems silly to store a state in a variable named pin3. It seems silly to name a variable pin3, and then store the value 1 in it. Therefore, it seems silly to expect pin3 to equal 1.
HazardsMind:
Its just pseudo code, he needs to fill in the gaps.
Using the pin number instead of the value read from the pin is a very common mistake. Even if you meant it to be pseudo code (which is not obvious, since that is syntactically valid C++) it's not doing the OP any favors by encouraging them to make that mistake.
if (minute == 1)
{
switch (lcd_key) // depending on which button was pushed, we perform an action
case btnLEFT:
{for(j=0;j<1;j++)
lcd.setCursor(0, 1);
lcd.print(" Timer ");
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
break;
}
}
i want to press hold switch LEFT for 30 sec and then it is working go on if dont press hold it can't do that.
You have to use a timer. Press the button once to start the timer and then keep it held. Using "millis() - timer > 30000UL", it will check to see if the state has changed within that period. If it DOES change within that period, it will NOT do the action. Only when the first state and second state are equal will it do the action.
if (minute == 1&&j<1)
{
switch (lcd_key) // depending on which button was pushed, we perform an action
case btnSELECT:
{for(i=0;i<1;i++)
lcd.setCursor(0, 1);
lcd.print(" MOTOR OIL ");
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
break;
}
}
if (minute == 1)
{
switch (lcd_key) // depending on which button was pushed, we perform an action
case btnLEFT:
{for(j=0;j<1;j++)
lcd.setCursor(0, 1);
lcd.print(" Timer ");
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
break;
}
}
I use "j" for checking on time t = 1 min if press button SELECT show
lcd.print(" MOTOR OIL ");
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
and then press LEFT show
lcd.print(" Timer ");
digitalWrite(led0, LOW);
digitalWrite(led1, LOW);
digitalWrite(led2, LOW);
use "j" if while min = 1 press SELECT and press LEFT and then press SELECT won't show
lcd.print(" MOTOR OIL ");
digitalWrite(led0, LOW);
digitalWrite(led1, HIGH);
digitalWrite(led2, LOW);
because j = 1
HazardsMind:
You have to use a timer. Press the button once to start the timer and then keep it held. Using "millis() - timer > 30000UL", it will check to see if the state has changed within that period. If it DOES change within that period, it will NOT do the action. Only when the first state and second state are equal will it do the action.
I didn't get your suggestion.
I want to press and hole button until 30 sec it will doing next stage command.
shitokung:
I use "j" for checking on time t = 1 min if press button SELECT show
The point is that you could replace that for "loop" with j=1 and it would do exactly the same thing, always, after the "loop" has executed. Same thing with the other loop and i=1... We don't understand why do you run the loop once.
I didn't get your suggestion.
I want to press and hole button until 30 sec it will doing next stage command.
You save the first time stamp with millis() to a variable, and then keep comparing has the 30 second or 30 000 millisecond mark been reached. When the difference is greater than the limit you proceed with the next stage. Oh, wait, I just repeated the previous answer, sorry..
shitokung:
I use "j" for checking on time t = 1 min if press button SELECT show
The point is that you could replace that for "loop" with j=1 and it would do exactly the same thing, always, after the "loop" has executed. Same thing with the other loop and i=1... We don't understand why do you run the loop once.
I didn't get your suggestion.
I want to press and hole button until 30 sec it will doing next stage command.
You save the first time stamp with millis() to a variable, and then keep comparing has the 30 second or 30 000 millisecond mark been reached. When the difference is greater than the limit you proceed with the next stage. Oh, wait, I just repeated the previous answer, sorry..
Ok thanks all for question.
This code I simulate for maintance car every 800 Hrs,1200Hrs,2000Hrs,2400Hrs but in this case i use time for easy test
I think my program it's OK but function press button it's not suitable I wan to press and hold 30 sec for working ,don't press and working