TFT SPI z PBC ILI9341Touchscreen 320*240 Arduino

Screen: 2.8” 65K Color

Driver IC: ILI9341 / ST7789V

IO logic: 3.3V

Pobierz “Wyświetlacz dotykowy TFT” Wyswietlkacz-dotykowy.pdf – Pobrano 9 razy – 126,52 KB

Połączenie LCD:

TFTVCCGNDCSRESETA0[DC]MOSISCKLEDMISO
ARDUINO5VGND108911133.3V12

1 Przykład użycia

#include <Adafruit_GFX.h>
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CLK 13

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
#include <Fonts/FreeSerif24pt7b.h>  // Add a custom font
int Variable1;                      // Create a variable to have something dynamic to show on the display

void setup() {
  tft.begin();
  tft.fillScreen(0x0000);  // Fill screen with black
  tft.setTextWrap(false);  
  tft.setCursor(0, 30);      // Set position (x,y)
  tft.setTextColor(0xFFFF);  // Set color of text. First is the color of text and after is color of background
  tft.setTextSize(4);
  tft.println("ASTRAJA");                                    
  tft.drawRect(0, 110, 110, 60, 0x07FF); // Draw rectangle (x,y,width,height,color)
}

void loop() {

  Variable1++; 
  if (Variable1 > 150) {
    Variable1 = 0;
  }
  char string[10];  // Create a character array of 10 characters
  // Convert float to a string:
  dtostrf(Variable1, 3, 0, string);  // (<variable>,<amount of digits we are going to use>,<amount of decimal digits>,<string name>)
  tft.setCursor(21, 125);            // Set position (x,y)
  tft.setTextColor(0xFFE0, 0x0000);  // Set color of text. First is the color of text and after is color of background
  tft.setTextSize(4);                // Set text size. Goes from 0 (the smallest) to 20 (very big)
  tft.println(Variable1);            // Print a text or value
    if (Variable1 < 10)  // If Variable1 is less than 10...
  {
    // Fill the other digit with background color:
    tft.fillRect(44, 124, 24, 34, 0x0000);  // Draw filled rectangle (x,y,width,height,color)
  }
  if (Variable1 < 100)  // If Variable1 is less than 100...
  {
    // Fill the other digit with background color:
    tft.fillRect(69, 124, 24, 34, 0x0000);  // Draw filled rectangle (x,y,width,height,color)
  }
}

2 Przykład

#include "Adafruit_ILI9341.h"

#define TFT_DC 9
#define TFT_CS 10
#define TFT_RST 8
#define TFT_MISO 12
#define TFT_MOSI 11
#define TFT_CLK 13

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);
int counter = 0;
void setup() {
  tft.begin();
  tft.setRotation(0);
}

void display() {
  tft.fillScreen(ILI9341_BLACK);
  tft.setTextColor(ILI9341_RED);
  tft.setTextSize(2);
  tft.setCursor(1, 20);
  tft.print("ASTRAJA");

  tft.setTextColor(ILI9341_GREEN);
  tft.setTextSize(3);
  tft.setCursor(1, 120);
  tft.print("COUNTER:");

  tft.setTextColor(ILI9341_BLUE);
  tft.setTextSize(6);
  tft.setCursor(1, 180);
  tft.print(counter);
  counter++;
  delay(100);
}
void loop() {
  display();
}

3 Przykład z funkcją touch

Połączenie touch screen:

TFTT_CLKT_CST_DINT_DOT_IRQ
ARDUINO34567

Biblioteka URTouch: http://www.rinkydinkelectronics.com/library.php?id=92#google_vignette

#include "Adafruit_GFX.h"     
#include "Adafruit_ILI9341.h" 
#include "URTouch.h"          

#define TFT_DC 9              
#define TFT_CS 10            
#define TFT_RST 8
#define TFT_MISO 12         
#define TFT_MOSI 11           
#define TFT_CLK 13            

Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_MOSI, TFT_CLK, TFT_RST, TFT_MISO);

#define t_SCK 3              
#define t_CS 4                
#define t_MOSI 5              
#define t_MISO 6             
#define t_IRQ 7              

URTouch ts(t_SCK, t_CS, t_MOSI, t_MISO, t_IRQ);

void setup(){
  tft.begin();                     
  tft.setRotation(3);           
 
  ts.InitTouch();                   
  ts.setPrecision(PREC_EXTREME);
  tft.fillScreen(ILI9341_BLACK);

  tft.setTextColor(ILI9341_RED);  
  tft.setTextSize(2);               
  tft.setCursor(85,5);              
  tft.print("Touch Demo"); 
}
 
void loop(){
  int x, y;                        
 
  while(ts.dataAvailable())        
  {
    ts.read();                      
    x = ts.getX();                 
    y = ts.getY();                  
    if((x!=-1) && (y!=-1))          
    {
      x += 13;                      
      y += 4;                       
      int radius = 4;               
      tft.fillCircle(x, y, radius, ILI9341_YELLOW);
    }
  }
}

Leave a Comment

Scroll to Top