Variable Value as "delay()" parameter?

Hi guys, so I'm working on a little project at work and convinced my boss to use arduinos, long story short, im using arduino micro with a 16x2 lcd and 4 push buttons, i got everything to work the way i wanted, except for one thing, i have a variable that gets its "value" from the "pushbuttons" if button a goes "HIGH" it increases the count by 1, if button b goes "HIGH" it decreases the count by 1, i got that down, i can even display the value in real time on the LCD, the problem is that i need this value to use it as a timer to set off an alarm, i don't know how to get a hold of this value to use it as a "delay()" parameter, any way i can plug in this value to the delay parameter?

this is the portion of the code that reads the buttons to increase or decrease the count and store it on a variable:

// include the library code:
#include <LiquidCrystal.h>


// initialize the library with the numbers of the interface pins              
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);






int DELAY    =      0;    //   DELAY TO BE CHANGED BY UP/DOWN BUTTONS ON LCD  
int TIMEUP   =      A3;     //   TIME UP PUSHBUTTON                             
int TIMEDOWN =      A2;     //   TIME DOWN                                      

int TIMEUPHI   =    A5;     //SETS TIMEUP BUTTON STATE HIGH OR LOW
int TIMEDOWNHI =    A4;     //SETS TIMEDOWN BUTTON STATE HIGH OR LOW

int TIMEUPSTATE =  0;       //VARIABLE TO STORE BUTTON STATE
int TIMEDOWNSTATE = 0;      //VARIABLE TO STORE BUTTON STATE

void setup () 
{
 lcd.begin(16, 2); 
 lcd.setCursor (0, 0);
 
 lcd.print ("ALARM TIME");
 lcd.print(" ");
 //lcd.print (DELAY);
pinMode (TIMEUP, INPUT);
pinMode (TIMEDOWN, INPUT);
pinMode(TIMEUPHI, OUTPUT);
pinMode(TIMEDOWNHI, OUTPUT);

Serial.begin(9600);
}

      void loop ()

{ 
  
       TIMEUPSTATE           = digitalRead(TIMEUP);                     //READS TIMEUP PUSHBUTTON FROM LCD      
       TIMEDOWNSTATE         = digitalRead(TIMEDOWN);      //READS TIMEDOWN PUSHBUTTON FROM LCD    
       
   
       digitalWrite(TIMEUPHI, HIGH);                           // HOT END OF PUSH BUTTONS
       digitalWrite(TIMEDOWNHI, HIGH);                                       
       
       
       
       
         if (TIMEUPSTATE == HIGH)  {     //IF PUSH BUTTON TIME UP GOES HIGH INCREASES COUNT, DIVISION USED TO IMPROVE
          (++DELAY / 10000);                    //AMOUNT INCREASED PER SECOND
          lcd.setCursor(0, 1);
          lcd.print(DELAY);
          lcd.print(" ");
          lcd.print("SECONDS");
          
        
         }
         
         if (TIMEDOWNSTATE == HIGH) { 
          (--DELAY);
          lcd.setCursor(0, 1);
          lcd.print(DELAY); 
          lcd.print(" ");
          lcd.print("SECONDS ");
         
         
          }
}

SO i need to get a hold of the variable "DELAY" and use it as an actual "delay() parameter, lets say i make the variable "DELAY" 1248, id like to plug it into the parameter so it comes out like:

delay(1248);

i need to use it for the other portion of code:

if (STARTBUTTONSTATE== HIGH)                  //IF START PUSHBUTTON IS HIGH IT WAITS "X" SECONDS AND WRITES "HIGH TO THE BUZZER
        { delay(5000);    // <----SO THIS DELAY WOULD GET ITS VALUE FROM THE "DELAY" VARIABLE
          digitalWrite(BUZZER, HIGH);

Not really following.
Do you mean. delay(DELAY);

(++DELAY / 10000); 
(--DELAY);

Is equivalent to:

DELAY++; 
DELAY--;

There is a fairly widespread convention that pre-processor definitions are named in uppercase and variable names, types, functions, methods etc are defined in lower case or camel case. It doesn't affect the behaviour of the code, but I think you'll find it's easier to understand other people's code (and vice versa) if you follow the convention.

How are your buttons wired ? (Is it an LCD Button Shield (like the LinkSprite one ?)

It is difficult for me to believe that having got this far and used functions like this

lcd.print(DELAY);

that it did not occur to you to trydelay(DELAY);
unless I am not understanding what you want to do.

yes, it did occur to me to place the variable inside the "time value" of the "delay()" parameter, the compiler doesn't like it, it throws and error, it highlights that line and says "value is not ignored as is ought to be" apparently the parameter "delay()" is something you can't change like a variable, it can be replaced with another delay, but i think it cannot be changed, is really frustrating because i got all working but the most important thing

raschemmel:
How are your buttons wired ? (Is it an LCD Button Shield (like the LinkSprite one ?)

https://www.sparkfun.com/products/11851

yes, similar, this is the one i will use once i get them on the mail:

but for now i am using this one:

BlueLoneWolf:
yes, it did occur to me to place the variable inside the "time value" of the "delay()" parameter, the compiler doesn't like it, it throws and error, it highlights that line and says "value is not ignored as is ought to be" apparently the parameter "delay()" is something you can't change like a variable, it can be replaced with another delay, but i think it cannot be changed, is really frustrating because i got all working but the most important thing

Can you post a program that causes the error ? It does not have to be your full program, just one that should compile but doesn't.

That is not an error I am familiar with (and I have made plenty!). Are you using the return value from delay?

Like this: x = delay(DELAY)

delay() does not return a value.

if you print your DELAY variable on the Serial Monitor what do you get?

i know delay() does not return a value, what i'm trying to do is to "plug" a value that i store in a "variable" that i NAMED "DELAY" but i guess there's some confusion since i named it DELAY, lets call it "ALARM TIME" so anyhow, im trying to plug the value stored on the variable "ALARM TIME" and plug it into the value of the "delay()" function, regarding the serial print i forgot how to print in line, but i just added one line to the code "Serial.print(DELAY);" and it works, every time i push a button it throws me a value, thing is the value doesn't mach what i am displaying to the LCD, which would conflict since im trying to use that value as a delay and displaying it as the delay going to be used, but lets leave that detail aside for now, i would like to concentrate on getting the value from the variable "ALARM TIME" and put it inside the "delay()" function

When you actually post some code, we'll be able to help you. Meanwhile, nice dance moves.

We know what you are trying to do, but it should work with no issues. When I google your error it refers to values returned by functions, not arguments to functions.

// include the library code:
#include <LiquidCrystal.h>


// initialize the library with the numbers of the interface pins              TEST
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);


///////////////////////////////////////////////////////////////////////////////////////////////
//                                 TIMER START/STOP PORTION        
            
                                                                                          ////
int STARTBUTTONSTATE = 0;   //   VALUE TO STORE START BUTTON HIGH OR LOW                  ////
int RESETBUTTONSTATE = 0;   //   VALUE TO STORE RESET BUTTON HIGH OR LOW                  ////
 
int STARTHI =        5;     //   SETS START BUTTON STATE HIGH OR LOW          
int STARTBUTTON =    4;    //    READS START BUTTON STATE HIGH OR LOW

int RESETBUTTON =    3;     //   READS RESET BUTTON STATE HIGH OR LOW
int RESETHI =        2;     //   SETS RESET BUTTON STATE HIGH OR LOW

int BUZZER =         6;     //   BUZZER CONNECTED TO PIN 6 

////////////////////////////////////////////////////////////////////////////////////////////////
                                    
//                               TIMER SET AND DISPLAY  PORTION


[glow=yellow,2,300]int AlarmTime    =       0;      //   DELAY TO BE CHANGED BY UP/DOWN BUTTONS ON LCD  TEST[/glow]

int TIMEUP   =      A3;     //   TIME UP PUSHBUTTON                             TEST
int TIMEDOWN =      A2;     //   TIME DOWN                                      TEST

[glow=yellow,2,300]int TIMEUPHI   =    A5;     //   SETS TIMEUP BUTTON STATE HIGH OR LOW
int TIMEDOWNHI =    A4;     //   SETS TIMEDOWN BUTTON STATE HIGH OR LOW[/glow]

[glow=yellow,2,300]int TIMEUPSTATE =    0;
int TIMEDOWNSTATE =  0;[/glow]


/////////////////////////////////////////////////////////////////////////////////////////////////

void setup () 
{
 lcd.begin(16, 2); 
 lcd.setCursor (0, 0);
 
 lcd.print ("ALARM TIME");   //prints "HEAT TIME" TO LCD
 lcd.print(" ");            //PRINTS BLANK SPACE

 
 
pinMode(STARTBUTTON, INPUT);      
pinMode(RESETHI, OUTPUT);   
pinMode(BUZZER, OUTPUT);    
pinMode(RESETBUTTON, INPUT); 
pinMode(STARTHI, OUTPUT);
//////////////////////////////////////////////
[glow=yellow,2,300]pinMode (TIMEUP, INPUT);
pinMode (TIMEDOWN, INPUT);
pinMode(TIMEUPHI, OUTPUT);
pinMode(TIMEDOWNHI, OUTPUT);[/glow]

Serial.begin(9600);
}

      void loop ()

{ 
  
      STARTBUTTONSTATE = digitalRead(STARTBUTTON);   //READS PUSHBUTTON "STARTBUTTON"
       RESETBUTTONSTATE = digitalRead(RESETBUTTON);   //READS PUSHBUTTON "RESET"
       
                       // TEST VARIAVLE                        TEST
       [glow=yellow,2,300]TIMEUPSTATE           = digitalRead(TIMEUP);        //READS TIMEUP PUSHBUTTON FROM LCD      TEST
       TIMEDOWNSTATE         = digitalRead(TIMEDOWN);      //READS TIMEDOWN PUSHBUTTON FROM LCD    TEST[/glow]
       
       
       
       
        digitalWrite (RESETHI, HIGH);                 //arms reset push button
        digitalWrite (STARTHI, HIGH);                 // ARMS START BUTTON
         
        if (STARTBUTTONSTATE== HIGH)                  //IF START PUSHBUTTON IS HIGH IT WAITS "X" SECONDS AND WRITES "HIGH TO THE BUZZER
        { [glow=yellow,2,300]delay(5000);[/glow]
          digitalWrite(BUZZER, HIGH);
         }
       
        if (RESETBUTTONSTATE==HIGH)                   //IF RESET PUSHBUTTON GOES HIGH, IT SENDS THE BUZZER TO LOW STATE
        {digitalWrite (BUZZER, LOW);}
         
   //////////////////////////////////////////////////////////////////////////////////////////////////////      
         
       [glow=yellow,2,300]  TIMEUPSTATE           = digitalRead(TIMEUP);        //READS TIMEUP PUSHBUTTON FROM LCD      TEST
         TIMEDOWNSTATE         = digitalRead(TIMEDOWN);      //READS TIMEDOWN PUSHBUTTON FROM LCD    TEST
       
   
       digitalWrite(TIMEUPHI, HIGH);
       digitalWrite(TIMEDOWNHI, HIGH);                  // TEST VARIAVLE                        TEST
       
       
       
       
         if (TIMEUPSTATE == HIGH)  {
          (++AlarmTime);
          lcd.setCursor(0, 1);
          lcd.print(AlarmTime);
          lcd.print(" ");
          lcd.print("SECONDS");
          Serial.print(AlarmTime);
         }
          
          
         
         if (TIMEDOWNSTATE == HIGH) { 
          (--AlarmTime);
          lcd.setCursor(0, 1);
          lcd.print(AlarmTime); 
          lcd.print(" ");
          lcd.print("SECONDS ");
         Serial.print(AlarmTime);
          [/glow]
          }    
 
   
}

that is the whole routine for now, as you can see, the variable "AlarmTime" holds a value every time the pushbuttons "TIMEUP" AND "TIMEDOWN" are pressed, and i can see them on the serial monitor as well, I highlighted the important parts, look for this line

"

 if (STARTBUTTONSTATE== HIGH)                  //IF START PUSHBUTTON IS HIGH IT WAITS "X" SECONDS AND WRITES "HIGH TO THE              
                                                                                     //BUZZER
        { [glow=yellow,2,300]delay(5000);[/glow]
          digitalWrite(BUZZER, HIGH);}

that "delay(5000); right now i have it with a fixed value, but that is the parameter i would like to "INSERT" the "VALUE" from the variable "AlarmTime"

[glow=yellow,2,300]

Your code doesn't really contain this, does it?

Try again, without trying to color your code. You can't.

What is the correct parameter type for "delay()"?

but that is the parameter i would like to "INSERT" the "VALUE" from the variable "AlarmTime"

So, why don't you?

no, it doesn't contain that, lol, i realized about that after i made the post i was trying to highlight parts of the code but forgot that when you instert the "code command" it takes that as part of the code, but no, thats not in the code, ok so i just renamed my variable to "AlarmTime" when at first it was "DELAY" now if i plug it into the "delay()" parameter the compiler makes no drama, thing is that now the time for that "delay()" parameter is not being updated, i mean, i see it changing on the serial port, but when i press the button that is suppose to start that "delay()" it fires up the alarm instantly, that tells me that is only taking in account the initial value of that variable, which is "0", recall " AlarmTime = 0;" so the "AlarmTime" value is changing since i see it on the serial monitor, but is not being updated into the "delay(AlarmTime);"

So, let's see the code that does not work properly, without any coloring.

Are you keeping in mind that delay() takes a value in microseconds, not seconds?

delay() is in milliseconds, not seconds (or microseconds!). And also you should make the AlarmTime variable an unsigned long, which is what delay() expects, as pointed out above. Shouldn't matter, but...