Saving TFT Touch Display values in an array

Status
Not open for further replies.

topicbird

Active member
Hello! :)

Currently, I'm trying to get the individual x,y-values I draw on my TFT Display (ILI9341) and store them in an array. My plan is to send them to Audio Shield's arbitrary wave synthesizer. My code so far:

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
#define TFT_CS 10
// 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);

int width = 4;
int16_t anArray_X[257] = {0};
int16_t anArray_Y[257] = {0};
byte arrayIndex_X = 0;
byte arrayIndex_Y = 0;

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) {
    int X, Y;
    TS_Point p = ts.getPoint(); // point getter function
    X = p.x - 231;
    X = map(X, 3482, 0, 0, 320);

    //   Serial.print("X:");
    //   Serial.print(p.x);
    //   Serial.println();
    Y = p.y - 360;
    Y = map(Y, 3465, 0, 0, 240);
    tft.fillCircle(X, Y, width, CL(255, 0, 0)); // CL stands for color --> RGB values
    for (arrayIndex_Y = 0; arrayIndex_Y <= 256; arrayIndex_Y++) {
      anArray_Y[arrayIndex_Y] = Y;
      Serial.print("Array Y:");
      Serial.print(anArray_Y[arrayIndex_Y]);
      Serial.println();
    }

    //  Serial.print("Y:");
    //   Serial.print(p.y);
    //   Serial.println();
    //   Serial.println();


  }
  /* for (arrayIndex_X = 0; arrayIndex_X <= 256; arrayIndex_X++) {
    //  anArray_X[arrayIndex_X] = X;
     Serial.print("Array X:");
     Serial.print(anArray_X[arrayIndex_X]);
     Serial.println();
  */

}


Whenever I run the code, it only registers the first dot I draw and won't move on.. Also, it wont draw any more dots with the for-loop in it. I would appreciate any kind of help! Thank you. :)
 
OK i'll take a stab, first thing I see is that your increment amount is a byte 0-255 but your loops go to 256, so at 256, loop counter will got to zero, hence for loop will run infinataly


byte arrayIndex_Y = 0; // 0-255
arrayIndex_Y = 0; arrayIndex_Y <= 256... // this means arrayIndex_Y will top out at 256 (which will loop around to zero at 256 because of byte variable type).

change
int arrayIndex_Y = 0;

Maybe other issues, but see if this gets you further along.
 
Status
Not open for further replies.
Back
Top