Here's a simple sketch. I have an array data
and a variable idx
.
I'm assigning a value to each of the array element, and then sending them to my serial monitor.
volatile uint16_t data[5];
volatile uint16_t idx = 5;
void setup() {
Serial.begin(9600);
while (!Serial) { }
Serial.println("\nHello!");
data[0] = 1010;
data[1] = 1011;
data[2] = 1012;
data[3] = 1013;
data[4] = 1014;
for(int i = 0; i< idx; ++i)
{
Serial.print(data[idx]);
Serial.write(",");
}
while(1){ }
}
void loop() {}
When I look into my serial monitor, I get this:
Hello!
0,0,0,0,0,
Why is this happening? Did I overlook something fundamental? I'd appreciate if you could offer your thoughts on this.
I'm testing this code on Arduino Mega2560.