Using XPT2046_Touchscreen Library with Audio Shield

Status
Not open for further replies.
I am glad you were able to get that to work. on the 2 projects I have built so far I opted to use one Teensy for the audio shield and another for the ILI9341 display, touch screen and SD card. I also set them up to communicate thru serial ports. I am fairly new to coding in C.

I am also new to coding in C and actually coding altogether. Here is the code I have for the ILI9341Test working with the audio board connections:
Code:
#include <ILI9341_t3.h>
#include <font_Arial.h> // from ILI9341_t3
#include <XPT2046_Touchscreen.h>
#include <SPI.h>

#define CS_PIN  8
//#define TFT_DC  9   //COMMENTED OUT FROM ORIGINAL VERSION
//#define TFT_CS 10   //COMMENTED OUT FROM ORIGINAL VERSION
// MOSI=11, MISO=12, SCK=13

XPT2046_Touchscreen ts(CS_PIN);
#define TIRQ_PIN  2
//XPT2046_Touchscreen ts(CS_PIN);  // Param 2 - NULL - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, 255);  // Param 2 - 255 - No interrupts
//XPT2046_Touchscreen ts(CS_PIN, TIRQ_PIN);  // Param 2 - Touch IRQ Pin - interrupt enabled polling

//ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);  //COMMENTED OUT FROM ORIGINAL VERSION


///////settings from audio tutorial Part 3.03////////
#define TFT_DC      20
#define TFT_CS      21
#define TFT_RST    255  // 255 = unused, connect to 3.3V
#define TFT_MOSI     7
#define TFT_SCLK    14
#define TFT_MISO    12
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC, TFT_RST, TFT_MOSI, TFT_SCLK, TFT_MISO);
/////// end settings from audio tutorial Part 3.03////////



void setup() {
  Serial.begin(38400);
  tft.begin();
  tft.setRotation(1);
  tft.fillScreen(ILI9341_BLACK);
  ts.begin();
  ts.setRotation(1);
  while (!Serial && (millis() <= 1000));
}

boolean wastouched = true;

void loop() {
  boolean istouched = ts.touched();
  if (istouched) {
    TS_Point p = ts.getPoint();
    if (!wastouched) {
      tft.fillScreen(ILI9341_BLACK);
      tft.setTextColor(ILI9341_YELLOW);
      tft.setFont(Arial_60);
      tft.setCursor(60, 80);
      tft.print("Touch");
    }
    tft.fillRect(100, 150, 140, 60, ILI9341_BLACK);
    tft.setTextColor(ILI9341_GREEN);
    tft.setFont(Arial_24);
    tft.setCursor(100, 150);
    tft.print("X = ");
    tft.print(p.x);
    tft.setCursor(100, 180);
    tft.print("Y = ");
    tft.print(p.y);
    Serial.print(", x = ");
    Serial.print(p.x);
    Serial.print(", y = ");
    Serial.println(p.y);
  } else {
    if (wastouched) {
      tft.fillScreen(ILI9341_BLACK);
      tft.setTextColor(ILI9341_RED);
      tft.setFont(Arial_48);
      tft.setCursor(120, 50);
      tft.print("No");
      tft.setCursor(80, 120);
      tft.print("Touch");
    }
    Serial.println("no touch");
  }
  wastouched = istouched;
  delay(100);
}
 
The MSP3218 does actually does have a ILI9341 chip and a XPT2046 chip plus a SD card socket. Can't guarantee that they aren't counterfeits but they are there.
I would have bought mine from PJRC but I thought it said "discontinued" when I was shopping and I wanted a larger display than even the 3.2" I didn't want to give a reference, but I bought mine on eBay and as of a few minutes ago they had 5 left in stock for quick shipment out of the U.S.
 
Status
Not open for further replies.
Back
Top