Let's Make Robots!

Arduino Sketches are "Evolving" for Official Robot.

When programming my "Official Arduino Robot" I have noticed that routines that would work on my previous robots need modification (this is under Arduino Sketch ver 1.05.)


int integrate()                               //noise filter
  int temp;
  int i;
  for (i=0; i<5; i++)
    temp = temp + analogRead(0);
  temp = temp/5;
  return (temp);

(used to work just fine)

(now it needs to be:)

int integrate()      //noise filter
  for (int i=0; i<5; i++)
    temp = temp + Robot.analogRead(sensorPin);
  temp = temp/5;
  return (temp);

(with the temp variable defined at the beginning of the program)

Interesting, and it seems like it will confuse the previous programmers (it did, to me for a short while).

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.

In the case you are showing, temp is a local variable. There is no reason it should need to be global. As for the for loop, I prefer for (int i = 0; ...) {} to declaring the counter variable before setting up the loop.