Loopcount code error

I'm trying my first Loopcount to flash some LEDs fast at first then either just stay on or go to a much slower flash rate.
The end result will use more than 2 LEDs. I was giving each LED it's own output because I am using "super Bright" Jumbo LEds (25ma max/per) and I didn't want to put too much current through any one pin. I was going to make it flash fast for around 4 to 5 seconds. I can figure that out with trial & error.

My problem is with the loop counting code. I get error: expected `}' before 'else' when i compile.

I also don't really know how if I can go from a fast flash rate to a slower one.

// setup
const int led13 =  13;      // the number of the LED pin
const int led2 =  2;  
const int led3 =  3;  
int LoopCount = 0;
const int analogPin = A0;    // input posotive signal 
const int threshold = 1000;   // an arbitrary threshold level 
// Variables will change:
int led13State = LOW;             // ledState used to set the LED
int led2State = LOW;
int led3State = LOW;
long previousMillis = 0;        // will store last time LED was updated

long interval = 100;           // interval at which to blink (milliseconds)  
// 1500 is a good slow rate. 100 is good for fast

void setup() {
  // set the digital pin as output:  
  pinMode(led13, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(led3, OUTPUT); 
}
void loop()
{
  // here is where you'd put code that needs to be running all the time.
  int analogValue = analogRead(analogPin);

  // check to see if it's time to blink the LED; that is, if the 
  // difference between the current time and last time you blinked the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if ((led2State == LOW) && (analogValue > threshold) && (LoopCount == 4))

     LoopCount = LoopCount + 1;
     if (LoopCount == 8) LoopCount = 0;

      led2State = HIGH;  
    else
      led2State = LOW;     

    // This a clock check.  It blinks regardless of input state
    if (led13State == LOW) 
      led13State = HIGH;
    else
      led13State = LOW;
 
         // set the LED with the ledState of the variable:
    digitalWrite(led2, led2State);
    digitalWrite(led13, led13State); 
    //-------------------------------------------------------------First led end
    if ((led3State == LOW) && (analogValue > threshold))
      led3State = HIGH;  
    else
      led3State = LOW;  

    digitalWrite(led3, led3State);
    //-----------------------------------------------------------Second LED end
      // Resets loop counter
  if (LoopCount == 8) LoopCount = 0;
  }
}
 :relaxed:

When you've fixed the brace problem , this :relaxed: is going to need fixing too.

I get error: expected `}' before 'else' when i compile.

That is because you forgot to put the statements you wanted to do if the if statement was true in braces { }, looks like you have forgot to do it after the else as well.
If you do not use braces the if will only do one statement, the one immediately after the if.

I find that a lot of example code is often so over-commented that you cannot see what you need to...

  if (LoopCount == 8) 
    {
      LoopCount = 0;
      led2State = HIGH; 
    }
  else
    {
      led2State = LOW;
    }

If you clean up the sketch, and use the auto format button, you can find your unmatched braces, parenthesis, and other syntax issues.

look how much simpler it looks once you do that

First off... I have no idea where the smilie thing came from. Oh. There it is on top of the post screen. Duh. :smiley:

It's still choking on the bold line below. With an error saying expected `)' before ';' token

void loop()
{
  // here is where you'd put code that needs to be running all the time.
  int analogValue = analogRead(analogPin);

  // check to see if it's time to blink the LED; that is, if the 
  // difference between the current time and last time you blinked the LED is bigger than the interval at which you want to
  // blink the LED.
  unsigned long currentMillis = millis();
 
  if(currentMillis - previousMillis > interval) {
    // save the last time you blinked the LED 
    previousMillis = currentMillis;   

    // if the LED is off turn it on and vice-versa:
    if ((led2State == LOW) && (analogValue > threshold) && (LoopCount == 4))

     LoopCount = LoopCount + 1;
     if (LoopCount == 8) 
     (
[b]      LoopCount = 0;[/b]
     led2State = HIGH;  
     )
    else (
      led2State = LOW;     
      )
    // This a clock check.  It blinks regardless of input state
    if (led13State == LOW) 
      led13State = HIGH;
    else
      led13State = LOW;
 
         // set the LED with the ledState of the variable:
    digitalWrite(led2, led2State);
    digitalWrite(led13, led13State); 
    //-------------------------------------------------------------First led end
    if ((led3State == LOW) && (analogValue > threshold))
      led3State = HIGH;  
    else
      led3State = LOW;  

    digitalWrite(led3, led3State);
    //-----------------------------------------------------------Second LED end
      // Resets loop counter
  if (LoopCount == 8) LoopCount = 0;
  }
}
if (LoopCount == 8) 
     (

Look closely

I had the error with or without that bracket...

I gotta just play with it for a while I guess.

That parenthesis should be a brace.

That's Funny. I've figured out my problem. I can't tell with the computer screen I am using the difference between a parenthesis and a brace. (){} very similar in this program. In the Arduino Program they look exactly the same. If I copy it into Notepad I see a big difference. Funny but frustrating. I'm using a friggin 50" HD TV for my computer monitor. Ok So 'ill look the program over in Notepad. Thanks for your patience. :smiley:

f I copy it into Notepad I see a big difference. Funny but frustrating. I’m using a friggin 50" HD TV for my computer monitor. Ok So 'ill look the program over in Notepad.

I prefer Notepad++. There is an addin available that colors Arduino code properly. You can use the external editor option so that you don’t need to copy code back and forth.

You can also change the font used in the IDE. Some fonts make the curly braces and parentheses look much more distinct.