How come this simple sound sensor graphing program I made in NXC is not working? Nothing is showing up on the screen. It should log the sound level each second and display the sound level on a bar graph that moves backwards. Do you have any suggestions?
Before trying muntoo's suggestion, please tell us what you want the for loop to accomplish. It is not at all clear from your uncommented code. It would be utter nonsense to iterate through every element in your 100 element array and move the value from the next element into the current element so I am sure that is not what you are trying to do.
muntoo, I do not think it is possible for you to know what someone else was trying to do with the kind of certainty you possess. Why not let him answer my question? If you want to simulate a stack with 100 maximum entries then use two arrays, ArrayBuild, ArraySubset, and ArrayInit.
task main()
{
SetSensorSound(S1); // don't use IN_1 in NXC code - it is for NBC use
int x[100], tmp[];
while (true) {
int value = MIC;
// ArraySubset(tmp, x, 0, 99); // all elements except the last
// ArrayBuild(x, value, tmp); // put the new value at the front
ArraySubset(tmp, x, 1, NA); // all elements except the first
ArrayBuild(x, tmp, value); // put the new value at the end
ArrayInit(tmp, 0, 0); // free memory
for(int p=0; p<100; p++ ) { // I disagree with those who recommend using pre-increment - especially in NXC code
LineOut(p,0,p,x[p]);
}
Wait(SEC_1);
}
}