A delay problem

Well I have been fighting this all day and can't seem to get it. What I am trying to accomplish is to pass an integer from one function to another function and update a delay time Just one of the many I have. Problem is if I put in a for loop the code automatically starts. So I know I am doing something wrong. I know I could get it by adding if statements throughout the code but by golly do I ever have a lot of those.Problem with being a noob I guess.. S I want to pass a number from this function

void setDel (int Del)
{
  if (Del ==1)
  {
  lcd.setCursor (5,0);
  lcd.print ("1.15 Sec");
  }


  else if (Del ==2)
  {
  lcd.setCursor (5,0);
  lcd.print ("1.25 Sec");
  }

to this function

// determine if  start button3 is high or low
int setState ()
{
  int d;
  
      if ((scrPer == 1) && (scrTime==1)&& digitalRead(BUTTON3)==HIGH)
{
      digitalWrite (rel,HIGH);
      delay (d);    // <--- This is where I want to declare the new time
      digitalWrite (rel,LOW);
      analogWrite (sol,25);
      delay (100);
      analogWrite (sol,50);
      delay (100);
      analogWrite (sol,75);
      delay (100);
      analogWrite (sol,100);
      delay (100);
      analogWrite (sol,125);
      delay (100);
      analogWrite (sol,150);
      delay (100);
      analogWrite (sol,175);
      delay (100);
      analogWrite (sol,200);
      delay (100);
      analogWrite (sol,225);
      delay (100);
      analogWrite (sol,250);
      delay (5000);
      analogWrite (sol,LOW);
}

these are just one of many if statements.... this code compiles.... I read someones tag and it said to look at what you last did for the error.so the attached code is the last point that the program worked the way I wanted it.... advice? should I be fighting with a loop or sticking with if else? Thanks for your time

today.ino (69.7 KB)

  int d;
  
      if ((scrPer == 1) && (scrTime==1)&& digitalRead(BUTTON3)==HIGH)
{
      digitalWrite (rel,HIGH);
      delay (d);    // <--- This is where I want to declare the new time

So, how long is this supposed to delay? In other words, what value does d contain? You haven't a clue, do you?

from here

void setDel (int Del)
{
  if (Del ==1)
  {
  lcd.setCursor (5,0);
  lcd.print ("1.15 Sec");
  }

I want to end up passing delay(1150) ie 1.15 seconds
I haven't a clue really where to go from here but I am trying

I want to end up passing delay(1150) ie 1.15 seconds

You can't pass a function call. You could pass a parameter, but setDel() doesn't appear to call setState().

What you have now is an uninitialized local variable that contains who knows what being used in the call to delay().

before your setup() you want to declare your timeofdelay ie

int timeofdelay = 1500;
[\code]

in your

[code]
if (Del ==1)
  {
  lcd.setCursor (5,0);
  lcd.print ("1.15 Sec");
  timeofdelay = 1150
  }
 int d; // you don't want to initialize it here because then it becomes a new variable and not using the global one
  
      if ((scrPer == 1) && (scrTime==1)&& digitalRead(BUTTON3)==HIGH)
{
      digitalWrite (rel,HIGH);
      delay (timeofdelay);    // <--- This is where I want to declare the new time

[/code]

Nice Guys thanks.... I will try that and let you know...

This will stay in the memory banks :smiley:

Keith

Works perfect..... seemed so easy when I typed it in and felt like banging my head on the wall... :smiley:

My son will be happy it is for his go kart racer..

Take care....i'll be reading in the background learning something

Keith

This will stay in the memory banks

Better back it up.