Advertisement
microrobotics

TFT 4-inch ST7796S Display Sample Code

Sep 23rd, 2023
1,344
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <Adafruit_GFX.h>    // Core graphics library
  2. #include <Adafruit_ST7735.h> // Hardware-specific library for ST7735
  3.  
  4. // Define the pins for the display (change these to match your wiring)
  5. #define TFT_RST    9
  6. #define TFT_DC     8
  7. #define TFT_CS     10
  8.  
  9. // Create an instance of the Adafruit_ST7735 class
  10. Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_RST);
  11.  
  12. void setup() {
  13.   // Initialize the display
  14.   tft.initR(INITR_BLACKTAB); // You may need to adjust the initialization type
  15.  
  16.   // Set the rotation (you may need to adjust this to match your display orientation)
  17.   tft.setRotation(1); // Use 0, 1, 2, or 3 depending on your needs
  18.  
  19.   // Clear the screen and set text color
  20.   tft.fillScreen(ST77XX_BLACK);
  21.   tft.setTextColor(ST77XX_WHITE);
  22.  
  23.   // Set the font size
  24.   tft.setTextSize(2);
  25. }
  26.  
  27. void loop() {
  28.   // Clear the screen
  29.   tft.fillScreen(ST77XX_BLACK);
  30.  
  31.   // Display some text
  32.   tft.setCursor(10, 10);
  33.   tft.print("Hello, Arduino!");
  34.  
  35.   delay(2000); // Delay for 2 seconds
  36. }
  37.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement