Hi All,
Using Platformio in VSC, ESP32, with TFT touchscreen and TFT-eSPI, I have a touch screen with different pages (screens) selected by “Menu” buttons at the bottom of the display.
The pages have various buttons, to perform various control functions.
The system sends CAN messages, with various data.
At the top of my code (after #include <TFT_eSPI.h>, etc) I declare a variable uint8_t Started = 0;
On Page 1, Button[1] will make Started = 1, to start a motor and Button[2] will make Started = 0, to stop the motor again.
“Started” will also put text "Motor 1 - " and “ON” (or “OFF”) on the screen and control other functions to test the motor speed, etc.
void Buttons_Motor1() {
uint16_t t_x = 0, t_y = 0;
bool pressed = tft.getTouch(&t_x, &t_y);
if (Button[1].contains(t_x, t_y)) {
Started = 1;
Motor1_text = "ON";
}
if (Button[2].contains(t_x, t_y)) {
Started = 0;
Motor1_text = "OFF";
}
}
One CAN message confirms Started = 1 ok.
However, pressing the MENU buttons to a different page, then the CAN message states Started = 0.
Like the variable value is LOST ???
if I test “Started” in the CAN send routine, then “Started” remains at 1 in the CAN messages, on all pages.
void SendCAN_01() { // Send a CAN message ID 01
if (Motor1_text == "ON") {
Started = 1;
} else {
Started = 0;
}
CAN.beginPacket(01);
CAN.write(Started); // byte 0
CAN.endPacket(); // end of message .... DLC total 8 bytes
}
I’ve been through the whole code and the “Started” variable is not modofied anywhere else, only in the void Buttons_Motor1() function.
Can the “Started” variable value be lost somewhere ?
Thank you,
Trevor