i wanted to try and use this code with an esp23 devkit, i originally coded this on an arduino uno. Am i able to just transfer the code over to the esp23, or do i need to change it? if i need to change would i need to rewrite the whole code again or is there a library i can use that will only require small changes and allow to use the same code and format
#include <SPI.h>
#include <nRF24L01.h>
#include <RF24.h>
#include <Adafruit_GFX.h>
#include <Adafruit_TFTLCD.h>
#include <TouchScreen.h>
#define LCD_CS A3
#define LCD_CD A2
#define LCD_WR A1
#define LCD_RD A0
#define LCD_RESET A4
// these pins define the pins being used by the Arduino^^
#define TS_MINX 118
#define TS_MINY 106
#define TS_MAXX 950
#define TS_MAXY 933
#define YP A3
#define XM A2
#define YM 9
#define XP 8
// this code calibrates the screen
Adafruit_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);
#define MINPRESSURE 10
#define MAXPRESSURE 1000
TouchScreen ts = TouchScreen(XP, YP, XM, YM, 300);
// these define the pins used to activate the screen, i believe that the 300 is the Maximum resistence of the screen
#define BLACK 0x0000
#define BLUE 0x001F
#define RED 0xF800
#define GREEN 0x07E0
#define CYAN 0x07FF
#define MAGENTA 0xf81F
#define YELLOW 0xFFE0
#define WHITE 0xFFFF
//transmitter
RF24 radio(10, 7); // CE, CSN
const byte address[6] = ("TEXTC");
const char txt[] = "Connection made";
struct Data_P {
bool touchvar = false;
char text[sizeof(txt)];
};
Data_P data;
int currentscreen = 0;
bool Camera = 0;
bool tracker = false;
bool Homevar = false;
bool backbutton = 1;
bool welcome = true;
// A touch variable that will switch depending on parameters for radio communication
void Home() {
tft.fillScreen(RED);
tft.setCursor(60, 100);
tft.setTextSize(2);
tft.print("CHOOSE APPLICATION");
tft.fillRect(10, 10, 75, 75, BLUE);
tft.fillRect(125, 10, 75, 75, BLUE);
tft.fillRect(240, 10, 75, 75, BLUE);
// creating buttons for applications, first test out using LED's
}
void Welcome() {
tft.fillScreen(WHITE); //WHat to fill the screen colour with- colours stated above
tft.drawRect(0, 0, 319, 240, WHITE); //the rectangularshape that the screen fills
tft.setCursor(5, 5); //set cursor is where text will begin on the screen, top right corner of the text
tft.setTextColor(BLACK);
tft.setTextSize(2);
tft.print("WELCOME LKAT");
//add parameters
tft.fillRect(50, 180, 210, 40, BLACK);
tft.drawRect(50, 180, 210, 40, GREEN);
tft.setCursor(60, 190);
tft.setTextColor(WHITE);
tft.setTextSize(2);
}
void LEDB() {
tft.setCursor(5, 5);
tft.fillScreen(BLUE);
tft.print("HELLO");
}
void LEDR() {
tft.setCursor(5, 5);
tft.fillScreen(RED);
tft.print("HELLO");
}
/////////////////////////////////////////////////////////////////////////////////////////////////////
void setup() {
Serial.begin(9600);
radio.begin();
radio.openWritingPipe(address); //00001
radio.setPALevel(RF24_PA_MIN);
radio.stopListening();
tft.reset();
uint16_t identifier = tft.readID();
tft.begin(identifier);
tft.setRotation(3); //changing this value between 1 and 0 will change the layout of the text on screen. landscape portarait
currentscreen = 0;
Welcome();
}
bool buttonPressed(const int x, const int y, const int buttonX, const int buttonY, const int buttonWidth, const int buttonHeight) {
return ((x >= buttonX) && (x <= buttonX + buttonWidth) && (y >= buttonY) && (y <= buttonY + buttonHeight));
}
/////////////////////////////////////////////////////////////////////////
void loop() {
TSPoint p = ts.getPoint();
pinMode(XM, OUTPUT);
pinMode(YP, OUTPUT);
radio.write(&data, sizeof(Data_P));
delay(1000);
if (p.z > ts.pressureThreshhold) {
data.touchvar = !data.touchvar;
strcpy(data.text, txt);
Serial.print("\tPressure = ");
Serial.println(p.z);
int y = map(p.x, TS_MINX, TS_MAXX, 0, 240);
int x = map(p.y, TS_MINY, TS_MAXY, 0, 320);
serial.print("y value");
serial.println(y);
// delay(1000);
if (welcome == true) {
if (currentscreen == 0) {
if (buttonPressed(x, y, 50, 180, 210, 40)) { // x and y map variables and then the starting x,y coordinate and then width and then hieght
currentscreen = 1;
welcome = false;
Homevar = true;
Home();
}
}
}
if (currentscreen == 1) {
if (Homevar == true && welcome == false) {
if (buttonPressed(x, y, 10, 10, 75, 75)) { // starting xy coord and then width and height
LEDB();
currentscreen = 2;
//if(currentscreen==2 && buttonPressed(x,y,0,0,319,240)){//tft.darwRect(0,0,319,240);
} else if (buttonPressed(x, y, 125, 10, 75, 75)) {
LEDR();
currentscreen = 3;
} else if (buttonPressed(x, y, 240, 10, 75, 75)) {
tft.fillScreen(GREEN);
currentscreen = 4;
if (currentscreen = 4) {
}
}
}
}
}
}