Hi,
while building a POV device I came across an interesting anomaly which I think may be a bug (but I could be missing something).
The issue centres around whether the Arduino pins are defined using bytes or integers. Here's the code:
int ledPin[] = {
2,3,4,5,6,7,8,9,10,11,12,13,15,16};
void setup() // run once, when the sketch starts
{
for(int i=0; i<sizeof(ledPin); i++){
pinMode(ledPin[i], OUTPUT); // sets the digital pins as output
digitalWrite(ledPin[i], LOW); // sets the LEDs on
}
}
void loop() // run over and over again
{
for(int i=0; i<sizeof(ledPin); i++){
digitalWrite(ledPin[i], LOW); // sets the LED on
delay(100); // waits
digitalWrite(ledPin[i], HIGH); // sets the LED off
delay(100); // waits
}
}
This code behaves oddly when uploaded to the Arduino: there is a long pause between loops (the for() loop seems to run for more than 14 time), pin 8 flashes LOW a couple of times during this pause, and after a number of cycles pin 8 ceases to come on.
I though this was hardware related, but then I defined the pin numbers as bytes using the following:
byte ledPin[] = {
2,3,4,5,6,7,8,9,10,11,12,13,15,16};
and all the problems went away.
Also of note: if I substitute the number 14 for the sizeof() function it will work fine with ints or bytes.
So, is this a bug? something to do with memory allocation?