lil help please

If trying to write a little code, lets call them Leds, actually they are relays. They all start same time run for a bit but end at different times. I think I can do it in a while loop, this gives me a Void loop': and a expected } error

void loop (){
boolean x = false;
while(x = false)
{
  
 unsigned long Task1Time = millis();
  if (Task1Time >= 0){
   digitalWrite(5, HIGH); 
  }
   if (Task1Time >= minutes_in_ms(5)){
   digitalWrite(5, LOW); 

}
}

Count the opening { braces. Count the closing } braces. The two numbers should be the same.

could you post all your code?

CTRL-T to get started.

while(x = false)

Why are you assigning false to x in the expression? == is the equality test operator, not =.

 unsigned long Task1Time = millis();
  if (Task1Time >= 0){

By the time this code gets executed, millis() will return a non-negative, non-zero value. Therefore this will ALWAYS be true. Seems silly to test an expression that can not possibly be false.

Running an infinite loop inside an infinite loop is pointless.

You do not have a matching number of } for the number of { you have.

your right "By the time this code gets executed, millis() will return a non-negative, non-zero value. Therefore this will ALWAYS be true. Seems silly to test an expression that can not possibly be false." I want it to always be true, as I want them all to start the same time, real dumb I should of said just start no expression. Loop within a loop is stupid, maybe, but what if you want to run some more code after this loop is finished, its going to fire 4 relays then do other stuff after they all finish. The while(x = false) was my way out of the loop after my 4 relays were finished. Why are you assigning false to x in the expression? == is the equality test operator, not = Not sure what you mean, I guess it should be while(x) or while(x==true) some thing like that got to go to work now I will think about this some more try again later thanks

OK I think I got it yay.. here's what I did. pin 5,6,7 come on same time 5 runs 3min. 6 runs 7min. 7 runs 9 min. then it breaks out of the loop and turns pin 4 on and the whole loops and starts over. This is not exactly what I want, but it is the Idea for what I'm trying to do. Hope its right

#define seconds_in_ms(s) ((s)*1000UL)
#define minutes_in_ms(m) ((m)*60UL*1000UL)
#define hours_in_ms(h)   ((h)*60UL*60UL*1000UL)
#define days_in_ms(d)    ((d)*24UL*60UL*60UL*1000UL)
#define weeks_in_ms(w)   ((w)*7UL*24UL*60UL*60UL*1000UL)

boolean x = true;

void setup() {
    
   
   pinMode(2, OUTPUT);   
   pinMode(3, OUTPUT);  
   pinMode(4, OUTPUT);  
   pinMode(5, OUTPUT); 
   pinMode(6, OUTPUT);   
   pinMode(7, OUTPUT);  

  digitalWrite(2, LOW);   
  digitalWrite(3, LOW);  
  digitalWrite(4, LOW);  
  digitalWrite(5, LOW);  
  digitalWrite(6, LOW);  
  digitalWrite(7, LOW);  

  
}
void loop ()
{
  digitalWrite(5, HIGH);
  digitalWrite(6, HIGH);
  digitalWrite(7, HIGH);
  unsigned long Task1Time = millis();
  while(x){

  if (Task1Time >= minutes_in_ms(3)){
   digitalWrite(5, LOW); 
    
}
  if (Task1Time >= minutes_in_ms(7)){
     digitalWrite(6, LOW); 
}
  if (Task1Time >= minutes_in_ms(9)){
     digitalWrite(7, LOW);
      x = false; 
}
}
  digitalWrite(4, HIGH); //not really but a whole bunch other code goes here before it all loops

}

Looks to me your code will work just once after a powerup or a board reset. Is this what you want ? Otherwise look closer to the blink without delay example.

perkunas: OK I think I got it yay.. here's what I did.

...

And what happened when you ran it?

John

"Looks to me your code will work just once after a powerup or a board reset. Is this what you want ?" Actually yes and no, nice catch. (this is just a test more to come) Its going to do a bunch of stuff 14 days, then start over at the end of the main loop (perfect) or start over on a power up or board reset...so yes but no...Id prefer it to pickup where it left off, on lets say a power outage. Code wise that's too hard to do, so battery backup is prob the answer. unless you got other ideas.

Haven't tried it yet I will tomorrow

I think you're taking the wrong approach. If you need to plan actions 14 days in the future, then repeat them, I think you'd be better off with an RTC module (e.g. DS1307) and the Time library.

perkunas: Why are you assigning false to x in the expression? == is the equality test operator, not = Not sure what you mean, I guess it should be while(x) or while(x==true) some thing like that

Actually, (x == false) would work just fine too. Every time you run (x = false), you're setting x equal to false, not checking to see whether or not it is, in fact, false. So you're basically saying "Just keep doing this all the time because it's always going to be time to do it." Using (x == false) actually checks the truthity or falsitude of x, then does stuff between the braces only when the falsitude is confirmed.