ok sorry for not being clear enough.
So when i touch the screen, say in x direction 100 and y direction 100 i would like the rectangular block to be drawn. so if i touch x=100 i want the block to be 10 pixel tall 20 pixel width.
currently it only work the way that if i touch the screen, the rect block is being drawn but its drawn down, where normally graph is going either from left to right or bottom to top, so i dont know how to invert this formula.
also, once the rect is drawn,it wont clear if the value x is lover the the previous higher x
this video may be a lot more helpfull than my description. you can see vertical columns going up and down.
//This example implements a simple sliding On/Off button. The example
// demonstrates drawing and touch operations.
//
//Thanks to Adafruit forums member Asteroid for the original sketch!
//
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <Wire.h>
#include <Adafruit_ILI9341.h>
#include <Adafruit_FT6206.h>
#include <Fonts/FreeMonoBoldOblique12pt7b.h>
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ts = Adafruit_FT6206();
// This is calibration data for the raw touch data to the screen coordinates
#define TS_MINX 150
#define TS_MINY 130
#define TS_MAXX 3800
#define TS_MAXY 4000
//
#define TFT_CS 9
#define TFT_DC 7
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
boolean RecordOn = false;
void setup(void)
{
Serial.begin(9600);
tft.begin();
if (!ts.begin(40)) {
SerialUSB.println("Unable to start touchscreen.");
}
else {
SerialUSB.println("Touchscreen started.");
}
tft.fillScreen(ILI9341_BLACK);
// origin = left,top landscape (USB left upper)
tft.setRotation(0);
}
void loop()
{
// See if there's any touch data for us
if (ts.touched()) {
// Retrieve a point
TS_Point p = ts.getPoint();
// rotate coordinate system
// flip it around to match the screen.
//p.x = map(p.x, 0, 240, 240, 0);
//p.y = map(p.y, 0, 320, 320, 0);
int y = p.y;
int x = p.x;
SerialUSB.print("x = ");
SerialUSB.print(x);
SerialUSB.print(" y = ");
SerialUSB.println(y);
// tft.setFont(&FreeMonoBoldOblique12pt7b);
tft.setCursor(20, 20);
tft.setTextColor(ILI9341_CYAN, ILI9341_BLACK);
tft.setTextSize(5);
tft.print("x = ");
tft.println(x);
tft.setCursor(20, 120);
tft.setTextColor(ILI9341_MAGENTA, ILI9341_BLACK);
tft.setTextSize(5);
tft.print("y = ");
tft.println(y);
if (x < 10)
{
tft.setCursor(170, 20);
tft.print(" ");
}
if (x < 100)
{
tft.setCursor(200, 20);
tft.print(" ");
}
if (y < 10)
{
tft.setCursor(170, 120);
tft.print(" ");
}
if (y < 100)
{
tft.setCursor(200, 120);
tft.print(" ");
}
tft.fillRect(100, 220, 20, x / 10, ILI9341_WHITE); //draw rectangual block in position x=100, y=200 width=20 pixel, tall= value x divided by 10(240 pixel screen i want 24 pixel block) on the scree based on where you touch on he screen in x direction
}
}