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
    
            }
posted by Alan Carson 20 Nov 2013

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 Erik - 20 Nov 2013

The 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 Alan Carson 20 Nov 2013

Well 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 Erik - 20 Nov 2013