Learning Ardunio

I am working on a touchscreen interface, my idea is a ScreenManager that manages the state of the touchscreen, IE: shows Menu / Interface / Submenus by using a list of screens, with that said, i am a C# guy so attempting to convert my c# ideas to c++ is a challenge, currently i am working on the base classes to set up what i want, and i am unable to pass my tft object to my class, i mean the code works, but the output to the touchscreen does not, i know my code my be horrid to you guys, and probably make your eyes bleed, and i am sure there are 100 different and better ways to do this, but i was hoping one of you might be able to point out whats wrong with this code .

In my main ino i create my tft with Elegoo hardware

Elegoo_TFTLCD tft(LCD_CS, LCD_CD, LCD_WR, LCD_RD, LCD_RESET);

Then i want to pass this to my screen class

Screen(uint8_t orientation, uint16_t backGroundColor, Elegoo_TFTLCD *tft);

i have tried &tft and just tft i cant assign it, so am forced to use a pointer, here is what my cpp looks like

#include "Screen.h"

Elegoo_TFTLCD *_tft;

Screen::Screen(uint8_t orientation, uint16_t backGroundColor, Elegoo_TFTLCD tft)
{
_orientation = orientation;
_backGroundColor = backGroundColor;
_tft = tft;
_mapper->SetOrientation(_orientation);
}
void Screen::addButton(Elegoo_GFX_Button
button)
{
_screenButtons.add(button);
}
void Screen::addButton(int16_t x, int16_t y, uint8_t buttonWidth, uint8_t buttonHeight, uint16_t buttonBorderColor, uint16_t buttonColor, uint16_t textColor, char* label, uint8_t textSize)
{
// Check we are within bounds
// if (x > BUTTON_RIGHT | x < BUTTON_LEFT)
// return;
// if (y > BUTTON_BOTTOM | y < BUTTON_TOP)
// return;

Elegoo_GFX_Button *button;
button->initButton(_tft, x, y, buttonWidth, buttonHeight, buttonBorderColor, buttonColor, textColor, label, textSize);
_screenButtons.add(button);
}
void Screen::draw()
{
// clear screen
_tft->reset();
//if (_identifier != -1)
_tft->begin(_identifier);

_tft->setRotation(_orientation);
_tft->fillScreen(_backGroundColor);

// Go through our buttons and draw them
for(int i =0;i<_screenButtons.size();i++)
{
Elegoo_GFX_Button *button = _screenButtons.get(i);
button->drawButton();
}
}
void Screen::setHardwareIdentifier(uint16_t id = 0x9341)
{
_identifier = id;
}

Using a pointer i compile but no output hits the screen

In my main ino

which you didn't post

Then i want to pass this to my screen class

That might be how the Screen class (Case matters!) receives. That has nothing to do with how you passed it.

I have tried it many ways, it all compiles fine but i do not really reference the tft because the screen does nothing, i may have to rethink this, code so far attached

ELEGOO_DRONE.ino (2.91 KB)

Screen.cpp (1.27 KB)

Screen.h (1.02 KB)

  Elegoo_GFX_Button *button;
  button->initButton(_tft, x, y, buttonWidth, buttonHeight, buttonBorderColor, buttonColor, textColor, label, textSize);

button doesn't point to anything. You can't dereference a pointer that doesn't point somewhere useful.

Thankyou i fixed that error

Elegoo_GFX_Button *button = new Elegoo_GFX_Button();

However i still cannot pass the tft correctly, so had not even made it to the point of the buttons working or not

I will answer my own question, you pass a ref to the tft

Elegoo_TFTLCD _tft;

Screen(uint8_t orientation, uint16_t backGroundColor, Elegoo_TFTLCD &tft);

Screen::Screen(uint8_t orientation, uint16_t backGroundColor, Elegoo_TFTLCD &tft)
: _tft(tft)
{
}

Ok next annoying issue, i will include all code, except the hardware specific as it uses same commands as the others.

So i am able to pass the tft to my screen class and draw a button using my linkedlist, however when i press the button it stays drawn in the on state even after i release it, any help would be appreciated.

The drawing function in in Screen.cpp ::draw();

ELEGOO_DRONE.ino (1.47 KB)

Screen.cpp (2.19 KB)

Screen.h (1.28 KB)

ScreenManager.cpp (97 Bytes)

ScreenManager.h (425 Bytes)

LinkedList.zip (7.92 KB)

TFTScreenMapper.zip (1.68 KB)

NM, i got it