Description
Draw a filled rectangle with a fix color, draw a filled and rounded rectangle, draw an anti-aliased filled and rounded rectangle.
Signature
void TFT_eSPI::fillRect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t color)void TFT_eSPI::fillRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color)void TFT_eSPI::fillSmoothRoundRect(int32_t x, int32_t y, int32_t w, int32_t h, int32_t radius, uint32_t color, uint32_t bg_color = 0x00FFFFFF)
Parameters
int32_tx: x coord.int32_ty: y coord.int32_tw: Rect width.int32_th: Rect height.int32_tradius: corner radius.uint32_tcolor: Fill color.uint32_tbg_color: Background color (defaulted to 0x00FFFFFF); If thebg_coloris not specified, the background pixel colour will be read from TFT or sprite.
Result
None.
Example
void setup() {
Serial.begin(115200);
tft.begin();
tft.setRotation(0);
tft.fillScreen(TFT_BLACK); // Clear the screen with black color
}
void loop() {
int x = 10; // x-coordinate of the top-left corner of the rectangle
int y = 10; // y-coordinate of the top-left corner of the rectangle
int w = 50; // width of the rectangle
int h = 20; // height of the rectangle
uint16_t color = TFT_RED; // color of the rectangle
tft.fillRect(x, y, w, h, color); // Draw a filled rectangle
delay(1000); // wait for 1 second
}
In this example, we first clear the screen with a black color using tft.fillScreen(TFT_BLACK). Then, in the loop()
function, we define the coordinates, width, height, and color of the rectangle we want to draw. Finally, we use
tft.fillRect(x, y, w, h, color) to draw the filled rectangle.
Note that the fillRect function takes five arguments:
x: the x-coordinate of the top-left corner of the rectangley: the y-coordinate of the top-left corner of the rectanglew: the width of the rectangleh: the height of the rectanglecolor: the color of the rectangle
You can adjust these values to draw rectangles of different sizes, positions, and colors on your TFT display.