3.2" TFT Touchscreen with a Pi Looper

EL Wire/Tape/Panels, LEDs, pixels and strips, LCDs and TFTs, etc products from Adafruit

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
User avatar
Kuffcakes
 
Posts: 49
Joined: Sun Oct 08, 2017 12:23 am

Re: 3.2" TFT Touchscreen with a Pi Looper

Post by Kuffcakes »

I tried to modify the code and received no errors compiling it. The Pure Data patch will not work now so that's new.
I don't know if this code is on the right track to make the touchscreen work.

Code: Select all

//NintendoScreen
#define YP A7
#define XM A8
#define YM A12
#define XP A13

int readtouchX;
int readtouchY;
int fxTogOn = 0;
int fxTogOff = 1; 
unsigned long readTime;
unsigned long prevReadTime;
unsigned long readTimeTwo;
unsigned long prevReadTimeTwo;

int getSmooth(int pin){
  int vals[10]; //array that stores 10 readings.
  for(int i = 0; i < 10; i++){
    vals[i] = analogRead(pin); //takes 10 readings.
  }
  float smooth = (vals[0] + vals[1] + vals[2] + vals[3] + vals[4] + vals[5] + vals[6] + vals[7] + vals[8] + vals[9]) / 10;
  return smooth;
}

TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);

Code: Select all

 //NDS_TOUCH
  //limit reads to 5ms
  TSPoint p = ts.getPoint();
  readTime = millis();
  //readtouchX = readtouchX();
  //readtouchY = Touchscreen();

  if ((readtouchX < 900) && (readtouchY < 900)){
    if(readTime - prevReadTime > 16){

 if (p.z > ts.pressureThreshhold) {
    Serial.print("X = "); 
    Serial.print(p.x);
    Serial.print("\tY = "); 
    Serial.print(p.y);
    Serial.print("\tPressure = "); 
    Serial.println(p.z);
    fxTogOn = 1;
    fxTogOff = 0; 
    prevReadTime = readTime;
    }
  }else{
    if (abs(fxTogOn - fxTogOff) > 0){
      Serial.print("postTog: ");
      Serial.print(0);
      Serial.print(" ");
      Serial.println(0);
      fxTogOff = fxTogOn;  
    }
  }  
 delay(100);
 }

User avatar
Kuffcakes
 
Posts: 49
Joined: Sun Oct 08, 2017 12:23 am

Re: 3.2" TFT Touchscreen with a Pi Looper

Post by Kuffcakes »

I used chatgpt to analyze the code. It was a minor change. It had me assign values to readtouchX and readtouchY.

Code: Select all

//NDS_TOUCH
  //limit reads to 5ms
  TSPoint p = ts.getPoint();
  readTime = millis();
  // Assign values to readtouchX and readtouchY
  readtouchX = p.x;
  readtouchY = p.y;

  if ((readtouchX < 900) && (readtouchY < 900)) {
    if (readTime - prevReadTime > 16) {
      if (p.z > ts.pressureThreshhold) {
        Serial.print("X = "); 
        Serial.print(p.x);
        Serial.print("\tY = "); 
        Serial.print(p.y);
        Serial.print("\tPressure = "); 
        Serial.println(p.z);
        fxTogOn = 1;
        fxTogOff = 0; 
        prevReadTime = readTime;
      }
    
  } else {
    if (abs(fxTogOn - fxTogOff) > 0) {
      Serial.print("postTog: ");
      Serial.print(0);
      Serial.print(" ");
      Serial.println(0);
      fxTogOff = fxTogOn;  
    }
  }  
  delay(100);
}

Locked
Please be positive and constructive with your questions and comments.

Return to “Glowy things (LCD, LED, TFT, EL) purchased at Adafruit”