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
shitokung:
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
It's up to you what you want it do after 30 seconds has passed. The hint we gave you just gives you the ability the measure that the time has passed. So, within that 30 seconds, do nothing, and after the condition returns true (> 30000UL), you do something. 30 seconds is a long time for holding a button though.
Previously I use Vin 5 Volt ,pin3 on board arduino Uno to command in this code for working
if (digitalRead(pin3) == HIGH)
{
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 >=2800) {
hour=0;
minute = 0;
// Reset minutes to zero
}
}
But Why I use other supply 5 V to command doesn't working ?
(I use 24 V drop to 5 V by regulator zener diode circuit)
When you say "other supply" do you mean that you are using 2 power supplies ?
If so, are the grounds of the 2 supplies connected ?
If that is not what you meant can you please explain more clearly ?
An explanation of how the Arduino, the power supply/supplies and pin 3 are wired would also help.
UKHeliBob:
When you say "other supply" do you mean that you are using 2 power supplies ?
If so, are the grounds of the 2 supplies connected ?
If that is not what you meant can you please explain more clearly ?
An explanation of how the Arduino, the power supply/supplies and pin 3 are wired would also help.
OK
I use Arduino Uno supply by USB computer.I connect 1 relay board and previously i use Vin on board to command code
if (digitalRead(pin3) == HIGH)
{
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 >=2800) {
hour=0;
minute = 0;
// Reset minutes to zero
}
}
It's working but
now I using 24 V supply one more (not supply arduino uno) for drop volt by regulator zener diode circuit to 5 V for use 5 V borad arduino instead
but it's not working.