Hello,
How do I add a menu to a project with the tft_espi library without conflict with "multiple definition of` tft '; " between the Definition in the library and my project, the line "TFT_eSPI tft;" or in my project "TFT_eSPI tft = TFT_eSPI ();" has no effect.
my code
/*
* LCD connect;
TFT_MOSI 15 // In some display driver board, it might be written as "SDA" and so on.
TFT_SCLK 4
TFT_CS 16 // Chip select control pin
TFT_DC 5 // Data Command control pin
TFT_RST 18 // Reset pin (could connect to Arduino RESET pin)
TFT_BL 19 // LED back-light
SDcard module;
MOSI 15
MISO 21
SCLK 4
CS 17
BME280, tea5767, ds1307, 24C32;
SCL 22
SDA 23
Buzzer;
Pin 26
Encoder;
pin_button 32
pin_DT 33
Pin_CLK 25
*/
#include <WiFi.h>
#include <SPI.h>
#include "AT24CX.h"
#include <ESPmDNS.h>
#include <WiFiUdp.h>
#include "RTClib.h"
#include <Adafruit_BME280.h>
#include <TFT_eSPI.h>
#include "elapsedMillis.h"
#include "BluetoothSerial.h"
#include "Button2.h"
//#include "ESPRotary.h"
#include <HTTPClient.h>
//#include <Arduino_JSON.h>
#include "src/test_menu.h"
#include <TEA5767.h>
//#include <tcMenuTfteSpi.h>
//#include <ThemeDarkModeModern.h>
#define Buzzer 32
#define SCL 22
#define SDA 23
//#define button 25
//#define ROTARY_ENCODER_A_PIN 27
//#define ROTARY_ENCODER_B_PIN 26
#define ROTARY_ENCODER_BUTTON_PIN 25
#define ROTARY_ENCODER_VCC_PIN -1
#define ILI9341_BLACK 0x0000 ///< 0, 0, 0
#define ILI9341_NAVY 0x000F ///< 0, 0, 123
#define ILI9341_DARKGREEN 0x03E0 ///< 0, 125, 0
#define ILI9341_DARKCYAN 0x03EF ///< 0, 125, 123
#define ILI9341_MAROON 0x7800 ///< 123, 0, 0
#define ILI9341_PURPLE 0x780F ///< 123, 0, 123
#define ILI9341_OLIVE 0x7BE0 ///< 123, 125, 0
#define ILI9341_LIGHTGREY 0xC618 ///< 198, 195, 198
#define ILI9341_DARKGREY 0x7BEF ///< 123, 125, 123
#define ILI9341_BLUE 0x001F ///< 0, 0, 255
#define ILI9341_GREEN 0x07E0 ///< 0, 255, 0
#define ILI9341_CYAN 0x07FF ///< 0, 255, 255
#define ILI9341_RED 0xF800 ///< 255, 0, 0
#define ILI9341_MAGENTA 0xF81F ///< 255, 0, 255
#define ILI9341_YELLOW 0xFFE0 ///< 255, 255, 0
#define ILI9341_WHITE 0xFFFF ///< 255, 255, 255
#define ILI9341_ORANGE 0xFD20 ///< 255, 165, 0
#define ILI9341_GREENYELLOW 0xAFE5 ///< 173, 255, 41
//#define ILI9341_PINK 0xFC18 ///< 255, 130, 198
#define SEALEVELPRESSURE_HPA (1013.25)
#define CLICKS_PER_STEP 20
int state = LOW;
const float adjustment = -1;
int ledState = 0;
TFT_eSPI tft = TFT_eSPI();
Adafruit_BME280 bme; // use I2C interface
elapsedMillis timer1, timer2, timer3, timer4, timer5;
AT24CX eeprom;
int alarm_hour = 18;
int alarm_minute = 32;
int alarm_on_off = 0;
bool lock = false;
bool lock2 = true;
int color_T;
int color_b;
int states = 0;
int morning_time = 6;
int evening_time = 20;
int comma_1, comma_2, comma_3, comma_4, comma_5, comma_6;
char Memory_SSID[69];
char Memory_Password[32];
int16_t read_state;
RTC_DS1307 rtc;
void alert(unsigned int clock);
void lcd();
void button();
void Wifi_Connect();
void budzik();
int c;
String httpGETRequest(const char* serverName);
BluetoothSerial BT;
//ESPRotary r = ESPRotary(ROTARY_ENCODER_A_PIN, ROTARY_ENCODER_B_PIN, CLICKS_PER_STEP);
Button2 pushing = Button2(ROTARY_ENCODER_BUTTON_PIN);
String StringBTRX = "";
String data;
String openWeatherMapApiKey = "49c70ef728e7ae9352496509a2c0864f";
String city = "Lukow";
String countryCode = "pl";
String jsonBuffer;
unsigned int be;
TwoWire I2CBME = TwoWire(0);
int Height_above_sea_level = 160;
float presure;
float result_presure;
void setup() {
setupMenu();
I2CBME.begin(SDA, SCL, 100000);
tft.init();
tft.setRotation(3);
pinMode(TFT_BL, OUTPUT);
pinMode(Buzzer, OUTPUT);
pinMode(2, OUTPUT);
//pinMode(button, INPUT_PULLUP);
//tft.fillScreen(color_background);
rtc.begin(&I2CBME);
bme.begin(0x76, &I2CBME);
Serial.begin(115200);
Wifi_Connect();
//BT.begin();
Serial.println("Booting");
BT.begin("Zegarek");
//pushing.setLongClickHandler(button);
delay(2000);
Serial.println("Ready");
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
DateTime now = rtc.now();
ledcSetup(0, 5000, 8);
ledcAttachPin(TFT_BL, 0);
}
void loop() {
taskManager.runLoop();
presure = bme.readPressure();
lcd();
budzik();
result_presure = (((presure) / pow((1 - ((float)(Height_above_sea_level)) / 44330), 5.255)) / 100.0);
Serial.println(result_presure);
if(BT.available())
{
StringBTRX = BT.readString();
comma_1 = StringBTRX.indexOf(',');
comma_2 = StringBTRX.indexOf(',', comma_1 + 1);
comma_3 = StringBTRX.indexOf(',', comma_2 + 1);
comma_4 = StringBTRX.indexOf(',', comma_3 + 1);
comma_5 = StringBTRX.indexOf(',', comma_4 + 1);
comma_6 = StringBTRX.indexOf(',', comma_5 + 1);
//Clock Settings
if(StringBTRX.indexOf("czas")>= 0)
{
uint16_t year_ = atoi(StringBTRX.substring(0, comma_1).c_str());
uint8_t Mounth_ = atoi(StringBTRX.substring(comma_1+1 , comma_2+1).c_str());
uint8_t Days_ = atoi(StringBTRX.substring(comma_2+1, comma_3+1).c_str());
uint8_t Hour_ = atoi(StringBTRX.substring(comma_3+1, comma_4+1).c_str());
uint8_t Minute_ = atoi(StringBTRX.substring(comma_4+1, comma_5+1).c_str());
uint8_t Secound_ = atoi(StringBTRX.substring(comma_5+1, comma_6+1).c_str());
rtc.adjust(DateTime(year_, Mounth_, Days_, Hour_, Minute_, Secound_));
StringBTRX = "";
}
//LCD Backlight
if (StringBTRX.indexOf("backlight") >= 0)
{
//comma_1 = StringBTRX.indexOf(',');
unsigned int backlight_ = atoi(StringBTRX.substring(0, comma_1).c_str());
eeprom.writeInt(0, backlight_); //4bit
StringBTRX = "";
}
//Wifi Settings
if (StringBTRX.indexOf("Wifi") >= 0)
{
String _SSID_ = StringBTRX.substring(0, comma_1+1);
String _Password_ = StringBTRX.substring(comma_1+1, comma_2+1 );
char SSID_[_SSID_.length()];
char Password_[ _Password_.length()];
_SSID_.toCharArray(SSID_, _SSID_.length());
_Password_.toCharArray(Password_, _Password_.length());
eeprom.writeChars(5, SSID_, sizeof(SSID_));
eeprom.writeChars(75, Password_, sizeof(Password_));
ESP.restart();
StringBTRX = "";
}
}
if (timer2 >= 500)
{
BT.println(String(result_presure) + "," + String((bme.readTemperature() + adjustment)) + "," + String(bme.readHumidity()) + "," + (String(alarm_hour) + ":" + alarm_minute));
timer2 = 0;
}
// if (states == 0 && read_state == 2 )
// {
//
// states = 1;
// alarm_on_off = !alarm_on_off;
// }
//
// if (states == 1 && read_state == 0)
// {
// states = 0;
// }
//Serial.print(sizeof(ssid));
}
void button(Button2& btn)
{
unsigned int time = btn.wasPressedFor();
if (time > 1000)
{
lock = !lock;
lock2 = !lock2;
}
else if (time > 200)
{
alarm_on_off = !alarm_on_off;
}
else {
Serial.print("long.");
}
Serial.print(" (");
Serial.print(time);
Serial.println(" ms)");
}
void Wifi_Connect()
{
eeprom.readChars(5, Memory_SSID, sizeof(Memory_SSID));
eeprom.readChars(75, Memory_Password, sizeof(Memory_Password));
WiFi.mode(WIFI_STA);
WiFi.setHostname("Stacja Meteo");
WiFi.begin(Memory_SSID, Memory_Password);
}
void alert(unsigned int clock)
{
if (timer1 >= clock)
{
state = !state;
digitalWrite(Buzzer, state);
timer1 = 0;
}
}
void lcd()
{
long RSSI = WiFi.RSSI();
int testif = 5;
DateTime now = rtc.now();
unsigned int _baacklight_ = eeprom.readInt(0);
//digitalWrite(backlight, HIGH
ledcWrite(0, _baacklight_);
//Serial.println(sizeof(_baacklight_));
//Night mode
if(lock2 == true)
{
if (lock == true)
{
//lock2 = false;
color_b = ILI9341_BLACK;
//tft.fillScreen(color_background);
color_T = ILI9341_GREEN;
//tft.setTextColor(color_T, color_b);
//tft.begin();
tft.setRotation(3);
tft.fillScreen(color_b);
lock2 = !lock2;
//lock = !lock;
//Day mode
}
else
{
//lock = false;
color_b = ILI9341_BLACK;
color_T = ILI9341_GREEN;
//tft.begin();
tft.setRotation(3);
tft.fillScreen(color_b);
lock2 = !lock2;
}
}
tft.setTextColor(ILI9341_YELLOW, color_b);
tft.setCursor(200, 50);
tft.setTextSize(2);
tft.print("Lukow");
tft.setCursor(15, 50);
tft.print("Pokoj");
tft.setTextColor(color_T, color_b);
//Serial.println(now.hour());
tft.setCursor(60, 170);
//tft.setFreeFont(&DS_DIGII4pt7b);
tft.setTextSize(4);
//tft.setFreeFont(&FreeMono9pt7b);
tft.print(String(now.hour(), DEC) + ":" + String(now.minute(), DEC) + ":" + String(now.second(), DEC) + " ");
//tft.print(&myObject["main"]["temp"]);
if (timer3 >= 1000)
{
tft.setCursor(20, 70);
tft.setTextSize(2);
tft.print(String(bme.readTemperature() + adjustment) + " " + "C");
tft.setCursor(20, 90);
tft.print(String(result_presure) + " " + "HPA");
tft.setCursor(20, 110);
tft.print(String(bme.readHumidity()) + " " + "%");
timer3 = 0;
}
//delay(1000);
tft.setCursor(200, 10);
tft.setTextSize(2);
tft.print(String(now.day()) + "-" + String(now.month()) + "-" + String(now.year()));
tft.setCursor(80, 210);
tft.print("alarm");
tft.setCursor(150, 210);
tft.print(String(alarm_hour) + ":" + String(alarm_minute) + ":" + "00" + " ");
//wifi display status
tft.setCursor(10, 10);
tft.print("Wifi");
if (WiFi.waitForConnectResult() == WL_CONNECTED)
{
tft.print(" ");
if (WiFi.RSSI() <= -100)
{
tft.setCursor(80, 10);
tft.print("|");
tft.print(" ");
}
else if (RSSI <= -80)
{
tft.setCursor(80, 10);
tft.print("||");
tft.print(" ");
}
else if (RSSI <= -60)
{
tft.setCursor(80, 10);
tft.print("|||");
tft.print(" ");
}
else if (RSSI <= -40)
{
tft.setCursor(80, 10);
tft.print("||||");
tft.print(" ");
}
else if (RSSI <= -20)
{
tft.setCursor(80, 10);
tft.print("|||||");
tft.print(" ");
}
else if (RSSI == 0)
{
tft.setCursor(80, 10);
tft.print("X");
}
}
else
{
tft.setCursor(70, 10);
tft.print("Brak Sieci");
//tft.print(" ");
//Wifi_Connect();
WiFi.reconnect();
//tft.setCursor(1, 40);
}
bool debuge = now.hour() >= 6;
//int16_t read_state = rotaryEncoder.currentButtonState();
//Serial.println(read_state);
//alarm display
if(alarm_on_off == 0)
{
tft.setTextColor(ILI9341_MAGENTA, color_b);
tft.setCursor(20, 210);
tft.print("Off");
tft.print(" ");
}
if (alarm_on_off == 1)
{
tft.setTextColor(ILI9341_GREEN, color_b);
tft.setCursor(20, 210);
tft.print("On");
tft.print(" ");
}
}
void budzik()
{
DateTime al = rtc.now();
if ((al.hour() == alarm_hour) && (al.minute() >= alarm_minute) && (alarm_on_off == 1))
{
alert(1000);
}
}
Code menu file
/*
The code in this file uses open source libraries provided by thecoderscorner
DO NOT EDIT THIS FILE, IT WILL BE GENERATED EVERY TIME YOU USE THE UI DESIGNER
INSTEAD EITHER PUT CODE IN YOUR SKETCH OR CREATE ANOTHER SOURCE FILE.
All the variables you may need access to are marked extern in this file for easy
use elsewhere.
*/
#include <tcMenu.h>
#include "test_menu.h"
#include "ThemeDarkModeTraditional.h"
// Global variable declarations
const PROGMEM ConnectorLocalInfo applicationInfo = { "Zegarek_ad", "746596d6-9fdc-494c-8d77-e8e2e9118e73" };
TFT_eSPI tft;
TfteSpiDrawable tftDrawable(&tft, 0);
GraphicsDeviceRenderer renderer(30, applicationInfo.name, &tftDrawable);
// Global Menu Item declarations
const PROGMEM BooleanMenuInfo minfoCiemnyStyl = { "Ciemny styl", 3, 0xffff, 1, NO_CALLBACK, NAMING_ON_OFF };
BooleanMenuItem menuCiemnyStyl(&minfoCiemnyStyl, false, NULL);
const PROGMEM BooleanMenuInfo minfoBudzik = { "Budzik", 2, 0xffff, 1, NO_CALLBACK, NAMING_ON_OFF };
BooleanMenuItem menuBudzik(&minfoBudzik, false, &menuCiemnyStyl);
const PROGMEM BooleanMenuInfo minfoRadioFM = { "Radio FM", 1, 0xffff, 1, NO_CALLBACK, NAMING_ON_OFF };
BooleanMenuItem menuRadioFM(&minfoRadioFM, false, &menuBudzik);
void setupMenu() {
// First we set up eeprom and authentication (if needed).
// Code generated by plugins.
tft.begin();
tft.setRotation(2);
renderer.setUpdatesPerSecond(10);
switches.initialise(internalDigitalIo(), true);
menuMgr.initForEncoder(&renderer, &menuRadioFM, 25, 33, 32, QUARTER_CYCLE);
renderer.setTitleMode(BaseGraphicalRenderer::NO_TITLE);
renderer.setUseSliderForAnalog(false);
installDarkModeTraditionalTheme(renderer, MenuFontDef(nullptr, 1), MenuFontDef(nullptr, 1), false);
}
Error Message
Arduino: 1.8.16 (Windows 10), Board: "ESP32 Dev Module, Disabled, Huge APP (3MB No OTA/1MB SPIFFS), 240MHz (WiFi/BT), QIO, 80MHz, 4MB (32Mb), 921600, Core 1, Core 1, None"
m:/arduino/hardware/espressif/esp32/tools/xtensa-esp32-elf/bin/../lib/gcc/xtensa-esp32-elf/8.4.0/../../../../xtensa-esp32-elf/bin/ld.exe: sketch\src\test_menu.cpp.o:C:\Users\foreste\source\repos\Advance-clock\sketches\test\src/test_menu.cpp:18: multiple definition of `tft'; sketch\test.ino.cpp.o:C:\Users\foreste\source\repos\Advance-clock\sketches\test/test.ino:84: first defined here
collect2.exe: error: ld returned 1 exit status
Multiple libraries were found for "TEA5767.h"
Used: M:\Arduino\libraries\TEA5767
Not used: M:\Arduino\libraries\Radio
Multiple libraries were found for "WiFi.h"
Used: M:\Arduino\hardware\espressif\esp32\libraries\WiFi
Not used: M:\Developer_tools\Arduino\libraries\WiFi
exit status 1
Error compiling for board ESP32 Dev Module.
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.