#include <Wire.h>
#include <SoftwareSerial.h>
#define SoftwareSerial Serial1
#define RX = 19
#define TX = 18
#define SoftwareSerial Serial2
#define RX = 17
#define TX = 16
#include <TouchScreen.h>
#include <Elegoo_TFTLCD.h>
#include <pin_magic.h>
#include <registers.h>
#include <Elegoo_GFX.h>
/* For Arduinoboards with multiple serial ports like DUEboard, interpret above two pieces of code and
directly use Serial1 serial port*/
#define LCD_CS A3 // Chip Select goes to Analog 3
#define LCD_CD A2 // Command/Data goes to Analog 2
#define LCD_WR A1 // LCD Write goes to Analog 1
#define LCD_RD A0 // LCD Read goes to Analog 0
#define LCD_RESET A4 // Can alternately just connect to Arduino's reset pin
// Assign human-readable names to some common 16-bit color values:
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
#define YP A3 // must be an analog pin, use "An" notation!
#define XM A2 // must be an analog pin, use "An" notation!
#define YM 9 // can be a digital pin
#define XP 8 // can be a digital pin
//Touch For New ILI9341 TP
#define TS_MINX 124
#define TS_MAXX 924
#define TS_MINY 150
#define TS_MAXY 900
// We have a status line for like, is FONA working
#define STATUS_X 10
#define STATUS_Y 65
Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET)
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300)
// If using the shield, all control and data lines are fixed, and
// a simpler declaration can optionally be used:
// Elegoo_TFTLCD tft
boolean buttonEnabled = true
// capteur Bas
int dist1 =0
int strength1
int check1
int i1
int uart1[9]
const int HEADER=0x59
// capteur haut
int dist2 = 0
int strength2
int check2
int i2
int uart2[9]
const int HEADER2=0x59
void setup()
{
Serial.begin(115200)
Serial1.begin(115200)
Serial2.begin(115200)
Serial.println(F("TFT LCD test"))
#ifdef USE_Elegoo_SHIELD_PINOUT
Serial.println(F("Using Elegoo 2.8\" TFT Arduino Shield Pinout"))
#else
Serial.println(F("Using Elegoo 2.8\" TFT Breakout Board Pinout"))
#endif
Serial.print("TFT size is ")
uint16_t identifier = tft.readID()
if(identifier == 0x9325) {
Serial.println(F("Found ILI9325 LCD driver"))
} else if(identifier == 0x9328) {
Serial.println(F("Found ILI9328 LCD driver"))
} else if(identifier == 0x4535) {
Serial.println(F("Found LGDP4535 LCD driver"))
}else if(identifier == 0x7575) {
Serial.println(F("Found HX8347G LCD driver"))
} else if(identifier == 0x9341) {
Serial.println(F("Found ILI9341 LCD driver"))
} else if(identifier == 0x8357) {
Serial.println(F("Found HX8357D LCD driver"))
} else if(identifier==0x0101)
{
identifier=0x9341
Serial.println(F("Found 0x9341 LCD driver"))
}else {
Serial.print(F("Unknown LCD driver chip: "))
Serial.println(identifier, HEX)
Serial.println(F("If using the Elegoo 2.8\" TFT Arduino shield, the line:"))
Serial.println(F(" #define USE_Elegoo_SHIELD_PINOUT"))
Serial.println(F("should appear in the library header (Elegoo_TFT.h)."))
Serial.println(F("If using the breakout board, it should NOT be #defined!"))
Serial.println(F("Also if using the breakout, double-check that all wiring"))
Serial.println(F("matches the tutorial."))
identifier=0x9341
}
tft.reset()
tft.begin(identifier)
tft.setRotation(0)
tft.fillScreen(BLACK)
// page principale
tft.drawRect(0,0,240,320,CYAN)
tft.setCursor(10,10)
tft.setTextSize(3)
tft.setTextColor(CYAN)
tft.print("LASER ")
tft.setCursor(50,50)
tft.setTextSize(2)
tft.setTextColor(RED)
tft.print("By lm")
tft.fillRect(15,180,200,40, RED)
tft.drawRect(15,180,200,40, CYAN)
tft.setCursor(30, 190)
tft.setTextColor(WHITE)
tft.setTextSize(3)
tft.print(" MESURES")
delay(500)
tft.fillScreen(BLACK)
TSPoint p = ts.getPoint()
if (p.z > ts.pressureThreshhold) {
p.x = map(p.x, TS_MAXX, TS_MINX, 0, 320)
p.y = map(p.y, TS_MAXY, TS_MINY, 0, 240)
delay(10)
}
pinMode(XM, OUTPUT)
pinMode(YP, OUTPUT)
}
void loop()
{
Unsigned long D = 0
// capteur bas
tft.setCursor(60, 20)
tft.setTextColor(WHITE, BLACK)
tft.setTextSize(2)
tft.print("Dist1 = ")
tft.setCursor(60, 40)
tft.print((dist1)/100.00)
tft.print('\t')
if (Serial1.available())//check if serial port has data input
{
if(Serial1.read()==HEADER)//assess data package frame header 0x59
{
uart1[0]=HEADER
if(Serial1.read()==HEADER)//assess data package frame header 0x59
{
uart1[1]=HEADER
for(i1=2
{
uart1[i1]=Serial1.read()
}
check1=uart1[0]+uart1[1]+uart1[2]+uart1[3]+uart1[4]+uart1[5]+uart1[6]+uart1[7]
if(uart1[8]==(check1&0xff))//verify the received data as per protocol
{
dist1=uart1[2]+uart1[3]*256
strength1=uart1[4]+uart1[5]*256
}
}
}
}
delay(50)
D +=dist1
// capteur haut
tft.setCursor(60, 60)
tft.setTextColor(WHITE, BLACK)
tft.setTextSize(2)
tft.print("Dist2 = ")
tft.setCursor(60, 80)
tft.print((dist2)/100.00,2)
tft.print('\t')
if (Serial2.available())//check if serial port has data input
{
if(Serial2.read()==HEADER2)//assess data package frame header 0x59
{
uart2[0]=HEADER2
if(Serial2.read()==HEADER2)//assess data package frame header 0x59
{
uart2[1]=HEADER2
for(i2=2
{
uart2[i2]=Serial2.read()
}
check2=uart2[0]+uart2[1]+uart2[2]+uart2[3]+uart2[4]+uart2[5]+uart2[6]+uart2[7]
if(uart2[8]==(check2&0xff))//verify the received data as per protocol
{
dist2=uart2[2]+uart2[3]*256
strength2=uart2[4]+uart2[5]*256
}
}
}
}
delay(50)
D += dist2
// Distance Total
tft.setCursor(60,120)
tft.setTextColor(WHITE, BLACK)
tft.print("DT:")
tft.setTextSize(3)
tft.setCursor(60,160)
tft.print((D)/100.00)
delay(50)
}