[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

Arduino wait state

Posted on 2017-08-26
5
Medium Priority
?
57 Views
Last Modified: 2017-09-01
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

0
Comment
Question by:Nadir Van Thielen
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
5 Comments
 
LVL 29

Expert Comment

by:Dr. Klahn
ID: 42270683
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
 

Author Comment

by:Nadir Van Thielen
ID: 42270703
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
 
LVL 36

Expert Comment

by:Shaun Vermaak
ID: 42270892
1
 

Accepted Solution

by:
Nadir Van Thielen earned 0 total points
ID: 42270926
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
 

Author Closing Comment

by:Nadir Van Thielen
ID: 42278294
white multiple events it will be challenging
but for now it the best easiest way
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this post we will learn different types of Android Layout and some basics of an Android App.
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
With the power of JIRA, there's an unlimited number of ways you can customize it, use it and benefit from it. With that in mind, there's bound to be things that I wasn't able to cover in this course. With this summary we'll look at some places to go…

656 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question