I'm trying to send array contents over Serial. This is the code:
#include <PCM.h>
const unsigned char sample[] PROGMEM = {
126, 127, 128, 128, 128, 128, 128, 127, 128, 128, 128, 129, 129, 128, 127, 128, 128, 127, 126, 127, 128, 129, 128, 127, 126, 127, 128, 128, 126, 126, 127, 127, 127, 127, 127, 127, 126, 127, 129, 130, 129, 128, 126, 126, 126, 126, 127, 129, 130, 129, 127, 127, 127, 127, 128, 128, 128, 128, 127, 127, 127, 127, 127, 127, 128, 130, 131, 129, 127, 126, 126, 126, 127, 127, 128, 128, 128, 128, 127, 128, 128, 127, 127};
void setup()
{
Serial.begin(115200);
delay(3000);
for (int i=0; i<sizeof(sample); i++)
{
delay(100);
Serial.println(sample[i]);
}
}
void loop()
{
}
When I start monitoring serial port, it gives non-intended output, not the original values inside the array. This is the Output of the first code "with Println":
0
0
6
0
0
0
1
0
0
6
6
6
6
6
6
6
0
0
135
0
0
6
0
0
1
3
0
6
171
0
0
0
0
0
0
0
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
6
2
6
1
4
45
0
0
6
0
6
0
248
254
This is the output with "Write": i could not paste the output of "write", i captured it as jpg
But, when I do this, I get the values I want , but I'll lose the FOR loop,
#include <PCM.h>
const unsigned char sample[] PROGMEM = {
126, 127, 128, 128, 128, 128, 128, 127, 128, 128, 128, 129, 129, 128, 127, 128, 128, 127, 126, 127, 128, 129, 128, 127, 126, 127, 128};
void setup()
{
Serial.begin(115200);
delay(3000);
//for (int i=0; i<sizeof(sample); i++)
// {
delay(100);
Serial.println(sample[0]);
Serial.println(sample[1]);
Serial.println(sample[2]);
Serial.println(sample[3]);
Serial.println(sample[4]);
// }
}
void loop()
{
}
What is the problem? I could not figure it out. Any help will be appreciated.
NOTE: Both codes should give same result for the first 5 values in the array, but it did not, the second code gives "126 127 128 128 128" and it is good, but the first code wont, and it has an only difference of having the variable "i" instead of listing all contents of the array one by one.
Thank you in advance,