[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Arduino wait state

Posted on 2017-08-26
5
Medium Priority
?
67 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
  • 3
5 Comments
 
LVL 30

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
 
LVL 1

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 37

Expert Comment

by:Shaun Vermaak
ID: 42270892
1
 
LVL 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
 
LVL 1

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.
What do responsible coders do? They don't take detrimental shortcuts. They do take reasonable security precautions, create important automation, implement sufficient logging, fix things they break, and care about users.
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…
Screencast - Getting to Know the Pipeline

873 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