Why wont the while loop begin?


bool a=false;

// theres a whole bunch irrelevant code here

digitalWrite (7, HIGH);
      digitalWrite (5, LOW);
      delay(8000);
      digitalWrite (6, HIGH);
      digitalWrite (7, LOW);
      
      while (a==false);
      {
      delay(1000);
      digitalWrite (6, LOW);
       digitalWrite (2, HIGH);
      digitalWrite (5, HIGH)

// more irrelevant code

}

theres more code before and after but it's mostly irrelevant; just more digitalWrites and delays.

the while loop isn't performing any action, instead freezing everything on the last lines before it. is there a fix for this?

Dollars to donuts, your problem is in your so called irrelevant code.

Post your complete sketch.

The semicolon make that line an infinite loop.

Do I get a donut? Oh wait, that may not be the only problem.

1 Like

bool hasRun=false;
bool hasRun2=false;
bool hasRun3=false;
bool hasRun4=false;
bool hasRun5=false;
bool hasRun6=false;
bool hasRun7=false;


void buttonCheck()
{
  Serial.println (analogRead(A0));
  if (analogRead(A5)==201)
  { 
    allOff();
  maintenance();
  }
   else if (analogRead(A5)==598) 
  {
    if (analogRead(A4)==0&&analogRead(A3)>0&&analogRead(A5)>0)
    {
     Serial.println ("a");
      smallButtonCheck(); 
      digitalWrite (7, LOW);
      digitalWrite (6, LOW);
      digitalWrite (5, HIGH);
      digitalWrite (2, HIGH);
      smallButtonCheck(); 
      digitalWrite (2, LOW);
      digitalWrite (4, HIGH);
      massButtonCheck(); 
      digitalWrite (4, LOW);
      digitalWrite (3, HIGH);
      smallButtonCheck(); 
      digitalWrite (3, LOW);
      digitalWrite (2, HIGH);
      smallButtonCheck(); 
      digitalWrite (7, HIGH);
      digitalWrite (5, LOW);
      massButtonCheck();
      massButtonCheck();
      digitalWrite (6, HIGH);
      digitalWrite (7, LOW);
      
      while (hasRun==false);
      {
       Serial.println ("b");
      smallButtonCheck(); 
      digitalWrite (6, LOW);
       digitalWrite (2, HIGH);
      digitalWrite (5, HIGH);
        smallButtonCheck();
      digitalWrite (2, LOW);
      digitalWrite (4, HIGH);
        massButtonCheck();
      digitalWrite (4, LOW);
      digitalWrite (3, HIGH);
      smallButtonCheck(); 
      digitalWrite (3, LOW);
      digitalWrite (2, HIGH);
      smallButtonCheck();
      digitalWrite (5, LOW);
      digitalWrite (7, HIGH);
        massButtonCheck();
        digitalWrite (7, LOW);
        digitalWrite (6, HIGH);
        smallButtonCheck();
        hasRun=true;
      }
    }
     
     if (analogRead(A4)==0&&analogRead(A2)==408&&analogRead(A5)>0&&analogRead(A0)==0)
     {
       Serial.println(analogRead(A2));
       if (hasRun2==false)
       {
         Serial.println ("c");
       smallButtonCheck();
       digitalWrite (4, HIGH);
       digitalWrite (5, HIGH);
       digitalWrite (2, LOW);
       massButtonCheck();
       digitalWrite (4, LOW);
       digitalWrite (3, HIGH);
       smallButtonCheck();
       digitalWrite (3, LOW);
       digitalWrite (2, HIGH);
       smallButtonCheck();
       digitalWrite (7, HIGH);
       digitalWrite (5, LOW);
       massButtonCheck();
       massButtonCheck();
       digitalWrite (7, LOW);
       digitalWrite (6, HIGH);
       smallButtonCheck();
       digitalWrite (5, HIGH);
       digitalWrite(6, LOW);
       hasRun2=true;
     }
      else if (hasRun2==true&&analogRead(A5)>0);
       {
        Serial.println ("d");
         smallButtonCheck();
        allOff();
        digitalWrite (4, HIGH);
        digitalWrite (5, HIGH);
        digitalWrite (2, LOW);
        massButtonCheck();
        digitalWrite (4, LOW);
        digitalWrite (3, HIGH);
        smallButtonCheck();
        digitalWrite (3, LOW);
        digitalWrite (2, HIGH);
        smallButtonCheck();
        digitalWrite (7, HIGH);
          digitalWrite (3, LOW);
        digitalWrite (5, LOW);
        massButtonCheck();
        digitalWrite (7, LOW);
        digitalWrite (6, HIGH);
        smallButtonCheck();
        digitalWrite (6, LOW); 
        digitalWrite (5, HIGH);
         hasRun2=false;
       }
     }
     if (analogRead(A4)==0&&analogRead(A0)==408&&analogRead(A1)==0&&analogRead(A5)>0)
     {
       Serial.println ("e");
       if (hasRun3==false)
      {
        smallButtonCheck();
        digitalWrite (3, LOW);
        digitalWrite (2, HIGH);
        smallButtonCheck();
        digitalWrite(5, LOW);
        digitalWrite(7, HIGH);
        massButtonCheck();
        massButtonCheck();
        digitalWrite (7, LOW);
        digitalWrite (6, HIGH);
        smallButtonCheck();
        digitalWrite (6, LOW);
        digitalWrite (5, HIGH);
        smallButtonCheck();
        digitalWrite (2, LOW);
        digitalWrite (4, HIGH);
        massButtonCheck();
        digitalWrite (4, LOW);
        digitalWrite (3, HIGH);
        hasRun3=true;
      }
      else if (hasRun3==true)
       {
        Serial.println ("f");
        smallButtonCheck();
        allOff();
         cycleSix();
         cycleOne();
         cycleTwo();
         cycleThree();
        cycleFour();
        cycleFive();
         hasRun3=false;
       }
     
     }
   
  if (analogRead(A5)==399)
  {
    if (analogRead(A3)>0&&analogRead(A4)==0&&analogRead(A5)>0)
    {
     if (hasRun5==false)
     {
       Serial.println ("g");
        smallButtonCheck(); 
      digitalWrite (7, LOW);
      digitalWrite (6, LOW);
      digitalWrite (5, HIGH);
      digitalWrite (2, HIGH);
      smallButtonCheck(); 
      digitalWrite (2, LOW);
      digitalWrite (4, HIGH);
      massButtonCheck(); 
       massButtonCheck();
      digitalWrite (4, LOW);
      digitalWrite (3, HIGH);
      smallButtonCheck(); 
      digitalWrite (3, LOW);
      digitalWrite (2, HIGH);
      smallButtonCheck(); 
      digitalWrite (7, HIGH);
      digitalWrite (5, LOW);
      massButtonCheck();
      digitalWrite (6, HIGH);
      digitalWrite (7, LOW);
        hasRun5=true;
     }
      if (hasRun5==true)
      {
        Serial.println ("h");
          smallButtonCheck(); 
      digitalWrite (6, LOW);
       digitalWrite (2, HIGH);
      digitalWrite (5, HIGH);
        smallButtonCheck();
      digitalWrite (2, LOW);
      digitalWrite (4, HIGH);
        massButtonCheck();
      digitalWrite (4, LOW);
      digitalWrite (3, HIGH);
      smallButtonCheck(); 
      digitalWrite (3, LOW);
      digitalWrite (2, HIGH);
      smallButtonCheck();
      digitalWrite (5, LOW);
      digitalWrite (7, HIGH);
        massButtonCheck();
        digitalWrite (7, LOW);
        digitalWrite (6, HIGH);
        smallButtonCheck();
        hasRun5=true;
      }
    } 
    if (analogRead(A4)==0&&analogRead(A2)==408&&analogRead(A5)>0&&analogRead(A0)==0)
    {

     if (hasRun6==false)
     {
       Serial.println ("i");
       smallButtonCheck();
       digitalWrite (4, HIGH);
       digitalWrite (5, HIGH);
       digitalWrite (2, LOW);
       massButtonCheck();
       massButtonCheck();
       digitalWrite (4, LOW);
       digitalWrite (3, HIGH);
       smallButtonCheck();
       digitalWrite (3, LOW);
       digitalWrite (2, HIGH);
       smallButtonCheck();
       digitalWrite (7, HIGH);
       digitalWrite (5, LOW);
       massButtonCheck();
       digitalWrite (7, LOW);
       digitalWrite (6, HIGH);
       smallButtonCheck();
       digitalWrite (5, HIGH);
       digitalWrite(6, LOW);
       hasRun6=true;
     }
      if (hasRun6==true)
      {Serial.println ("j");
        
        smallButtonCheck();
        allOff();
        digitalWrite (4, HIGH);
        digitalWrite (5, HIGH);
        digitalWrite (2, LOW);
        massButtonCheck();
        digitalWrite (4, LOW);
        digitalWrite (3, HIGH);
        smallButtonCheck();
        digitalWrite (3, LOW);
        digitalWrite (2, HIGH);
        smallButtonCheck();
        digitalWrite (7, HIGH);
        digitalWrite (3, LOW);
        digitalWrite (5, LOW);
        massButtonCheck();
        digitalWrite (7, LOW);
        digitalWrite (6, HIGH);
        smallButtonCheck();
        digitalWrite (6, LOW); 
        digitalWrite (5, HIGH);
         hasRun6=true;
      }
    }
    if (analogRead(A0)>0&&analogRead(A1)==0&&analogRead(A5)>0)
    {
     if (hasRun7==false)
     {
       Serial.println ("k");
        smallButtonCheck();
        digitalWrite (3, LOW);
        digitalWrite (2, HIGH);
        smallButtonCheck();
        digitalWrite(5, LOW);
        digitalWrite(7, HIGH);
        massButtonCheck();
        digitalWrite (7, LOW);
        digitalWrite (6, HIGH);
        smallButtonCheck();
        digitalWrite (6, LOW);
        digitalWrite (5, HIGH);
        smallButtonCheck();
        digitalWrite (2, LOW);
        digitalWrite (4, HIGH);
        massButtonCheck();
        massButtonCheck();
        digitalWrite (4, LOW);
        digitalWrite (3, HIGH);
        hasRun7=true;
     }
      if (hasRun7==true)
      {
        Serial.println ("l");
        smallButtonCheck();
        allOff();
         cycleSix();
         cycleOne();
         cycleTwo();
         cycleThree();
        cycleFour();
        cycleFive();
         hasRun3=true;
      }
    }
  }
}
}

void defaultPattern()
{
  cycleOne();
  cycleTwo();
  cycleThree();
  cycleFour();
  cycleFive();
  cycleSix();
}

void smallButtonCheck()
{
    delay(100);
  buttonCheck();
    delay(100);
  buttonCheck();
    delay(100);
  buttonCheck();
    delay(100);
  buttonCheck();
    delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
    delay(100);
  buttonCheck();
    delay(100);
  buttonCheck();
    delay(100);
  buttonCheck();
    delay(100);
  buttonCheck();
}

void massButtonCheck()
{
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
  delay(100);
  buttonCheck();
}

void maintenance() 
{
  if (analogRead(A5)==201)
  { 
   Serial.println (analogRead(A5));
   digitalWrite (2, HIGH);
   digitalWrite (5, HIGH);
   digitalWrite (4, LOW);
   digitalWrite (3, LOW);
   digitalWrite (6, LOW);
   digitalWrite (7, LOW);
   delay(1500);
    if (analogRead(A5)==201)
    {
   digitalWrite (2, LOW);
   digitalWrite (5, LOW);
   digitalWrite (4, HIGH);
   digitalWrite (7, HIGH);
 delay(1500);
    }
    else if (analogRead(A5)!=201)
    {
      defaultPattern();
    }
  }
}

void cycleOne()
{
  if (analogRead(A5)==201)
  { 
    maintenance();
     }
else if (analogRead(A5)==0)
{
  digitalWrite (5, LOW);
  digitalWrite (6, LOW);
  digitalWrite (3, LOW);
  digitalWrite (2, HIGH);
  digitalWrite (7, HIGH);
  digitalWrite (4, LOW);
 massButtonCheck();
}
}


void cycleTwo()
{
  if (analogRead(A5)==201)
  { 
    allOff();
  maintenance();
     }
 else if (analogRead(A5)==0)
{
  digitalWrite (7, LOW);
  digitalWrite (6, HIGH);
   smallButtonCheck();
}
}

void cycleThree()
{
  if (analogRead(A5)==201)
  { 
    allOff();
  maintenance();
     }
  else if (analogRead(A5)==0)
{
  digitalWrite (6, LOW);
  digitalWrite (5, HIGH);
    digitalWrite (4, LOW);
    digitalWrite (2, HIGH);
    digitalWrite (3, LOW);
    digitalWrite (7, LOW);
smallButtonCheck();
  }
}

void cycleFour()
{
  if (analogRead(A5)==201)
  { 
    allOff();
  maintenance();
     }
else if (analogRead(A5)==0)
{
  digitalWrite (2, LOW);
digitalWrite (4, HIGH);
 massButtonCheck();
}
}
  


void cycleFive()
{
  if (analogRead(A5)==201)
  { 
    allOff();
  maintenance();
     }
 else if (analogRead(A5)==0)
{
  digitalWrite (4, LOW);
  digitalWrite (3, HIGH);
  smallButtonCheck();
}
}

void cycleSix()
{
  if (analogRead(A5)==201)
  { 
    allOff();
   maintenance();
  }
  else if (analogRead(A5)==0)
{
  digitalWrite (3, LOW);
  digitalWrite (2, HIGH);
  smallButtonCheck();
}
}
  
void allOff() 
{
  for (int x=2; x<=13; x++)
  {
    digitalWrite (x, LOW);
  }
}

void setup()
{
  for (int i=2; i<=13; i++)
  {
    pinMode (i, OUTPUT);
  }
  Serial.begin (9600);
}

void loop()
{
  Serial.println (analogRead(A5));
  if (analogRead(A5)==201)
  { 
    allOff();
   maintenance();
     }
  else if (analogRead(A5)==0)
  {
  defaultPattern();
  }
}

that worked, I deleted it and now its fine. Thanks

Never to write a "spaghetti code" like this. Use an arrays instead of rows of similar variables like that:

Use loops rather than copy-pasting numerous blocks of nearly-identical code.

See, programming is an interesting creative activity, not copying the same lines dozens of times

1 Like

You have the same extra semicolon problem in several places. I would suggest looking at some basic C++ tutorials and learning a little bit the syntax.

2 Likes

I wonder what would lead to someone putting in the extra semicolon where it doesn't belong. I can see forgetting to put one in at the end of a statement, but where does the extra one come from? It's not (supposed to be) the end of a statement.

No, but it is the end of a line. A lot of people think that they'll learn better by skipping the basics and just trying to adjust some example code and see what happens. When you have no idea the difference between a line and a statement, then there's nothing to tell you a semicolon doesn't go there.

Tinkering around is a great way to learn coding tricks and algorithms. But if you don't know the very basics of the syntax and it's all just magic to you then it gets really hard to do that.

they're mostly just typos.

Is this what drives your leds in the other post?
Cross posting is not allowed.
Please read forum guidelines.
A moderator can merge your two threads...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.