I'm making a midi sequencer with the seeedstudio TFT shield.
I made a little gird for the sequencer and need the squares to toggle between black and blue to show if it's active or not. I have a way to place the square in the correct spot but I can't figure out how to do it efficiently. I need to be able to toggle them at any time...
Heres the chunch of code that plots the square.
I'll put the whole thing in the attachment.
I assume I would have to iterate over it somehow and change the the values in the if statements but I'm still kindof a noob and I'm not entirely sure what I'm doing.
Thanks for the help!
//GRID TOGGLES
if (x > 0 && x < 60 && y > 180 && y < 240) //first square
{
//have to have way to tell if it's already selected or not
if (seqBool[0]==0)
{
//fill square
Tft.fillRectangle(1, 181, 59,59,CYAN); //slightly smaller square fits inside blue grid square. hense 61 instead of 60
seqBool[0]=1;
}
I ran into the same 'slow' fillRectangle problem with the 3.2 TFT display.. fillRectangle is a slow function..
drawRectangle is fast if u can use that instead..
U might check the TFT.h and see if theres any notes on speeding up fill functions
I see nothing in 'TFTv2.h' that suggests a way to speed it up, but as PaulS say's looping the drawing of like sized rectangles can be simplified and made easier to read.
{
int16_t _left;
int16_t _top;
int16_t _width;
int16_t _height;
rect_t(int16_t left = 0, int16_t top = 0, int16_t width = 0, int16_t height = 0)
: _left(left), _top(top)
, _width(width), _height(height)
{ }
rect_t& operator= (const rect_t& rhs)
{
_left = rhs._left;
_top = rhs._top;
_width = rhs._width;
_height = rhs._height;
return *this;
}
rect_t& offset(int16_t dx, int16_t dy)
{
_width += dx;
_height += dy;
return *this;
}
int16_t left() const { return _left; }
int16_t top() const { return _top; }
int16_t width() const { return _width; }
int16_t height() const { return _height; }
};
void drawGrid()
{
// ... allocate an instance of rect_t named 'rect' ...
// ... 'rect' will be initialized a to 0, 0 and a width and height of 12, 60 ...
rect_t rect(0, 0, 12, 60);
for ( size_t iCol = 0; iCol < 3; iCol++ )
{
// ... allocate another instance of 'rect_t' named 'rc' and initialize it with the existing rectangle 'rect' ...
rect_t rc = rect;
// ... offset instance 'rc' by 'iCol' times its width ...
rc.offset(iCol * rc.left(), 0);
Tft.drawRectangle(rc.left(), rc.top(), rc.width(), rc.height(), BLUE);
}
...
}
I've recently been using the Adafruit GFX and MCUFRIEND_kbv libraries and find them extremely fast on the UNO. For reasons I don't fully understand, the routines seem about half as fast on a Mega board.
working on the UNO with the libraries above and it is very nice. However, I am running out of Flash, hence the try with the Mega, but the graphics are not as fast as I'd like. I'd really like to get the code moved to a Teensy 3.2, but have not been able to get the libraries to compile with it. If there are any Teensy experts out there who have a good graphics engine, I'd love to hear about it.