Closed seamaster101 closed 6 years ago
Hi just wanted to let everyone know that the problem was in my code. The problem is that I redefine RA8875 on my button.cpp RA8875 b = RA8875(RA8875_CS, RA8875_RESET); but I do not initialize that. I had to use only one instance of tft. So when replaced line RA8875 b = RA8875(RA8875_CS, RA8875_RESET); in my definition on button.cpp with extern RA8875 tft; and I used tft. instead of b. in my calls all worked as expected The issue is resolved
Hi sumotoy, thanks for the great library and guidance how to connect and revive the screens. I found one problem when i use class that i wrote to create an button. The text will not get positioned where the cursor is set to. if i use simple setCursor(x,y) without the class then the text gets positioned correctly and it works as expected. Maybe its my class fault, but I cant figure it out. here is my code:
this is code
My .ino file: `#includeinclude "ColorDefinitions.h"
include "Button.h"
RA8875 tft = RA8875(RA8875_CS, RA8875_RESET); void setup() { tft.begin(RA8875_800x480); tft.setRotation(0);//works at any rotation as well tft.clearScreen(RA8875_BLACK); tButton EngineButton(20, 20, 300, 100, 10, 3, GREEN, WHITE,"ENGINE"); EngineButton.Title("ENGINE"); } void loop() { }`
then my Button.h file: `// // Button Class // Jordan Shishmanov // tft screen button class //
ifndef _BUTTONH
define _BUTTONH
include //for display communications
include
define RA8875_CS 10
define RA8875_RESET 9 //any pin or 255 to disable it!
define CTP_INT 2 // touch data ready for read from FT5206 touch controller
class tButton { private:
//int m_bNumber;
int m_bX = 0; int m_bY = 0; int m_bWidth = 0; int m_bHeight = 0; int m_bRadius = 0; int m_bBorderTickness = 0; uint16_t m_bColor = 0; uint16_t m_bBorderColor = 0; String m_bText = "Button";
public:
tButton ( //int bNumber, int bX, int bY, int bWidth, int bHeight, int bRadius, int bBorderTickness, uint16_t bColor, uint16_t bBorderColor, String bText );
void Draw(); void DrawFrame(uint16_t c); void DrawFrame(); void Title(String); };
endif`
then my Button.cpp file: `// // Button Class // Jordan Shishmanov // tft screen button class //
include "ColorDefinitions.h"
include "Button.h"
RA8875 b = RA8875(RA8875_CS, RA8875_RESET); tButton::tButton( int bX, int bY, int bWidth, int bHeight, int bRadius, int bBorderTickness, uint16_t bColor, uint16_t bBorderColor, String bText) { // m_bNumber = bNumber; m_bX = bX; m_bY = bY; m_bWidth = bWidth; m_bHeight = bHeight; m_bRadius = bRadius; m_bBorderTickness = bBorderTickness; m_bColor = bColor; m_bBorderColor = bBorderColor; m_bText = bText;
}
void tButton::Draw() { b.fillRoundRect(m_bX, m_bY, m_bWidth, m_bHeight, m_bRadius, m_bColor ); //button FILL }
void tButton::DrawFrame(uint16_t c) { m_bBorderColor = c; for (int i = 0; i < m_bBorderTickness; i++ ) { b.drawRoundRect(m_bX - i, m_bY - i, m_bWidth + i 2, m_bHeight + i 2, m_bRadius, m_bBorderColor); //button OUTLINE } }
void tButton::DrawFrame() { for (int i = 0; i < m_bBorderTickness; i++ ) { b.drawRoundRect(m_bX - i, m_bY - i, m_bWidth + i 2, m_bHeight + i 2, m_bRadius, m_bBorderColor); //button OUTLINE } }
void tButton::Title(String t){ //will load specific b.setCursor((m_bX+m_bWidth)/2, (m_bY+m_bHeight)/2, true); //it will not set text location???? why? it always prits the text at 0,0. b.setTextColor(WHITE); //b.setCursor(50, 40); //it will not set text location????
Serial.print ((m_bX+m_bWidth)/2); Serial.print(", "); Serial.print ((m_bY+m_bHeight)/2); b.setFontScale(0); b.print(t); }`
Can you please help me? thanks!