I'm trying to use a subprogram that will read the serial port. I can't figure out where to initialize the serial port without having to write it into the main program Setup function.
In the below pseudo code I've tried to show the crux of my question, though I know there are numerous syntax issues. I'm not good enough at programming to type this stuff off the top of my head and I've not written the actual code yet (I do have a bunch of snippets).
I guess I could put the serial setup code in the beginning of the subprogram with a header blocker type of setup. But I think there might be an approach I just can't see.
Any suggestions would be appreciated.
Thanks
John
Main program:
// My Program
// Globals etc
int x;
#include callablefunction.h
void setup(){
some setup stuff
} // --- end of setup ---
void loop () {
do this and that
x = callablefunction
} // --- end loop ---
Support code:
callablefunction.cpp
static int count = 0;
static int state = 0;
// other code
char inChar = (char)Serial.read() & 0x7F;
// more code