help in programming

Hi i am working on a project of obstacle avoidance using SRF04 sensor i need 10 different reading inside a loop.
but am getting error invalid type int[int] array subscript i have bolded the portion where am facing this problem.
thanks.

void loop()
{

myservo.write(pos);
delay(100);
for(pos = 105; pos > 75; pos -=5) // goes from 105 degrees to 75 degrees
{ // in steps of 5 degree
myservo.write(pos); // tell servo to go to position in variable 'pos'

digitalWrite(trigPin, LOW); // Set the trigger pin to low for 2uS
delayMicroseconds(2);
digitalWrite(trigPin, HIGH); // Send a 10uS high to trigger ranging
delayMicroseconds(10);
digitalWrite(trigPin, LOW); // Send pin low again
int distance= pulseIn(echoPin, HIGH); // Read in times pulse
distance=distance/58; // Calculate distance from time of pulse

int DISTANCE;
** for (int a = 0; a < 6; a = a + 1)**
{
** DISTANCE[a]= distance; /// i want 5 reading of angle 105 , 100, 95, 90, 85, 80,75 to be stored in DISTANCE1, DISTANCE2 RESPECTIVELY**
** }**

delay(25); // Wait 50mS before next ranging
Serial.print("ANGLE ");
Serial.print(pos);
Serial.print(" = ");
Serial.println(distance);

}

Please do not cross-post. I have deleted your other post.

While you are waiting for a reply you might want to Google "C array".

And modify your post to alter the topic to be more useful than "help in programming". You are in the programming section, and we know you want help.

sorry about that (o_o)

Hi i am working on a project of obstacle avoidance using SRF04 sensor i need 10 different reading inside a loop.

int DISTANCE;

Try:

int DISTANCE [10];

  int distance= pulseIn(echoPin, HIGH);        // Read in times pulse
 int DISTANCE;

If you worked for me, I'd kick your ass for coding like this (with or without the array notation). There is a real problem if you can't think of different names for these two variables. Something that differs by more than case.

There is a convention that all upper case names are constant, too. The array you are creating/trying to create here is NOT constant.

I agree with PaulS here. I was just too tired to point it out myself.

Plus, I didn't notice this:

 int distance ...

Just imagine you are talking to someone. If you say "I put the book in the box" you don't expect it to be different to "I put the book in the BOX" or "I put the book in the Box".

Or even worse... The box is in the BOX.


To first understand recursion, you must first understand recursion...