Advertisement
pleasedontcode

**Display Messages** rev_01

Feb 25th, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /********* Pleasedontcode.com **********
  2.  
  3.     Pleasedontcode thanks you for automatic code generation! Enjoy your code!
  4.  
  5.     - Terms and Conditions:
  6.     You have a non-exclusive, revocable, worldwide, royalty-free license
  7.     for personal and commercial use. Attribution is optional; modifications
  8.     are allowed, but you're responsible for code maintenance. We're not
  9.     liable for any loss or damage. For full terms,
  10.     please visit pleasedontcode.com/termsandconditions.
  11.  
  12.     - Project: **Display Messages**
  13.     - Source Code NOT compiled for: Arduino Mega
  14.     - Source Code created on: 2025-02-25 21:29:44
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* it is necessary to optimize and improve the code. */
  21.     /* Make a design on a TFT screen */
  22. /****** END SYSTEM REQUIREMENTS *****/
  23.  
  24. /* START CODE */
  25.  
  26. /****** DEFINITION OF LIBRARIES *****/
  27. #include <SPI.h>
  28. #include <Adafruit_ILI9341.h>   //https://github.com/adafruit/Adafruit_ILI9341
  29. #include <U8g2_for_Adafruit_GFX.h>  //https://github.com/olikraus/U8g2_for_Adafruit_GFX
  30.  
  31. /****** FUNCTION PROTOTYPES *****/
  32. void setup(void);
  33. void loop(void);
  34. void updateOutputs();
  35. void displayMessage(const char* message);
  36.  
  37. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  38. const uint8_t myTFT_ILI9341_TFT_RST_PIN_D2      = 2;
  39. const uint8_t myTFT_ILI9341_TFT_DC_PIN_D3       = 3;
  40.  
  41. /***** DEFINITION OF SPI PINS *****/
  42. const uint8_t myTFT_ILI9341_TFT_SPI_PIN_MOSI_D51        = 51;
  43. const uint8_t myTFT_ILI9341_TFT_SPI_PIN_MISO_D50        = 50;
  44. const uint8_t myTFT_ILI9341_TFT_SPI_PIN_SCLK_D52        = 52;
  45. const uint8_t myTFT_ILI9341_TFT_SPI_PIN_CS_D53      = 53;
  46.  
  47. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  48. bool    myTFT_ILI9341_TFT_RST_PIN_D2_rawData        = 0;
  49. bool    myTFT_ILI9341_TFT_DC_PIN_D3_rawData     = 0;
  50.  
  51. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  52. float   myTFT_ILI9341_TFT_RST_PIN_D2_phyData        = 0.0;
  53. float   myTFT_ILI9341_TFT_DC_PIN_D3_phyData     = 0.0;
  54.  
  55. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  56. // Create instances for the TFT display and U8g2
  57. Adafruit_ILI9341 tft(myTFT_ILI9341_TFT_SPI_PIN_CS_D53, myTFT_ILI9341_TFT_DC_PIN_D3, -1); // -1 for RST pin
  58. U8G2_FOR_ADAFRUIT_GFX u8g2;
  59.  
  60. void setup(void)
  61. {
  62.     // Initialize the TFT display
  63.     tft.begin();
  64.     tft.setRotation(3); // Set rotation if needed
  65.     tft.fillScreen(ILI9341_BLACK); // Clear the screen
  66.  
  67.     // Initialize U8g2 with the TFT display
  68.     u8g2.begin(tft);
  69.     u8g2.setFont(u8g2_font_ncenB08_tr); // Set a font for U8g2
  70.  
  71.     pinMode(myTFT_ILI9341_TFT_RST_PIN_D2, OUTPUT);
  72.     pinMode(myTFT_ILI9341_TFT_DC_PIN_D3, OUTPUT);
  73.     pinMode(myTFT_ILI9341_TFT_SPI_PIN_CS_D53, OUTPUT);
  74.     SPI.begin();
  75. }
  76.  
  77. void loop(void)
  78. {
  79.     // Refresh output data
  80.     updateOutputs();
  81.  
  82.     // Display a message on the TFT screen
  83.     displayMessage("Hello, TFT Display!");
  84.     delay(1000); // Delay for demonstration purposes
  85. }
  86.  
  87. void updateOutputs()
  88. {
  89.     digitalWrite(myTFT_ILI9341_TFT_RST_PIN_D2, myTFT_ILI9341_TFT_RST_PIN_D2_rawData);
  90.     digitalWrite(myTFT_ILI9341_TFT_DC_PIN_D3, myTFT_ILI9341_TFT_DC_PIN_D3_rawData);
  91. }
  92.  
  93. void displayMessage(const char* message)
  94. {
  95.     tft.fillScreen(ILI9341_BLACK); // Clear the screen
  96.     u8g2.setCursor(10, 20); // Set cursor position
  97.     u8g2.print(message); // Print the message
  98.     u8g2.sendBuffer(); // Send the buffer to the display
  99. }
  100.  
  101. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement