error: 'MorseFlasher' has not been declared In function 'void morse_char(char, void ()(long unsigned int))':
In function 'void morse_dash(void ()(long unsigned int))':
In function 'void morse_dot(void ()(long unsigned int))':
In function 'void morse_string(const char, void (*)(long unsigned int))':
I'm not sure where I'm going wrong, when I compile this code by hand with avr-gcc, I don't get this error. What is wrong with how I am using function pointers?
The problem is related to the fact that Arduino automatically generates prototypes for functions in your sketch. These prototypes are inserted above your code. Thus, MorseFlasher is not declared before those prototypes and you get an error. Typedefs are a feature of C/C++ that we thought might be too confusing for our target audience, so we haven't yet worried about supporting them. For now, you can try rewriting your code without using the typedef, or compiling it outside of Arduino (e.g. with the Arduino command line instructions at: http://www.arduino.cc/en/Hacking/CommandLine).
Does Arduino generate prototypes for all files in the sketch or just in the main sketch file? As in, if I split off my morse code stuff into an .h and .c file, would that work?
It should, yea, good point. I believe it only generates prototypes for functions in the "main sketch file" - any of the tabs with no extension (that all get concatenated into a single file).
Did you #include "morse.h" in your main sketch file? Also, the main sketch is compiled as C++, so you either need to rename morse.c to morse.cpp or wrap the function declarations in morse.h with:
Did you #include "morse.h" in your main sketch file? Also, the main sketch is compiled as C++, so you either need to rename morse.c to morse.cpp or wrap the function declarations in morse.h with:
The extern "C" was what I needed, thanks. I found that if I renamed morse.c to morse.cpp, I needed to include WProgram.h