Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
11 years ago.
Warning: Subscript out of range in "main.cpp", Line: 94, Col: 4
1 Answer
11 years ago.
samples is an array with length ADC_Count, in C(++) that is from zero up to ADC_Count - 1. So if you try to address samples[ADC_Count], you are one above the length of your array, which is definately not a warning you can ignore.
I don't understand exactly what the ADC function needs to do, but you need to consider where in the array it should write its data.
Thanks Erik I have changed the code to samples[127] and now the warning has been removed. Although I am struggling to get the values which are being calculated into the actual array i have changed my Ticker to call the Write function as shown below although it still is not writing my calculated values to the array. Can you see anything wrong with my code? Thanks
void ADC() { writeValue(); ADC_Voltage_data=(AinV*3.3); //multiplyed by 3.3 to give the correct voltage reading samples[127]=ADC_Voltage_data; //Save voltage reading within an array named ADC_count }
So what is writeValue supposed to do?
Then you read the ADC, and multiply it by 3.3, that makes sense.
Next you store the value in samples 127? Or ADC_count as shown here. Anyway where is it supposed to be stored?
posted by 20 Nov 2013The write value should write a new value into the array and I am looking to write the value which is being calculated by the ADC_Voltage_data calculation. Then I am storing the value in samples[127] (I have just updated that.) and I am trying to display the values calculated and using a ring buffer to constantly update the values in the array. Although I am not getting the correct values back when I compile the above program, have you any ideas as to where I am going wrong?
posted by 20 Nov 2013Well it makes little sense to me that you want to store them in a ringbuffer, yet you always store it in samples[127], which is just one location. writeValue does something, but I don't know what it is supposed to do. It multiplies the value that is pointed to by two, and then points to the next value. Shouldn't you write your data to your writepointer location?
posted by 20 Nov 2013