Error Help

Hello! I have a few questions about an error i’m getting. Here is my code:

int count = 1;
int pin = 2;

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

void loop()
{
  if(analogRead(A0) > 250 count++);
  {
  }
  for(count=1; count < 6; count++);
  {
    if (count == 236) break
    continue
  }
  if (count == 236);
  {
    digitalWrite (pin, HIGH);
  }
  if (count == 236; pin++; count=1);
  {
  }
}

what does “expected ‘)’ before ‘count’” mean? If you spot more problems with the code let me know. I’m sure I’ll have more error questions!

It means don't put semicolons at the end of if and for statements 99.9% of the time.

 if(analogRead(A0) > 250 count++);

What are you trying to do here?

I was going to go through and point out everything that is wrong, but it occured to me that just about the entire code is wrong. if/for statements aren't interchangeable. If statements should have a single condition and not an assignment or a semicolon within their parenthesis.

Perhaps you should start by explaining what you are trying to accomplish with this code.

Arrch: It means don't put semicolons at the end of if and for statements 99.9% of the time.

 if(analogRead(A0) > 250 count++);

What are you trying to do here?

I was going to go through and point out everything that is wrong, but it occured to me that just about the entire code is wrong. if/for statements aren't interchangeable. If statements should have a single condition and not an assignment or a semicolon within their parenthesis.

Perhaps you should start by explaining what you are trying to accomplish with this code.

Ok, I will explain if you can tell me what to do :). So, what happened is one night I was woke up by a car alarm. I didn't know if it was our car. Later that night I was outside and heard a car alarm, so I ran to the car to see if it was ours. It was. What I ended up doing is crawling under the car and unplugging the the two horns. The car doesn't alarm now. However, the lights still blink. I am wondering if, and how many times the alarm goes off each night. I got in the car and set off the alarm and counted how many tiled the lights blink. What I'm trying to do is use a photoresistor (A0) to count how many times the lights blink. Then, if they blink 236 times, turn an LED on (pin 2) and reset the int "count". Thank you for any suggestions that you may have!!!

Your If/For/and (apparently) Case loops/statements are all kinds of wrong.

    if(analogRead(A0) > 250 count++)  
  {
  }

Needs be:

   if(analogRead(A0) > 250)  {
    //actual code related to condition
    count++;
  }

And same for For Loops...remove semicolons and code w/in brackets (which you have)

But anyways, in regards to what you're doing. I don't think an analog pin is the ideal way to go. Analog reading is looking for voltages. Yes you could write your code to look for values greater than 0, I suppose, but the more ideal way would be to use a digital input. This way you are reading 1 and 0 (on and off). Have the digital input act as a trigger and simply have it count every time the lights go on/off. Does anyone oppose to that or did I completely miss the task at hand?

Actually, I think that should be:

if (analogRead(A0) > 250)
{
     count++
}

count++ makes absolutely no sense inside the if condition and would give you the "expected ‘)’ before count error.

An analog light sensor is an LDR and a resistor/potentiometer.. A digital one is? and is it 5V or 3V3 operated?.. So many decisions, all to keep it simple?

Doc

for(count=1; count < 6; count++);
  {
    if (count == 236) break
    continue
  }

This is broken too. The for loop is going to give count the values 1,2,3,4, and 5. At no point is it ever possible for count to be == 236 in that loop.

Then the very next line checks to see if count is == 236 again. No way, the for loop leaves count = 5. But it doesn’t matter because that if statement has a semicolon after it so it ends right there and never would take any action even if count was ==236.

Finally, that last if block suffers the same mistake as the first one. The only thing that goes inside the parenthesis is the condition. The statements you want conditionally executed go in a block of code following the if statement. There should be no semicolon at the end of the if statement else the block of code that follows will be ignored.

sigilwig444: Ok, I will explain if you can tell me what to do :). So, what happened is one night I was woke up by a car alarm. I didn't know if it was our car. Later that night I was outside and heard a car alarm, so I ran to the car to see if it was ours. It was. What I ended up doing is crawling under the car and unplugging the the two horns. The car doesn't alarm now. However, the lights still blink. I am wondering if, and how many times the alarm goes off each night. I got in the car and set off the alarm and counted how many tiled the lights blink. What I'm trying to do is use a photoresistor (A0) to count how many times the lights blink. Then, if they blink 236 times, turn an LED on (pin 2) and reset the int "count". Thank you for any suggestions that you may have!!!

Start off with some basic examples until you get a hang of the syntax of for loop, selection statements (ifs) and assignment statements. Only until you understand the basics of the language can you actually start to write the logic out for your code.

When you are ready to get the logic started, take a look at the StateChangeExample because simply reading whether the photosensor is above a certain threshold isn't enough; you need to determine when the photosensor [u]crosses[/u] that threshold. That's what the StateChangeDetection example demonstrates, albeit with a digital sensor rather than an analog. The concept of keeping track of the last sensor reading, however, is the same.

Also, start small. Don't try to get everything working at once. Get a small bit of code working and use Serial prints and the Arduino Serial monitor to ensure that it's working. Build from those small bits of code, little by little.

Another error. "Error compiling." core.a(main.cpp.o): In function main': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:14: undefined reference toloop'

HELP!!!

Sounds like a bracket issue. The forums can’t teach you how to program and how to use the loops properly. Visit:
http://arduino.cc/en/Reference/HomePage

It has numerous info on how to program the Arduino. Look at the various loops and conditional statements then check out the examples. Compare them to yours. FYI, yours are wrong.

Give a man a fish, feed him for a day. Teach a man to fish, feed him for a lifetime.

sigilwig444:
Another error. “Error compiling.”
core.a(main.cpp.o): In function main': C:\Program Files (x86)\Arduino\hardware\arduino\cores\arduino/main.cpp:14: undefined reference to loop’

HELP!!!

I can’t see the new code.