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 ThielenDHL Asked:
Who is Participating?
 
Nadir Van ThielenDHL Author 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
 
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 ThielenDHL Author 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 ThielenDHL Author Commented:
white multiple events it will be challenging
but for now it the best easiest way
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.