Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /********* Pleasedontcode.com **********
- Pleasedontcode thanks you for automatic code generation! Enjoy your code!
- - Terms and Conditions:
- You have a non-exclusive, revocable, worldwide, royalty-free license
- for personal and commercial use. Attribution is optional; modifications
- are allowed, but you're responsible for code maintenance. We're not
- liable for any loss or damage. For full terms,
- please visit pleasedontcode.com/termsandconditions.
- - Project: **Display Messages**
- - Source Code NOT compiled for: Arduino Mega
- - Source Code created on: 2025-02-25 21:29:44
- ********* Pleasedontcode.com **********/
- /****** SYSTEM REQUIREMENTS *****/
- /****** SYSTEM REQUIREMENT 1 *****/
- /* it is necessary to optimize and improve the code. */
- /* Make a design on a TFT screen */
- /****** END SYSTEM REQUIREMENTS *****/
- /* START CODE */
- /****** DEFINITION OF LIBRARIES *****/
- #include <SPI.h>
- #include <Adafruit_ILI9341.h> //https://github.com/adafruit/Adafruit_ILI9341
- #include <U8g2_for_Adafruit_GFX.h> //https://github.com/olikraus/U8g2_for_Adafruit_GFX
- /****** FUNCTION PROTOTYPES *****/
- void setup(void);
- void loop(void);
- void updateOutputs();
- void displayMessage(const char* message);
- /***** DEFINITION OF DIGITAL OUTPUT PINS *****/
- const uint8_t myTFT_ILI9341_TFT_RST_PIN_D2 = 2;
- const uint8_t myTFT_ILI9341_TFT_DC_PIN_D3 = 3;
- /***** DEFINITION OF SPI PINS *****/
- const uint8_t myTFT_ILI9341_TFT_SPI_PIN_MOSI_D51 = 51;
- const uint8_t myTFT_ILI9341_TFT_SPI_PIN_MISO_D50 = 50;
- const uint8_t myTFT_ILI9341_TFT_SPI_PIN_SCLK_D52 = 52;
- const uint8_t myTFT_ILI9341_TFT_SPI_PIN_CS_D53 = 53;
- /***** DEFINITION OF OUTPUT RAW VARIABLES *****/
- bool myTFT_ILI9341_TFT_RST_PIN_D2_rawData = 0;
- bool myTFT_ILI9341_TFT_DC_PIN_D3_rawData = 0;
- /***** DEFINITION OF OUTPUT PHYSICAL VARIABLES *****/
- float myTFT_ILI9341_TFT_RST_PIN_D2_phyData = 0.0;
- float myTFT_ILI9341_TFT_DC_PIN_D3_phyData = 0.0;
- /****** DEFINITION OF LIBRARIES CLASS INSTANCES*****/
- // Create instances for the TFT display and U8g2
- Adafruit_ILI9341 tft(myTFT_ILI9341_TFT_SPI_PIN_CS_D53, myTFT_ILI9341_TFT_DC_PIN_D3, -1); // -1 for RST pin
- U8G2_FOR_ADAFRUIT_GFX u8g2;
- void setup(void)
- {
- // Initialize the TFT display
- tft.begin();
- tft.setRotation(3); // Set rotation if needed
- tft.fillScreen(ILI9341_BLACK); // Clear the screen
- // Initialize U8g2 with the TFT display
- u8g2.begin(tft);
- u8g2.setFont(u8g2_font_ncenB08_tr); // Set a font for U8g2
- pinMode(myTFT_ILI9341_TFT_RST_PIN_D2, OUTPUT);
- pinMode(myTFT_ILI9341_TFT_DC_PIN_D3, OUTPUT);
- pinMode(myTFT_ILI9341_TFT_SPI_PIN_CS_D53, OUTPUT);
- SPI.begin();
- }
- void loop(void)
- {
- // Refresh output data
- updateOutputs();
- // Display a message on the TFT screen
- displayMessage("Hello, TFT Display!");
- delay(1000); // Delay for demonstration purposes
- }
- void updateOutputs()
- {
- digitalWrite(myTFT_ILI9341_TFT_RST_PIN_D2, myTFT_ILI9341_TFT_RST_PIN_D2_rawData);
- digitalWrite(myTFT_ILI9341_TFT_DC_PIN_D3, myTFT_ILI9341_TFT_DC_PIN_D3_rawData);
- }
- void displayMessage(const char* message)
- {
- tft.fillScreen(ILI9341_BLACK); // Clear the screen
- u8g2.setCursor(10, 20); // Set cursor position
- u8g2.print(message); // Print the message
- u8g2.sendBuffer(); // Send the buffer to the display
- }
- /* END CODE */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement