Variable output on tft

Hello, i want to show a variable on my ILI9341 TFT screen but i need help.

My code:

/**********************************************************************
 
 Interfacing ESP8266 NodeMCU with ILI9341 TFT display (240x320 pixel).
 This is a free software with NO WARRANTY.
 https://simple-circuit.com/
 
/**********************************************************************
/**********************************************************************
  This is our GFX example for the Adafruit ILI9341 Breakout and Shield
  ----> http://www.adafruit.com/products/1651
 
  Check out the links above for our tutorials and wiring diagrams
  These displays use SPI to communicate, 4 or 5 pins are required to
  interface (RST is optional)
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing
  products from Adafruit!
 
  Written by Limor Fried/Ladyada for Adafruit Industries.
  MIT license, all text above must be included in any redistribution
 **********************************************************************/
 
 
#include <Adafruit_GFX.h>       // include Adafruit graphics library
#include <Adafruit_ILI9341.h>   // include Adafruit ILI9341 TFT library


#define TFT_CS    D2     // TFT CS  pin is connected to NodeMCU pin D2
#define TFT_RST   D3     // TFT RST pin is connected to NodeMCU pin D3
#define TFT_DC    D4     // TFT DC  pin is connected to NodeMCU pin D4
// initialize ILI9341 TFT library with hardware SPI module
// SCK (CLK) ---> NodeMCU pin D5 (GPIO14)
// MOSI(DIN) ---> NodeMCU pin D7 (GPIO13)
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
 
void setup() {
  Serial.begin(9600);
  Serial.println("ILI9341 Test!"); 
  tft.begin();
  tft.setRotation(1);
 
  // read diagnostics (optional but can help debug problems)
  uint8_t x = tft.readcommand8(ILI9341_RDMODE);
  Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDMADCTL);
  Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDPIXFMT);
  Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDIMGFMT);
  Serial.print("Image Format: 0x"); Serial.println(x, HEX);
  x = tft.readcommand8(ILI9341_RDSELFDIAG);
  Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX); 
  
  Serial.println(F("Benchmark                Time (microseconds)"));


 
  Serial.print(F("Text                     "));
  Serial.println(testText());
  Serial.println(F("Done!"));


 
}


byte runXTimes = 0;


void loop() {
if (runXTimes)
 {
 testText();
    runXTimes--;
 }
  
}


String myvariable = test;


unsigned long testText() {
  tft.fillScreen(ILI9341_BLACK);
  tft.setCursor(40, 55);
  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(2);
  tft.println("myvariable");
}

And the error i become is:
1time_tft:74:21: error: 'test' was not declared in this scope
String myvariable = test;
^
exit status 1
'test' was not declared in this scope

can someone help me please, i'm new with Arduino.
Thanks!

Regards
Alex

Did you mean "testText"?

testText works but i want to output the text of myvariable

grumpy_oleg:
testText works but i want to output the text of myvariable

What do you expect that to be?

String myvariable = test;

The variable named test is not declared in the sketch so no wonder you get an error

What exactly do you want to print ?

Your codeline

String myvariable = test;

assigns the variable myvariable the content of the variable named test.
One quick and easy way to get your code running is use a string-constant like this

String myvariable = "Hello World";

hardcoded strings always needs double-hyphens at most left and most right "
single characters stored in variables of type char need single-hyphens 'A'
You shouldn't use variable-type String for real code.
variables of type String eat up all memory over time when you re-assign values to it.
This leads to very hard to debug errors.
You should use the library PString or SafeString.

For learning programming in general Take a look into this tutorial:
Arduino Programming Course
It is easy to understand and has a good mixture between explaining important concepts and example-codes to get you going. So give it a try and report your opinion about this tutorial.

best regards Stefan

hardcoded strings always needs double-hyphens

Stefan - there maybe a language problem here. What do you mean by a hyphen ?

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