Pages: [1]   Go Down
Author Topic: Creating Simultaneous Loops  (Read 255 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Karma: 0
Posts: 21
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I am having some trouble trying to figure out how to increment a timer to be referenced in if and while statements in a second loop. I want to be able to get rid of the timer incrementation in the while statements so I can just have one timer to reference by. I would like to have the timer count down from a set value then keep counting down in 1 second increments until 0 while the buzzers go off. If I could have something like a completely separate loop for the timer increment counter and a completely separate one for the buzzers and whatever else I want to add later such as a timer display or something.

#include <Tone.h>

Tone tone1;
Tone tone2;

long countervalue = 1;
int RLED = 1;
int YLED = 2;
int GLED = 3;
int button = 0;
void setup(){
  pinMode(YLED, OUTPUT);
  pinMode(GLED, OUTPUT);

void loop()

  while(countervalue < 4){
    digitalWrite(GLED,HIGH); , 150);
    countervalue = (countervalue+1)%1000000;

  while(countervalue <= 8){
    digitalWrite(YLED,HIGH); , 1000); , 1000);
    countervalue = (countervalue+1)%1000000;

  if(countervalue == 9){
    digitalWrite(RLED,HIGH);, 1000);
    delay(1000);, 1000);
    countervalue = (countervalue+1)%1000000;



East Anglia (UK)
Offline Offline
Faraday Member
Karma: 116
Posts: 4312
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Read up on 'blink without delay' to see how you can time something without blocking execution of other code, which is what delay() does.

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Pages: [1]   Go Up
Jump to: