Pages: 1 2 [3] 4   Go Down
Author Topic: Help me for solve my code  (Read 2071 times)
0 Members and 1 Guest are viewing this topic.
East Anglia (UK)
Online Online
Faraday Member
**
Karma: 90
Posts: 3511
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
     {for(j=0;j<1;j++)
Why ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:


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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Finland
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Quote
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..
« Last Edit: February 23, 2013, 04:19:31 am by Chaul » Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Quote
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
Logged

Finland
Offline Offline
Jr. Member
**
Karma: 1
Posts: 84
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi all again smiley-razz
I have new problem

Previously I use Vin 5 Volt ,pin3 on board arduino Uno to command in this code for working
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
    }

}


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)
Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 90
Posts: 3511
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
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.
Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 90
Posts: 3511
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So the Arduino is powered via USB and the relay board is powered by a separate power supply.
Are the grounds of the two supplies connected ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So the Arduino is powered via USB and the relay board is powered by a separate power supply.
Are the grounds of the two supplies connected ?
no
Arduino is powered via USB and the relay board is powered via USB too, use pin 5V on board .
Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 90
Posts: 3511
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So what is the 24V supply doing ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So what is the 24V supply doing ?
I have 24 volt supply but I want 5 V. I use zener diode regulator circuit 24 V to 5 V.
Logged

East Anglia (UK)
Online Online
Faraday Member
**
Karma: 90
Posts: 3511
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, it works if you get power from the USB for both boards, but not if you use the 24V supply reduced to 5V by a Zener diode.  Are you sure that you are actually getting 5V all the time.  Is there any other form of regulation on the supply other than the Zener ?
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Offline Offline
Newbie
*
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

So, it works if you get power from the USB for both boards, but not if you use the 24V supply reduced to 5V by a Zener diode.  Are you sure that you are actually getting 5V all the time.  Is there any other form of regulation on the supply other than the Zener ?

yep i sure i measure zener board 4.9 V when connect remain 4.7 V it's ok for volt but program doesn't work !!!

I measure Volt on UNO board 5 V remain 4.5 V it's work

HELP ME ??
Logged

Pages: 1 2 [3] 4   Go Up
Jump to: