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