help with compiler error

01 Apr 2010

I am trying to write code to fill a buffer with real numbers from the ADC, and am getting two compiler errors at lines 25 and 29:

"Expression must have (pointer to-) function type (E109)"

//Spectrum analyser using Ivan's fft code // mods by Tony Abbey // version 31 March 2010 #include "mbed.h" #include <limits.h> #include "TextLCD.h" BusOut leds(LED1, LED2, LED3, LED4); LocalFileSystem local("local"); TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3 AnalogIn ain(p20); Ticker ticker; Timer t; FILE *fp; float samples(1024); /* Sampling routine; records a buffer full */ void sample() { for(int i=0; i<1024; i++) { samples(i) = ain.read(); /* Compute next bar graph value */ leds = (1 << (int)(samples(i) * 5.0)) - 1; wait_us(10); } }

Help please

Tony

01 Apr 2010

Hi Tony,

The problem is simply syntax; you are using ()'s rather than []'s to index arrays; ()'s are used to call functions.

float samples[1024];
float y = samples[3];

Hope that helps!

Simon

01 Apr 2010

Hi Simon

Grrrr! - thanks for pointing out my silly error - and I fell for the April's fool stunt as well ;-)

ps I didnt get any formatting into my code when I copied and pasted into the forum post. Thanks for deciphering it. Can you remind me what I should do to post a properly formatted listing.

Tony

01 Apr 2010 . Edited: 01 Apr 2010

Hi Tony,

The "ideal" way is to right-click your project in the compiler and hit "Publish" - that way you can insert a link to it in the forum post (using the little package icon) and people can easily reproduce your program. Helps them reproduce the problem, and check their solution really does fix it.

However, you obviously might not want to share your entire project, so you can use the code insert button [<>] in the forum to paste in a snippit; that will give you a formatted block. Just remember, that means someone is going to have to either rely on debugging-by-eye, or reproducing the problem in the compiler themselves which obviously takes them a bit of effort before they can help. But certainly a very valid way to do it.

Glad you got it working.

Stunt. What stunt?! :)

Simon