Hey guys!
I am trying to build a simple calculator with my Teensy and a TFT ILI9341 display for touch screen input. Unfortunately, I don't really understand how to use libraries inside my own libraries. I would be glad about every help! Thank you!
This is the error I get:
.pio/build/teensy40/src/ScreenInit.cpp.o:(.bss.tft+0x0): multiple definition of `tft'
.pio/build/teensy40/src/GetTouchValues.cpp.o:(.bss.tft+0x0): first defined here
.pio/build/teensy40/src/ScreenInit.cpp.o:(.data.ts+0x0): multiple definition of `ts'
Main code:
#include "Arduino.h"
#include "Arithmetik.h"
#include "ScreenInit.h"
#include "GetTouchValues.h"
Arithmetik arithmetik(10, 2);
ScreenInit screenInit;
GetTouchValues getTouchValues;
boolean pointInRect(int x, float y, float rectX, float rectY, float rectW, float rectH)
{
 boolean ret = false;
 if ((x >= rectX) && (x <= (rectX + rectW)) && (y >= rectY) && (y <= (rectY + rectH)))
 {
  ret = true;
 }
 return ret;
}
void setup()
{
 screenInit.startDisplay();
}
void loop()
{
 // boolean istouched = ts.touched();
 // int X;
 // float Y;
 /* if (istouched)
 {
  TS_Point p = ts.getPoint(); // point getter function */
}
GetTouchValues.cpp:
#include "Arduino.h"
#include "GetTouchValues.h"
GetTouchValues::GetTouchValues()
{
}
float GetTouchValues::GetPoints()
{
if (istouched)
{
TS_Point p = ts.getPoint(); // point getter function
p.x = _x;
p.y = _y;
return _x;
return _y;
}
}
GetTouchValues.h:
#ifndef GetTouchValues_h
#define GetTouchvalues_h
#include "ScreenInit.h"
#include "Arduino.h"
class GetTouchValues
{
public:
GetTouchValues();
float GetPoints();
private:
boolean istouched = ts.touched();
float _x;
float _y;
};
#endif
ScreenInit.cpp:
#include "Arduino.h"
#include "ScreenInit.h"
ScreenInit::ScreenInit()
{
}
void ScreenInit::redrawButtons()
{
}
void ScreenInit::clearDisplay()
{
tft.fillScreen(ILI9341_RED);
redrawButtons();
}
void ScreenInit::startDisplay()
{
Serial.begin(38600);
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_RED);
ts.begin();
ts.setRotation(1);
while (!Serial && (millis() <= 1000)); // weiß nicht was das ist
}
ScreenInit.h:
#ifndef ScreenInit_h
#define ScreenInit_h
#include <SPI.h>
#include <ILI9341_t3.h>
#include <font_Arial.h>
#include <XPT2046_Touchscreen.h>
#define CS_PIN 8
#define TFT_DC 9
#define TFT_CS 10
XPT2046_Touchscreen ts(CS_PIN);
#define TIRQ_PIN 2
ILI9341_t3 tft = ILI9341_t3(TFT_CS, TFT_DC);
#include "Arduino.h"
class ScreenInit
{
public:
ScreenInit();
void clearDisplay();
void redrawButtons();
void startDisplay();
};
#endif