Advertisement
pleasedontcode

**Display Initialization** rev_02

May 1st, 2025
133
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 Initialization**
  13.     - Source Code NOT compiled for: ESP32 DevKit V1
  14.     - Source Code created on: 2025-05-01 07:34:51
  15.  
  16. ********* Pleasedontcode.com **********/
  17.  
  18. /****** SYSTEM REQUIREMENTS *****/
  19. /****** SYSTEM REQUIREMENT 1 *****/
  20.     /* Enable the Obsidian ESP32 board to control the */
  21.     /* ILI9341 TFT display, utilizing SPI communication */
  22.     /* for efficient data transfer. Ensure proper */
  23.     /* initialization of the display and manage output */
  24.     /* states for the reset and data command pins. */
  25. /****** END SYSTEM REQUIREMENTS *****/
  26.  
  27. /* START CODE */
  28.  
  29. /****** DEFINITION OF LIBRARIES *****/
  30. #include <SPI.h>
  31. #include <Adafruit_ILI9341.h>    //https://github.com/adafruit/Adafruit_ILI9341
  32. #include <U8g2_for_Adafruit_GFX.h>    //https://github.com/olikraus/U8g2_for_Adafruit_GFX
  33.  
  34. /****** FUNCTION PROTOTYPES *****/
  35. void setup(void);
  36. void loop(void);
  37. void updateOutputs();
  38. void initializeDisplay();
  39.  
  40. /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
  41. const uint8_t dis_ILI9341_TFT_RST_PIN_D4        = 4;
  42. const uint8_t dis_ILI9341_TFT_DC_PIN_D13        = 13;
  43.  
  44. /***** DEFINITION OF SPI PINS *****/
  45. const uint8_t dis_ILI9341_TFT_SPI_PIN_MOSI_D23      = 23;
  46. const uint8_t dis_ILI9341_TFT_SPI_PIN_MISO_D19      = 19;
  47. const uint8_t dis_ILI9341_TFT_SPI_PIN_SCLK_D18      = 18;
  48. const uint8_t dis_ILI9341_TFT_SPI_PIN_CS_D5         = 5;
  49.  
  50. /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
  51. /***** used to store raw data *****/
  52. bool    dis_ILI9341_TFT_RST_PIN_D4_rawData        = 0;
  53. bool    dis_ILI9341_TFT_DC_PIN_D13_rawData        = 0;
  54.  
  55. /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
  56. /***** used to store data after characteristic curve transformation *****/
  57. float   dis_ILI9341_TFT_RST_PIN_D4_phyData        = 0.0;
  58. float   dis_ILI9341_TFT_DC_PIN_D13_phyData        = 0.0;
  59.  
  60. /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
  61. // Instantiate the display object
  62. Adafruit_ILI9341 display(dis_ILI9341_TFT_SPI_PIN_CS_D5, dis_ILI9341_TFT_DC_PIN_D13, dis_ILI9341_TFT_SPI_PIN_MOSI_D23, dis_ILI9341_TFT_SPI_PIN_SCLK_D18, dis_ILI9341_TFT_RST_PIN_D4);
  63.  
  64. void setup(void)
  65. {
  66.     // put your setup code here, to run once:
  67.     pinMode(dis_ILI9341_TFT_RST_PIN_D4, OUTPUT);
  68.     pinMode(dis_ILI9341_TFT_DC_PIN_D13, OUTPUT);
  69.     pinMode(dis_ILI9341_TFT_SPI_PIN_CS_D5, OUTPUT);
  70.    
  71.     // start the SPI library:
  72.     SPI.begin();
  73.    
  74.     // Initialize the display
  75.     initializeDisplay();
  76. }
  77.  
  78. void loop(void)
  79. {
  80.     // put your main code here, to run repeatedly:
  81.     updateOutputs(); // Refresh output data
  82. }
  83.  
  84. void updateOutputs()
  85. {
  86.     digitalWrite(dis_ILI9341_TFT_RST_PIN_D4, dis_ILI9341_TFT_RST_PIN_D4_rawData);
  87.     digitalWrite(dis_ILI9341_TFT_DC_PIN_D13, dis_ILI9341_TFT_DC_PIN_D13_rawData);
  88. }
  89.  
  90. void initializeDisplay() {
  91.     // Initialize the display
  92.     display.begin();
  93.     display.setRotation(3); // Set the rotation of the display
  94.     display.fillScreen(ILI9341_BLACK); // Clear the screen with black color
  95. }
  96.  
  97. /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement