# Display 1602 function

**URL:** <https://forum.arduino.cc/t/display-1602-function/899181>\
**Category:** Displays\
**Created:** [August 25, 2021, 7:01pm UTC](https://forum.arduino.cc/t/display-1602-function/899181 "2021-08-25T19:01:37Z")\
**Posts on this page:** 1\
**Showing post:** 10

<div class="post-metadata">

**Author:** ![noiasca](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/noiasca/32/1126910_2.png) [@noiasca](https://forum.arduino.cc/u/noiasca)\
**Post date:** [August 26, 2021, 5:14am UTC](https://forum.arduino.cc/t/display-1602-function/899181/10 "2021-08-26T05:14:16Z")

</div>

@cevepe  
you could use a [template](https://www.google.com/search?q=c%2B%2B+function+template) to spare a lot of overloads

```cpp
template < typename T0, typename T1>
void printLCD(T0 line0, T1 line1)
{
  lcd.clear();
  //lcd.setCursor(0, 0); // done by clear anyway
  lcd.print(line0);
  lcd.setCursor(0, 1);
  lcd.print(line1);
}
```

this enables you do print out more than just char\*,  
Examples:

```cpp
  printLCD("test", "string lit"); 
  printLCD("char", 'x');
  String aString = "FooFoo";
  printLCD("String", aString);
  printLCD("int", 1234);
  printLCD(1234, "int");
  printLCD("float", 12.34);
  printLCD(12.34, "float");
  printLCD(12.34, F("mixed with F-Makro"));
```

but if you need really a function for "that i don't have to write 5 lines all the time" ... and if you really need it a lot in your sketch, you might consider other concepts, for example holding the data in PROGMEM or using the F-Makro

---

_[View the full topic](https://forum.arduino.cc/t/display-1602-function/899181)._
