Go Down

Topic: question about void, passing data and print\write (Read 865 times) previous topic - next topic

zarobhr

IDE 1.01
UNO

this is a general question not specific to a program yet so just the void is here

goal. when i print or write some info to a serial port or network port etc the write and print commands take a variity of formats such as a byte, a number, a string and even an array.

so as an example i might have this
Code: [Select]
lcd.setCursor(10,0);
  lcd.print("ALL in    ");
  lcd.setCursor(5,1);
  lcd.print("Error");


i would like to get it down to something like this

Code: [Select]
MyLCD(10,0,"ALL in    ");
MyLCD(5,1,"Error");
void MyLCD(byte col, byte row, ?????? info { \\Here is where i am not sure of the proper datatype for the ?????? so it will take anything just like the print/write does
//do additional stuff here

lcd.setCursor(col,row);
lcd.print(info);
}


fungus


Code: [Select]
MyLCD(10,0,"ALL in    ");
MyLCD(5,1,"Error");
void MyLCD(byte col, byte row, ?????? info { \\Here is where i am not sure of the proper datatype for the ?????? so it will take anything just like the print/write does
//do additional stuff here

lcd.setCursor(col,row);
lcd.print(info);
}




Try this:

Code: [Select]
template<class T>
void MyLCD(byte col, byte row, T t)
{
 lcd.setCursor(col,row);
 lcd.print(t);
}
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

zarobhr



Code: [Select]
MyLCD(10,0,"ALL in    ");
MyLCD(5,1,"Error");
void MyLCD(byte col, byte row, ?????? info { \\Here is where i am not sure of the proper datatype for the ?????? so it will take anything just like the print/write does
//do additional stuff here

lcd.setCursor(col,row);
lcd.print(info);
}




Try this:

Code: [Select]
template<class T>
void MyLCD(byte col, byte row, T t)
{
 lcd.setCursor(col,row);
 lcd.print(t);
}



i added that to the code after my void loop
Code: [Select]
CMSBridge_ino2:6: error: 'T' has not been declared
CMSBridge_ino2.cpp: In function 'void loop()':
CMSBridge_ino2:246: error: invalid conversion from 'const char*' to 'int'
CMSBridge_ino2:246: error: initializing argument 3 of 'void MyLCD(byte, byte, int)'

fungus


i added that to the code after my void loop
Code: [Select]
CMSBridge_ino2:6: error: 'T' has not been declared
CMSBridge_ino2.cpp: In function 'void loop()':
CMSBridge_ino2:246: error: invalid conversion from 'const char*' to 'int'
CMSBridge_ino2:246: error: initializing argument 3 of 'void MyLCD(byte, byte, int)'



Did you try putting it before the place where it's used?
No, I don't answer questions sent in private messages (but I do accept thank-you notes...)

zarobhr



i added that to the code after my void loop
Code: [Select]
CMSBridge_ino2:6: error: 'T' has not been declared
CMSBridge_ino2.cpp: In function 'void loop()':
CMSBridge_ino2:246: error: invalid conversion from 'const char*' to 'int'
CMSBridge_ino2:246: error: initializing argument 3 of 'void MyLCD(byte, byte, int)'



Did you try putting it before the place where it's used?


no matter where in code i put
Code: [Select]
template<class T> i get the first error that T has not been declared

Go Up