/**
ESP32s3 adaptation by Tyeth Gundry of Arduino version of
First demo for FT6206 Capactive Touch Screen on Wokwi. Enjoy!
https://wokwi.com/arduino/projects/311598148845830720
*/
/***************************************************
This is our touchscreen painting example for the Adafruit ILI9341
captouch shield
----> http://www.adafruit.com/products/1947
Check out the links above for our tutorials and wiring diagrams
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
#include <Adafruit_GFX.h> // Core graphics library
#include <SPI.h> // this is needed for display
#include <Adafruit_ILI9341.h>
#include <Arduino.h> // this is needed for FT6206
#include <Adafruit_FT6206.h>
// The FT6206 uses hardware I2C (SCL/SDA)
Adafruit_FT6206 ctp = Adafruit_FT6206();
// // The display also uses hardware SPI, plus #9 & #10
// #define TFT_CS 10
// #define TFT_DC 9
#define TFT_DC 2
#define TFT_CS 15
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
int meas;
int PIN1;
int ygscale=58;
int ylong=290;
void setup(void) {
PIN1=20;
Serial.begin(9600);
//_______________Acquisition____________________________________
pinMode(PIN1, INPUT);
//______________________Affichage__________________________________
//while (!Serial); // used for leonardo debugging
//Serial.begin(115200);
Wire.setPins(10, 8); // redefine first I2C port to be on pins 10/8
tft.begin();
// if (! ctp.begin(40)) { // pass in 'sensitivity' coefficient
// Serial.println("Couldn't start FT6206 touchscreen controller");
// while (1);
// }
//COULEUR fond d'écran: ILI9341_WHITE /RED/YELLOW/GREEN/CYAN/BLUE/MAGENTA/WHITE
tft.fillScreen(ILI9341_BLACK);
//Tracer rectangle plein
//tft.fillRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_RED);
//Tracer rectangle vide
//tft.drawRect(0, 0, BOXSIZE, BOXSIZE, ILI9341_WHITE);
//Tracer ligne
//tft.drawLine(20, 20, 20, 300, ILI9341_WHITE);
//_______________________________________________________
//Graphique
//x
//grille
for (int i=0; i<221; i+=55){
tft.drawLine(10+i, 20, 10+i, 310, ILI9341_RED);
}
//abscice
tft.drawLine(119, 19, 119, 310, ILI9341_WHITE);
tft.drawLine(120, 20, 120, 310, ILI9341_WHITE);
tft.drawLine(121, 20, 121, 310, ILI9341_WHITE);
//y
//grille
for (int i=0; i<ylong; i+=ygscale){
tft.drawLine(10, 20+i, 230, 20+i, ILI9341_RED);
}
//Ordonnée
tft.drawLine(10, 19, 230, 19, ILI9341_WHITE);
tft.drawLine(10, 20, 230, 20, ILI9341_WHITE);
tft.drawLine(10, 21, 230, 21, ILI9341_WHITE);
//Légende V &t
tft.setRotation(3);
tft.setCursor(290, 130);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.println("t");
tft.setCursor(30, 20);
//tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
tft.println("V");
}
int lmeas[300];
int i=0;
int k=0;
int j=1;
int h;
int dpt=5;
int inc=2;
char color=ILI9341_CYAN;
char colorf=ILI9341_BLACK;
void loop() {
//delay(500);
//________________Acquisition________________________
meas=analogRead(PIN1);
meas=map(meas,0,8191,10,230);
//Serial.println(meas);
i=i+inc;
if (i==280){
h=ylong-i;
tft.fillCircle(h+inc, lmeas[j], dpt, colorf);
i=0;
}
k=k+1;
if (k==2){
k=0;
}
j=j-1;
if (j==-1){
j=1;
}
lmeas[k]=meas;
tft.fillCircle(ylong-i, lmeas[k], dpt, color);
tft.fillCircle(ylong-i+inc, lmeas[j], dpt, colorf);
// / int ygscale=58;
// int ylong=290;
int a=ylong-i+inc;
Serial.println(a);
if(a==20+58){
tft.fillCircle(ylong-i+inc, lmeas[j], 1, ILI9341_RED);
}
//__________________affichage_____________________________
// Wait for a touch
// if (! ctp.touched()) {
// return;
// }
// Retrieve a point (récupérer coordonnées appui tactile)
//TS_Point p = ctp.getPoint();
// flip it around to match the screen. map(value,ancienne, plage, nouvelle, plage)
// p.x = map(p.x, 0, 240, 240, 0);
// p.y = map(p.y, 0, 320, 320, 0);
}
////////////////////////////////////////////////////////////////////////////////////