Arduino wait state

I build a simpel program ,

but the button input need to wait 1000ms , for the next reaction
any way to fix that problem.

int led1 = 13;
int led2 = 12;
int button = 7;
int buttonState;

void setup() {
  
  
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(button, INPUT);

}

void loop() {

  buttonState = digitalRead(button);

  
if (buttonState == HIGH) 
{
digitalWrite(led2 , LOW);


} 
else
{

digitalWrite(led2,HIGH); 
  
}
  digitalWrite(led1, HIGH);  
  delay(1000);                      
  digitalWrite(led1, LOW);    
  delay(1000);                      
}

Open in new window

LVL 1
Nadir Van ThielenAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dr. KlahnPrincipal Software EngineerCommented:
https://www.arduino.cc/en/Reference/Delay

"delay()
Description

Pauses the program for the amount of time (in miliseconds) specified as parameter. (There are 1000 milliseconds in a second.)
"
0
Nadir Van ThielenAuthor Commented:
Dr. Klahn,  Delay yes ,

but not what i need, the program need to run whit out delay.

the test i wanna make :
 led on / off whit delay of 1 sec and and when I pres the button.
The second led need to go on whit out delay
0
Shaun VermaakTechnical Specialist/DeveloperCommented:
1
Nadir Van ThielenAuthor Commented:
this also a solution make a counter.


int led1 = 13;
int led2 = 12;
int button = 7;
int buttonState;
int counter;  //  interval counter
void setup() {
  
  
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(button, INPUT);

counter == 1000;

}

void loop() {

buttonState = digitalRead(button);

 // -------------------------------------button up/down  ---- start
if (buttonState == HIGH) 
{
digitalWrite(led2 , LOW);
} 
else
{
digitalWrite(led2,HIGH); 
 
}
// -------------------------------------button up/down  ---- end
 
 delay(1); 
 counter++;
  
  
if (counter <= 1000)  
 {
  digitalWrite(led1, HIGH); 
 counter == 0;
 }
 else
 {
  digitalWrite(led1, LOW);    
 }
}

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Nadir Van ThielenAuthor Commented:
white multiple events it will be challenging
but for now it the best easiest way
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming

From novice to tech pro — start learning today.