# Help with shorting tft lcd print code

**URL:** <https://forum.arduino.cc/t/help-with-shorting-tft-lcd-print-code/932242>\
**Category:** Programming\
**Created:** [December 4, 2021, 11:00pm UTC](https://forum.arduino.cc/t/help-with-shorting-tft-lcd-print-code/932242 "2021-12-04T23:00:23Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ifsaguozg](https://avatars.discourse-cdn.com/v4/letter/i/a6a055/32.png) [@ifsaguozg](https://forum.arduino.cc/u/ifsaguozg)\
**Post date:** [December 4, 2021, 11:00pm UTC](https://forum.arduino.cc/t/help-with-shorting-tft-lcd-print-code/932242/1 "2021-12-04T23:00:23Z")

</div>

I have this repetitive code that just print some variables on lcd, how could i shorten this ?

```cpp
    tft.setCursor(150, 40);
    tft.setTextSize(3);
    tft.setTextColor(ILI9341_WHITE);
    tft.print(Input_Current);
    tft.println("A");

    tft.setCursor(250, 0);
    tft.setTextSize(1);
    tft.setTextColor(ILI9341_GREEN);
    tft.print(Thermistor1);
    tft.println("°C");

```

---

<div class="post-metadata">

**Author:** ![anon73444976](https://avatars.discourse-cdn.com/v4/letter/a/439d5e/32.png) [@anon73444976](https://forum.arduino.cc/u/anon73444976)\
**Post date:** [December 4, 2021, 11:02pm UTC](https://forum.arduino.cc/t/help-with-shorting-tft-lcd-print-code/932242/2 "2021-12-04T23:02:28Z")

</div>

Make it a function?

Change the name of the tft object to just t?

What are you trying to do with the code you didn't post?

---

<div class="post-metadata">

**Author:** ![killzone\_kid](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/killzone_kid/32/1098074_2.png) [@killzone\_kid](https://forum.arduino.cc/u/killzone_kid)\
**Post date:** [December 4, 2021, 11:44pm UTC](https://forum.arduino.cc/t/help-with-shorting-tft-lcd-print-code/932242/3 "2021-12-04T23:44:19Z")

</div>

make a macro

---

<div class="post-metadata">

**Author:** ![johnwasser](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/johnwasser/32/214270_2.png) [@johnwasser](https://forum.arduino.cc/u/johnwasser)\
**Post date:** [December 5, 2021, 3:14pm UTC](https://forum.arduino.cc/t/help-with-shorting-tft-lcd-print-code/932242/4 "2021-12-05T15:14:32Z")

</div>

A macro like this:

```cpp
#define show(X, Y, Size, Color, Variable, Label) \
  do { \
    tft.setCursor(X, Y); \
    tft.setTextSize(Size); \
    tft.setTextColor(Color); \
    tft.print(Variable); \
    tft.println(Label); \
  } while (false)

show(150, 40, 3, ILI9341_WHITE, Input_Current, "A");
show(250, 0, 1, ILI9341_GREEN, Thermistor1, "°C");
```

---

<div class="post-metadata">

**Author:** ![ifsaguozg](https://avatars.discourse-cdn.com/v4/letter/i/a6a055/32.png) [@ifsaguozg](https://forum.arduino.cc/u/ifsaguozg)\
**Post date:** [December 5, 2021, 3:46pm UTC](https://forum.arduino.cc/t/help-with-shorting-tft-lcd-print-code/932242/5 "2021-12-05T15:46:59Z")

</div>

Yes, thanks so much this is exactly what i was looking for, but i forgot what it was called already 😁

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [June 3, 2022, 3:47pm UTC](https://forum.arduino.cc/t/help-with-shorting-tft-lcd-print-code/932242/6 "2022-06-03T15:47:29Z")

</div>

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
