I would like some help writing a function. The need is the following:
I have an arduino and an LCD display attached on it.
I use lcd.print function to write things on the LCD.
I need to write a function that enables or disables all writes on the LCD replacing the lcd.print depending on a "condition".
Something like that:
void my_lcd_print (????????? txt)
{
if (condition)
lcd.print (txt);
}
"condition" will be a globally defined variable.
I need to pass to this function (my_lcd_print) all kind of types of arguments lcd.print accepts (int, strings etc) without casting compilation problems.
Not familiar with the LCD screen, but as far as my (limited) knowledge of Arduino programming goes, its rather impossible to define an argument for a method that can take multiple or all forms. I would suggest to either store the to-be-printed material in global variables, and handle the different formats with different methods, or use an identifier in the argument to tell the method what kind of data is being printed. Perhaps with a switch case or something.
int a
string b
byte c
int identifier
void print(identifier){
switch(identifier)
case 1: print a
case 2: print b
case 3: print c
}
I have no clue exactly what the extend of the expected data formats is, but this is a general solution which should be easily implementable
EDIT: perhaps you can set up 'condition' as to take care of selecting the correct method to handle the data. Some actual code would be useful, primarily the part which fills/selects the data for the final printing. How do you decide which variables are printed? The casting question I cannot answer, but would be useful if the method would simply print what you feed it...
AWOL:
A macro is simply a text-replacement mechanism, so yes, it can take any type as argument.
Ok thanks....Im now at a level that I can program virtually anything I want on Arduino, but it is things like this I still have to read up about. My JAVA-only background doesnt help....
That how the STL (standard template library) does things like make lists of any type. The actual code to do a list is a templated function (or functions) so it can handle any type.