Funciones del ILI9341 para Display
Funciones del ILI9341 para Display
clearTextArea
void clearTextArea();
clearTextArea
void clearTextArea(gTextArea area);
clearTextArea
void clearTextArea(uint16_t color);
clearTextArea
void clearTextArea(gTextArea area, uint16_t color);
cursorTo
void cursorTo(uint8_t column, uint8_t row);
cursorTo
void cursorTo(uint8_t column);
cursorToXY
void cursorToXY(int16_t x, int16_t y)
display
void display(boolean d);
drawBitmap
void drawBitmap(const uint8_t *bitmap, int16_t x, int16_t y, int16_t w, int16_t
h, uint16_t color);
drawCircle
void drawCircle(int16_t x, int16_t y, int16_t r, uint16_t color);
drawFastHLine
void drawFastHLine(int16_t x, int16_t y, uint16_t w, uint16_t color);
drawFastVLine
void drawFastVLine(int16_t x, int16_t y, uint16_t h, uint16_t color);
drawImage
void drawImage(const uint16_t *colors, uint16_t x, uint16_t y, uint16_t w,
uint16_t h);
drawLine
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
drawLineByAngle
void drawLineByAngle(int16_t x, int16_t y, int16_t angle, uint16_t length,
uint16_t color);
drawPixel
void drawPixel(int16_t x, int16_t y, uint16_t color);
drawRect
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
drawRoundRect
void drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t radius,
uint16_t color);
drawTriangle
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2,
fillArc
void fillArc(uint16_t x, uint16_t y, uint16_t radius, uint16_t thickness, float
fillCircle
void fillCircle(int16_t x, int16_t y, int16_t r, uint16_t color);
fillRect
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
fillRoundRect
void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t radius,
uint16_t color);
fillScreen
void fillScreen(uint16_t color);
fillTriangle
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2,
getCharWidth
uint16_t getCharWidth(uint8_t c);
getCharWidth
uint16_t getCharWidth(uint8_t c, gTextFont font, uint8_t textScale);
getDisplayStatus
void getDisplayStatus();
getFontHeight
uint8_t getFontHeight();
getFontHeight
uint8_t getFontHeight(gTextFont font);
getFontMode
gTextFontMode getFontMode();
getTextArea
gTextArea getTextArea();
getTextBackgroundColor
uint16_t getTextBackgroundColor();
getTextColor
uint16_t getTextColor();
getTextLetterSpacing
uint8_t getTextLetterSpacing();
getTextLineSpacing
uint8_t getTextLineSpacing();
getTextScale
uint8_t getTextScale();
idle
void idle(boolean i);
invertDisplay
void invertDisplay(boolean i);
printAligned
void printAligned(const char *str, gTextAlign align);
printAligned
void printAligned(const char *str, gTextAlign align, gTextEraseLine eraseLine);
gTextEraseLine eraseLine);
printAligned
void printAligned(const char *str, gTextAlign align, uint16_t
printAlignedOffseted
void printAlignedOffseted(const char *str, gTextAlign align, uint16_t offsetX,
uint16_t offsetY);
uint16_t offsetY);
printAlignedOffseted
void printAlignedOffseted(const char *str, gTextAlign align, uint16_t offsetX,
printAlignedOffseted
void printAlignedOffseted(const char *str, gTextAlign align, uint16_t offsetX,
pixelsClearedOnRight);
printAlignedPivotedOffseted
void printAlignedPivotedOffseted(const char *str, gTextAlign align, gTextPivot
eraseLine);
printAlignedPivotedOffseted
void printAlignedPivotedOffseted(const char *str, gTextAlign align, gTextPivot
pixelsClearedOnRight);
pixelsClearedOnRight);
printAt
void printAt(const char *str, int16_t x, int16_t y);
printAt
void printAt(const char *str, int16_t x, int16_t y, gTextEraseLine eraseLine);
void printAt(const String &str, int16_t x, int16_t y, gTextEraseLine eraseLine);
void printAt(const __FlashStringHelper *str, int16_t x, int16_t y, gTextEraseLine
eraseLine);
printAt
void printAt(const char *str, int16_t x, int16_t y, uint16_t pixelsClearedOnLeft,
uint16_t pixelsClearedOnRight);
printAtPivoted
void printAtPivoted(const char *str, int16_t x, int16_t y, gTextPivot pivot);
gTextPivot pivot);
pushColor
void pushColor(uint16_t color);
pushColors
void pushColors(uint16_t *colors, uint16_t offset, uint32_t len);
readPixel
uint16_t readPixel(int16_t x, int16_t y);
screenshotToConsole
void screenshotToConsole();
setAddrWindow
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
setAddrWindowRect
void setAddrWindowRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
setAngleOffset
void setAngleOffset(int16_t angleOffset);
setArcParams
void setArcParams(float arcAngleMax);
setFont
void setFont(gTextFont font);
setFontMode
void setFontMode(gTextFontMode fontMode);
setPowerLevel
void setPowerLevel(pwrLevel p);
setRotation
void setRotation(iliRotation r);
setSPIClockDivider
void setSPIClockDivider(uint8_t divider);
setTextArea
void setTextArea(gTextArea area);
setTextArea
void setTextArea(int16_t x, int16_t y, int16_t w, int16_t h);
setTextArea
void setTextArea(int16_t x, int16_t y, int16_t columns, int16_t rows, gTextFont
font);
setTextColor
void setTextColor(uint16_t color);
setTextColor
void setTextColor(uint8_t R, uint8_t G, uint8_t B);
setTextColor
void setTextColor(uint16_t color, uint16_t backgroundColor);
setTextColor
void setTextColor(uint8_t R, uint8_t G, uint8_t B, uint8_t bgR, uint8_t bgG,
uint8_t bgB);
setTextLetterSpacing
void setTextLetterSpacing(uint8_t letterSpacing);
setTextLineSpacing
void setTextLineSpacing(uint8_t lineSpacing);
setTextScale
void setTextScale(uint8_t textScale);
sleep
void sleep(boolean s);
Functions details
fillScreen
Fills/clears the whole screen.
void fillScreen(uint16_t color);
Arguments:
color - color to fill the screen with
Example:
A screen filled with blue color.
[Link](ILI9341_BLUE);
drawPixel
Draws a pixel.
void drawPixel(int16_t x, int16_t y, uint16_t color);
Arguments:
x - x-coordinate
y - y-coordinate
color - pixel color
Example:
A white pixel at position (100,100).
[Link](100, 100, ILI9341_WHITE);
drawLine
Draws a line.
void drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color);
Arguments:
x0 - x-coordinate of the starting point
y0 - y-coordinate of the starting point
x1 - x-coordinate of the ending point
y1 - y-coordinate of the ending point
color - line color
Example:
A white line from point (100,100) to point (150,120)
[Link](100, 100, 150, 120, ILI9341_WHITE);
drawLineByAngle
Draws a line defined by a start point and an angle. An offset from the start point can be
defined.
void drawLineByAngle(int16_t x, int16_t y, int16_t angle, uint16_t length,
uint16_t color);
Arguments:
x - x-coordinate of the starting point
y - y-coordinate of the starting point
angle - line angle
start - offset from the starting point (optional)
lenght - line lenght
color - line color
Example:
A white line from point (100,100) at 45 degree angle and of 50px length. A red line from
point (100,100) at 90 degree angle starting 10px from the start point and with length of
50px.
[Link](100, 100, 45, 50, ILI9341_WHITE);
[Link](100, 100, 90, 10, 50, ILI9341_RED);
drawFastHLine
Draws a horizontal line. Performance optimized version of drawLine for drawing horizontal
lines.
void drawFastHLine(int16_t x, int16_t y, uint16_t w, uint16_t color);
Arguments:
x - x-coordinate of the starting point
y - y-coordinate of the starting point
w - line width (line is drawn from left to right)
color - line color
Example:
A white horizontal line from point (100,100) of 50px length.
[Link](100, 100, 50, ILI9341_WHITE);
drawFastVLine
Draws a vertical line. Performance optimized version of drawLine for drawing vertical
lines.
void drawFastVLine(int16_t x, int16_t y, uint16_t h, uint16_t color);
Arguments:
x - x-coordinate of the starting point
y - y-coordinate of the starting point
h - line height (line is drawn from top to bottom)
color - line color
Example:
A white vertical line from point (100,100) of 50px length.
[Link](100, 100, 50, ILI9341_WHITE);
drawRect
Draws a rectangle.
void drawRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
Arguments:
x - x-coordinate of the rectangle top left corner
y - y-coordinate of the rectangle top left corner
w - rectangle width
h - rectangle height
color - rectangle color
Example:
A white rectangle from point (100,100) of 50px width and of 20px height.
[Link](100, 100, 50, 20, ILI9341_WHITE);
fillRect
Draws a filled rectangle.
void fillRect(int16_t x, int16_t y, int16_t w, int16_t h, uint16_t color);
Arguments:
x - x-coordinate of the rectangle top left corner
y - y-coordinate of the rectangle top left corner
w - rectangle width
h - rectangle height
color - rectangle fill color
Example:
A white filled rectangle from point (100,100) of 50px width and of 20px height.
[Link](100, 100, 50, 20, ILI9341_WHITE);
drawRoundRect
Draws a rectangle with rounded edges.
void drawRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t radius,
uint16_t color);
Arguments:
x - x-coordinate of the rectangle top left corner
y - y-coordinate of the rectangle top left corner
w - rectangle width
h - rectangle height
radius - corner radius
color - rectangle color
Example:
A white rounded rectangle from point (100,100) of 50px width, 20px height and rounded
edges of 7px radius.
[Link](100, 100, 50, 20, 7, ILI9341_WHITE);
fillRoundRect
Draws a filled rectangle with rounded edges of specified radius from the specified position
and of specified width and height.
void fillRoundRect(int16_t x, int16_t y, int16_t w, int16_t h, int16_t radius,
uint16_t color);
Arguments:
x - x-coordinate of the rectangle top left corner
y - y-coordinate of the rectangle top left corner
w - rectangle width
h - rectangle height
radius - corner radius
color - rectangle fill color
Example:
A white filled rounded rectangle from point (100,100) of 50px width, 20px height and
rounded edges of 7px radius.
[Link](100, 100, 50, 20, 7, ILI9341_WHITE);
drawCircle
Draws a circle.
void drawCircle(int16_t x, int16_t y, int16_t r, uint16_t color);
Arguments:
x - x-coordinate of the circle center
y - y-coordinate of the circle center
r - circle radius
color - circle color
Example:
A white circle with center at (100,100) and 20px radius.
[Link](100, 100, 20, ILI9341_WHITE);
fillCircle
Draws a filled circle.
void fillCircle(int16_t x, int16_t y, int16_t r, uint16_t color);
Arguments:
x - x-coordinate of the circle center
y - y-coordinate of the circle center
r - circle radius
color - circle fill color
Example:
A white filled circle with center at (100,100) and 20px radius.
[Link](100, 100, 20, ILI9341_WHITE);
fillArc
Draws a filled arc. Can also be used to draw a pie.
void fillArc(uint16_t x, uint16_t y, uint16_t radius, uint16_t thickness, float
start, float end, uint16_t color);
Arguments:
x - x-coordinate of the arc center
y - y-coordinate of the arc center
radius - arc radius
thickness - arc inward thickness
start - arc start angle
end - arc end angle
color - arc fill color
Example:
A white arc with center at (100,100), 20px radius, 5px thickness, starting at 45 degrees and
ending at 180 degrees.
A red pie with center at (160,100), 20px radius, starting at 45 degrees and ending at 270
degrees.
[Link](100, 100, 20, 5, 45, 180, ILI9341_WHITE);
[Link](160, 100, 20, 20, 45, 270, ILI9341_RED);
drawTriangle
Draws a triangle.
void drawTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2,
int16_t y2, uint16_t color);
Arguments:
x0 - x-coordinate of triangle 1st corner
y0 - y-coordinate of the triangle 1st corner
x1 - x-coordinate of triangle 2nd corner
y1 - y-coordinate of the triangle 2nd corner
x2 - x-coordinate of triangle 3rd corner
y2 - y-coordinate of the triangle 3rd corner
color - triangle color
Example:
A triangle defined by points (100,100) (80,130) (120,120).
[Link](100, 100, 80, 130, 120, 120, ILI9341_WHITE);
fillTriangle
Draws a filled triangle.
void fillTriangle(int16_t x0, int16_t y0, int16_t x1, int16_t y1, int16_t x2,
int16_t y2, uint16_t color);
Arguments:
x0 - x-coordinate of triangle 1st corner
y0 - y-coordinate of the triangle 1st corner
x1 - x-coordinate of triangle 2nd corner
y1 - y-coordinate of the triangle 2nd corner
x2 - x-coordinate of triangle 3rd corner
y2 - y-coordinate of the triangle 3rd corner
color - triangle fill color
Example:
A filled triangle defined by points (100,100) (80,130) (120,120).
[Link](100, 100, 80, 130, 120, 120, ILI9341_WHITE);
drawBitmap
Draws a monochrome image from a byte array. A background color can be specified,
otherwise the background will be transparent.
void drawBitmap(const uint8_t *bitmap, int16_t x, int16_t y, int16_t w, int16_t
h, uint16_t color);
Arguments:
bitmap - a pointer to a byte array (in progmem for AVR) holding pixel data
x - x-coordinate of the bitmaps's top left corner
y - y-coordinate of the bitmaps's top left corner
w - bitmap width (in pixels)
h - bitmap height (in pixels)
color - bitmap color (a color that will be used for drawing pixels where the corresponding
bit in the array is set to 1)
bgColor - bitmap's background color (optional) (a color that will be used for drawing pixels
where the corresponding bit in the array is set to 0). If not specified then the background is
transparent.
Example:
Arduino logo with solid and transparent background (arrayMonochromeBitmap example
sketch).
const uint8_t arduLogo[] PROGMEM = {" // width 40, height 32
...
solid background
drawImage
Draws an image from an array generated with BMP24toILI565Array tool.
void drawImage(const uint16_t *colors, uint16_t x, uint16_t y, uint16_t w,
uint16_t h);
Arguments:
colors - a pointer to an array (in progmem for AVR) holding pixel colors
x - x-coordinate of the image top left corner
y - y-coordinate of the image top left corner
w - image width, you can use the constant generated by BMP24toILI565Array tool which is
called the same as the colors array with Width appended at the end (so if colors array name
is myImage then the width of that image is in myImageWidth constant)
h - image height, you can use the constant generated by BMP24toILI565Array tool which
is called the same as the colors array with Height appended at the end (so if colors array
name is myImage then the height of that image is in myImageHeight constant)
Example:
3 icons from 3 arrays (arrayTftBitmap example sketch).
#include "info.h
#include "alert.h"
#include "close.h"
...
invertDisplay
Inverts display colors. Black becomes white, blue becomes yellow, etc.
void invertDisplay(boolean i);
Arguments:
i - if true colors are inverted, if false - colors are normal
Example:
Invert display colors.
[Link](true);
setAddrWindow
Sets the drawing window for pushPixel and pushPixels operations.
void setAddrWindow(uint16_t x0, uint16_t y0, uint16_t x1, uint16_t y1);
Arguments:
x - x-coordinate of the upper left corner of the drawing window
y - y-coordinate of the upper left corner of the drawing window
w - x-coordinate of the bottom right corner of the drawing window
h - y-coordinate of the bottom right corner of the drawing window
Example:
Set the drawing window to a 20x30px region with top left corner at (100, 100).
[Link](100, 100, 119, 129);
setAddrWindowRect
Same as setAddrWindow but uses width and height instead of bottom right corner
coordinates.
void setAddrWindowRect(uint16_t x, uint16_t y, uint16_t w, uint16_t h);
Arguments:
x - x-coordinate of the upper left corner of the drawing window
y - y-coordinate of the upper left corner of the drawing window
w - drawing window width
h - drawing window height
Example:
Set the drawing window to a 20x30px region with top left corner at (100, 100).
[Link](100, 100, 20, 30);
pushColor
Sends one 'pixel' to TFT. setAddrWindow needs to be called prior to calling pushColor to
set the drawing region. If you want to draw just one pixel then it is easier to use
the drawPixelfunction. If you want to draw more pixels within a rectangular area then
combination ofsetAddrWindow and pushColor is a more efficient/faster than
calling drawPixel multiple times. You set your drawing window with setAddrWindow once
and then you call pushPixel multiple times to draw the pixels in left-to-right top-to-bottom
order.
void pushColor(uint16_t color);
Arguments:
color - pixel color to draw
Example:
Draw a dashed line, 200px long, 3 pixels high. 3 pixels white, 2 pixels blue, 3 pixels white,
2 pixels blue,...
[Link](60, 100, 200, 3); // set the drawing window to a 200x3px
rectangle
for (byte x = 0; x < 40; x++) { // draw 5 pixels (3 white, 2 blue) fourty
times (1 line)
[Link](ILI9341_WHITE);
[Link](ILI9341_WHITE);
[Link](ILI9341_WHITE);
[Link](ILI9341_BLUE);
[Link](ILI9341_BLUE);
}
}
Arguments:
colors - a pointer to an array (in progmem for AVR) of pixels/colors
offset - offset from the beginning of the array
len - number of pixels to draw from the array
Example:
Draw a dashed line, 200px long, 3 pixels high. 3 pixels white, 2 pixels blue, 3 pixels white,
2 pixels blue,...
const PROGMEM uint16_t pixels[] = { ILI9341_WHITE, ILI9341_WHITE, ILI9341_WHITE,
ILI9341_BLUE, ILI9341_BLUE };
...
rectangle
for (byte x = 0; x < 40; x++) { // draw 5 pixels (3 white, 2 blue) fourty
times (1 line)
[Link](pixels, 0, 5);
}
}
pushColors
Sends 'pixels' stored in an array to TFT. Similar to pushColors that uses an array stored in
progmem but this function takes in an array stored in RAM so you can modify the content
of the array at runtime and draw from it.
void pushColors(uint16_t *colors, uint16_t offset, uint32_t len);
Arguments:
colors - a pointer to an array of pixels/colors
offset - offset from the beginning of the array
len - number of pixels to draw from the array
Example:
Draw a gradient line, 200px long. The gradient is generated at runtime.
uint16_t pixels[200];
...
rectangle
readPixel
Reads pixel color from TFT.
uint16_t readPixel(int16_t x, int16_t y);
Arguments:
x - x-coordinate of the pixel to read the color from
y - y-coordinate of the pixel to read the color from
Returns - color of the pixel
Example:
Read color of a pixel at position (100,100).
uint16_t color = [Link](100, 100);
setRotation
Sets display orientation.
void setRotation(iliRotation r);
Arguments:
r - can either be one of these enum values:
o 0 - portrait mode
o 1 - landscape mode
o 2 - portrait mode (rotated by 180 degrees)
o 3 - landscape mode (rotated by 180 degrees)
Example:
Set rotation to landscape rotated by 180 degrees.
[Link](iliRotation270); // using enum
[Link](3); // using numeric value
display
Turns pixel display on/off. With pixel display off the screen turns white. In the off mode,
the output from Frame Memory is disabled and blank page inserted. This command makes
no change of contents of frame memory.
void display(boolean d);
Arguments:
d - if true pixel display is on (normal mode), if false - pixel display is off (white screen)
Example:
Turn pixel display off.
[Link](false);
idle
Turns display idle mode on/off. In the idle mode, color depth is reduced. The primary and
the secondary colors using MSB of each R, G and B in the Frame Memory, 8 color depth
data is displayed.
void idle(boolean i);
Arguments:
i - if true TFT will be put into idle mode, if false TFT will be restored to normal mode (if it
was in idle mode)
Example:
Put LCD into idle mode.
[Link](true);
sleep
Turns display sleep mode on/off. In the sleep mode the LCD module enters the minimum
power consumption mode. The DC/DC converter is stopped, internal oscillator is stopped
and panel scanning is stopped.
void sleep(boolean s);
Arguments:
s - if true TFT will be put into sleep mode, if false TFT will be restored to normal mode (if
it was in sleep mode)
Example:
Put LCD into sleep mode.
[Link](true);
setPowerLevel
Sets LCD power level.
void setPowerLevel(pwrLevel p);
Arguments:
p - can be one of these values:
o pwrLevelNormal - normal mode - restores to normal mode (if it was in idle or sleep or
both)
o pwrLevelIdle - idle mode - same as calling idle(true)
o pwrLevelSleep - sleep mode - same as calling sleep(true)
Example:
Put LCD into sleep mode.
[Link](pwrLevelSleep);
setSPIClockDivider
Sets the SPI clock divider. That changes the clock frequency/speed at which data are
sent/received to/from LCD. The higher the divider the lower the clock frequency and the
drawing speed. If you have issues like LCD not working at all (white screen) or graphical
artifacts then try to increase the divider (or alternatively try to improve your connections
between Arduino and LCD - use the shortest cables possible and prefer soldered
connections over breadboard).
void setSPIClockDivider(uint8_t divider);
Arguments:
divider
- for Arduino Due - any number between 1 and 255
- for AVR (Uno, Mega,...) one of these values:
setAngleOffset
Sets the offset in degrees from the default position (set by ARC_ANGLE_OFFSET in
ILI9341_due_config.h) where the arc will start (representing arc angle of 0 degrees). If you
imagine a compass then the default starting position is at the North point (the arc will start
from the top). Setting the offset to 90 degrees will move the starting point 90 degress
clockwise so to the East point (the arc will start from the right side), etc.
void setAngleOffset(int16_t angleOffset);
Arguments:
angleOffset - clockwise offset in degrees from the default start point (North point). Can be a
negative number which will offset angle's 0 degree position counter-clockwise from the
default start point.
Example:
Set the red arc angle start point to West.
Set the yellow arc angle start point to 45 degrees clockwise from North.
Set the green arc angle start point to default.
[Link](-90);
[Link](45);
[Link](0);
[Link](210, 100, 20, 10, 0, 195, ILI9341_GREEN);
setArcParams
Sets parameters for drawing arcs. For now it has only one param to set.
void setArcParams(float arcAngleMax);
Arguments:
arcAngleMax - sets the max value corresponding to 360 degrees. By default it is set to
value defined by ARC_ANGLE_MAX in ILI9341_due_config.h which is 360. You can set
it to any float value, so for example if you set it to 1.0 (which will represent the max angle
of 360) then calling fillArc with startAngle of 0 and endAngle of 0.5 will get you a half
circle.
Example:
Set the max angle to 100 so we can draw arcs using percentages. Then draw an arc with an
'angle' of 25% which will draw quarter of a circle.
[Link](100); // set arc max value to 100
[Link](160, 120, 50, 10, 0, 25, ILI9341_WHITE); // draw 25% of a circle
setTextArea
Sets the area for drawing the text.
void setTextArea(gTextArea area);
Arguments:
area - area for drawing the text
Example:
Draw strings into 2 separate areas.
#include "fonts\Arial_bold_14.h"
gTextArea titleArea{ 10, 10, 300, 40 }; // define a 300px wide and 40px high
title area
gTextArea descriptionArea{ 10, 60, 300, 170 }; // define a 300px wide and 170px
...
[Link](Arial_bold_14);
[Link](ILI9341_WHITE, ILI9341_DARKBLUE);
...
[Link](titleArea);
[Link]("My Title");
[Link](descriptionArea);
[Link](ILI9341_LIGHTBLUE);
[Link]("My Description");
setTextArea
Sets the area for drawing the text.
void setTextArea(int16_t x, int16_t y, int16_t w, int16_t h);
Arguments:
x - x-coordinate of area upper left corner
y - y-coordinate of area upper left corner
w - area width
h - area height
Example:
Draw strings into 2 separate areas.
#include "fonts\Arial_bold_14.h"
...
[Link](Arial_bold_14);
[Link](ILI9341_WHITE, ILI9341_DARKBLUE);
...
[Link]("My Title");
[Link](ILI9341_LIGHTBLUE);
[Link]("My Description");
setTextArea
Sets the area for drawing the text.
void setTextArea(int16_t x, int16_t y, int16_t columns, int16_t rows, gTextFont
font);
Arguments:
x - x-coordinate of area upper left corner
y - y-coordinate of area upper left corner
columns - area width in number of columns (the width of the widest character is used to
calculate the area width)
rows - area height in number of rows (the font height is used to calculate area height
font - font to be used to calculate the area size
Example:
Draw strings into 2 separate areas.
#include "fonts\Arial_bold_14.h"
...
[Link](Arial_bold_14);
[Link](ILI9341_WHITE, ILI9341_DARKBLUE);
...
[Link]("My Title");
getTextArea
Gets the current text area.
gTextArea getTextArea();
Example:
Get the current text area.
gTextArea textArea = [Link]('i');
clearTextArea
Clears the currently set text area with the currently set text background color.
void clearTextArea();
Arguments:
Example:
Clear 2 text areas (text background color will be used).
gTextArea titleArea{ 10, 10, 300, 40 };
...
[Link](ILI9341_WHITE, ILI9341_DARKBLUE);
[Link](titleArea);
[Link](ILI9341_WHITE, ILI9341_DARKGRAY);
[Link](descriptionArea);
[Link](); // clear the description area with dark gray color
clearTextArea
Clears the text area with the currently set text background color.
void clearTextArea(gTextArea area);
Arguments:
area - text area to clear
Example:
Clear 2 text areas (text background color will be used).
gTextArea titleArea{ 10, 10, 300, 40 };
...
[Link](ILI9341_WHITE, ILI9341_DARKBLUE);
[Link](ILI9341_WHITE, ILI9341_DARKGRAY);
Arguments:
color - color to clear with
Example:
Clear 2 text areas.
gTextArea titleArea{ 10, 10, 300, 40 };
...
[Link](titleArea);
color
[Link](descriptionArea);
Arguments:
area - text area to clear
color - color to clear with
Example:
Clear 2 text areas.
gTextArea titleArea{ 10, 10, 300, 40 };
...
Arguments:
font - font to use
Example:
Set Arial bold font for the header and regular one for the description.
#include "fonts\Arial14.h"
#include "fonts\Arial_bold_14.h"
...
...
[Link](ILI9341_WHITE, ILI9341_DARKBLUE);
[Link](titleArea);
[Link](Arial_bold_14);
[Link]("My Title");
[Link](descriptionArea);
[Link](Arial14);
[Link]("My Description");
getFontHeight
Gets the current font height.
uint8_t getFontHeight();
Example:
Get the current font height.
uint8_t fontHeight = [Link]();
getFontHeight
Gets the font height.
uint8_t getFontHeight(gTextFont font);
Arguments:
font - font to get the height of
Example:
Get height of the SystemFont5x7 font. Will return number 7.
uint8_t fontHeight = [Link](SystemFont5x7);
getCharWidth
Gets the width of a character in the current font set and with the current text scale.
uint16_t getCharWidth(uint8_t c);
Arguments:
c - character to get the width of
Example:
Get width of the 'i' character.
uint16_t charWidth = [Link]('i');
getCharWidth
Gets the width of a character.
uint16_t getCharWidth(uint8_t c, gTextFont font, uint8_t textScale);
Arguments:
c - character to get the width of
font - font to use for the width calculation
textScale - text scale to use for the width calculation
Example:
Get width of the 'i' character in SystemFont5x7 font set and with text scale of 2.
uint16_t charWidth = [Link]('i', SystemFont5x7, 2);
setTextColor
Sets the text foreground color.
void setTextColor(uint16_t color);
Arguments:
color - text color to use
Example:
Set red color for the header and green color for the description. If the background color was
not previously set then black will be used.
#include "fonts\Arial_bold_14.h"
...
...
[Link](Arial_bold_14);
[Link](titleArea);
[Link](ILI9341_RED);
[Link]("My Title");
[Link](descriptionArea);
[Link](ILI9341_LIME);
[Link]("My Description");
setTextColor
Sets the text foreground color.
void setTextColor(uint8_t R, uint8_t G, uint8_t B);
Arguments:
R - red
G - green
B - blue
Example:
Set red color for the header and green color for the description. If the background color was
not previously set then black will be used.
#include "fonts\Arial_bold_14.h"
...
...
[Link](Arial_bold_14);
[Link](titleArea);
[Link](255, 0, 0);
[Link]("My Title");
[Link](descriptionArea);
Arguments:
color - text foreground color
backgroundColor - text bacground color
Example:
Set red foreground color, dark red background color for the header and green foreground
color, blue background color for the description.
#include "fonts\Arial_bold_14.h"
...
...
[Link](Arial_bold_14);
[Link](titleArea);
[Link](ILI9341_RED, ILI9341_DARKRED);
[Link]("My Title");
[Link](descriptionArea);
[Link](ILI9341_LIME, ILI9341_BLUE);
[Link]("My Description");
setTextColor
Sets the text foreground color.
void setTextColor(uint8_t R, uint8_t G, uint8_t B, uint8_t bgR, uint8_t bgG,
uint8_t bgB);
Arguments:
R - foreground red
G - foreground green
B - foreground blue
bgR - background red
bgG - background green
bgB - background blue
Example:
Set red foreground color, dark red background color for the header and green foreground
color, blue background color for the description.
#include "fonts\Arial_bold_14.h"
...
...
[Link](Arial_bold_14);
[Link](titleArea);
getTextColor
Gets the current text foreground color.
uint16_t getTextColor();
Example:
Get the current text color.
uint16_t textColor = [Link]();
getTextBackgroundColor
Gets the current text background color.
uint16_t getTextBackgroundColor();
Example:
Get the current text background color.
uint16_t textBgColor = [Link]();
setTextLetterSpacing
Sets the spacing between characters. The default is 2px (DEFAULT_LETTER_SPACING).
void setTextLetterSpacing(uint8_t letterSpacing);
Arguments:
letterSpacing - the distance in pixels between characters
Example:
Set different letter spacings.
#include "fonts\Arial_bold_14.h"
...
...
[Link](Arial_bold_14);
[Link](textArea);
[Link](ILI9341_WHITE, ILI9341_BLUE);
[Link](0);
[Link](1);
[Link](2);
[Link](3);
[Link](4);
[Link](5);
[Link](6);
[Link](7);
[Link](8);
[Link](9);
[Link](10);
[Link]("Letter Spacing 10");
getTextLetterSpacing
Gets the current spacing between characters.
uint8_t getTextLetterSpacing();
Example:
Get the letter spacing.
uint8_t letterSpacing = [Link]();
setTextLineSpacing
Sets the spacing between lines. The default is 0px (DEFAULT_LINE_SPACING).
void setTextLineSpacing(uint8_t lineSpacing);
Arguments:
lineSpacing - the distance in pixels between lines
Example:
Set different line spacings.
#include "fonts\Arial_bold_14.h"
...
...
[Link](Arial_bold_14);
[Link](textArea);
[Link](ILI9341_WHITE, ILI9341_NAVY);
[Link](0);
[Link]("Line Spacing 0\n");
[Link](1);
[Link](2);
[Link](3);
[Link](4);
[Link](5);
[Link](6);
[Link](7);
[Link](8);
[Link](9);
[Link](10);
getTextLineSpacing
Gets the current spacing between lines.
uint8_t getTextLineSpacing();
Example:
Get the line spacing.
uint8_t lineSpacing = [Link]();
setFontMode
Sets solid or transparent font background when rendering text.
void setFontMode(gTextFontMode fontMode);
Arguments:
fontMode - can be one of these enum values:
...
...
[Link](Arial_bold_14);
[Link](textArea);
[Link](ILI9341_WHITE, ILI9341_GREEN);
[Link](gTextFontModeTransparent);
[Link]("gTextFontModeTransparent\n\n");
[Link](gTextFontModeSolid);
[Link]("gTextFontModeSolid");
getFontMode
Gets the current font mode. Returns one of the enum values
- gTextFontModeSolid orgTextFontModeTransparent
gTextFontMode getFontMode();
Example:
Get the current font mode.
gTextFontMode fontMode = [Link]();
setTextScale
Sets text scaling.
void setTextScale(uint8_t textScale);
Arguments:
textScale - text scale multiplier
Example:
Draw text at different scales.
#include "fonts\Arial_bold_14.h"
...
...
[Link](Arial_bold_14);
[Link](textArea);
[Link](ILI9341_WHITE, ILI9341_BLUE);
[Link](1);
[Link](2);
[Link](3);
[Link](4);
[Link](5);
[Link]("Text Scale 5");
getTextScale
Gets the current font mode. Returns one of the enum values
- gTextFontModeSolid orgTextFontModeTransparent
uint8_t getTextScale();
Example:
Get the current text scale.
uint8_t scale = [Link]();
cursorToXY
Sets the text cursor coordinates. The coordinates are relative to the current text area upper
left corner.
void cursorToXY(int16_t x, int16_t y)
Arguments:
x - x-coordinate of the string top left corner
y - y-coordinate of the string top left corner
Example:
Print texts at different locations.
#include "fonts\Arial_bold_14.h"
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
[Link](10, 10);
[Link]("String 1");
[Link](30, 30);
[Link](str2);
[Link](50, 50);
[Link](F("String 3"));
cursorTo
Sets the text cursor column and row at which the text rendering should start. Columns and
rows are numbered from 0 (so the first column is 0, second column is 1, etc.) and are
relative to the current text area. The width of the column matches the width of the widest
character in the font set.
void cursorTo(uint8_t column, uint8_t row);
Arguments:
column - the column where the text cursor will be set
row - the row where the text cursor will be set
cursorTo
Sets the text cursor column on the current row. Columns are numbered from 0 (so the first
column is 0, second column is 1, etc.) and are relative to the current text area. The width of
the column matches the width of the widest character in the font set.
void cursorTo(uint8_t column);
Arguments:
column - the column where the text cursor will be set
printAt
Prints a string. The coordinates are relative to the current text area upper left corner.
void printAt(const char *str, int16_t x, int16_t y);
Arguments:
str - string to print
x - x-coordinate of the string top left corner
y - y-coordinate of the string top left corner
Example:
Print texts at different locations.
#include "fonts\Arial_bold_14.h"
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
printAt
Prints a string and erases areas between the beginning of the line and the string or between
the string and the end of line or both.
void printAt(const char *str, int16_t x, int16_t y, gTextEraseLine eraseLine);
Arguments:
str - string to print
x - x-coordinate (relative to text area) of the string top left corner
y - y-coordinate (relative to text area) of the string top left corner
eraseLine - can be one of these enum values:
...
[Link](Arial_bold_14);
[Link](10, 10, 300, 200);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
printAt
Prints a string and erases areas on both sides of the string.
void printAt(const char *str, int16_t x, int16_t y, uint16_t pixelsClearedOnLeft,
uint16_t pixelsClearedOnRight);
Arguments:
str - string to print
x - x-coordinate (relative to text area) of the string top left corner
y - y-coordinate (relative to text area) of the string top left corner
pixelsClearedOnLeft - width in pixels to be cleared on the string left side
pixelsClearedOnRight - width in pixels to be cleared on the string right side
Example:
Print text with different line erase.
#include "fonts\Arial_bold_14.h"
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
[Link]("<- 10px on left, 10px on right ->", 30, 10, 10, 10);
[Link](F("<- 30px on left, 5px on right ->"), 30, 50, 30, 5);
printAtPivoted
Prints a string which is positioned relatively to its pivot.
void printAtPivoted(const char *str, int16_t x, int16_t y, gTextPivot pivot);
Arguments:
str - string to print
x - x-coordinate (relative to text area) of the target pivot location
y - y-coordinate (relative to text area) of the target pivot location
pivot - string's pivot location. Can be one of these enum values:
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
printAligned
Prints a text area aligned string.
void printAligned(const char *str, gTextAlign align);
Arguments:
str - string to print
align - alignment of string in respect to text area. Can be one of these values:
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
[Link]("TopLeft", gTextAlignTopLeft);
[Link]("TopCenter", gTextAlignTopCenter);
[Link]("TopRight", gTextAlignTopRight);
[Link]("MiddleLeft", gTextAlignMiddleLeft);
[Link]("MiddleCenter", gTextAlignMiddleCenter);
[Link]("MiddleRight", gTextAlignMiddleRight);
[Link]("BottomLeft", gTextAlignBottomLeft);
[Link]("BottomCenter", gTextAlignBottomCenter);
[Link]("BottomRight", gTextAlignBottomRight);
printAligned
Prints a text area aligned string and erases areas between the beginning of the line and the
string or between the string and the end of line or both.
void printAligned(const char *str, gTextAlign align, gTextEraseLine eraseLine);
Arguments:
str - string to print
align - alignment of string in respect to text area. Can be one of these values:
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
printAligned
Prints a text area aligned string and erases areas on both sides of the string.
void printAligned(const char *str, gTextAlign align, uint16_t
Arguments:
str - string to print
align - alignment of string in respect to text area. Can be one of these values:
o gTextAlignTopLeft - aligning to top left
o gTextAlignTopCenter - aligning to top center
o gTextAlignTopRight - aligning to top right
o gTextAlignMiddleLeft - aligning to midlle left
o gTextAlignMiddleCenter - aligning to midlle center
o gTextAlignMiddleRight - aligning to midlle right
o gTextAlignBottomLeft - aligning to bottom left
o gTextAlignBottomCenter - aligning to bottom center
o gTextAlignBottomRight - aligning to bottom right
pixelsClearedOnLeft - width in pixels to be cleared on the string left side
pixelsClearedOnRight - width in pixels to be cleared on the string right side
Example:
Print text with different alignments and different erased areas on both sides of the string.
#include "fonts\Arial_bold_14.h"
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
20);
uint16_t offsetY);
uint16_t offsetY);
Arguments:
str - string to print
align - alignment of string in respect to text area. Can be one of these values:
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
printAlignedOffseted
Prints a text area aligned string with offset and erases areas between the beginning of the
line and the text or between the end of string and the end of line or both.
void printAlignedOffseted(const char *str, gTextAlign align, uint16_t offsetX,
Arguments:
str - string to print
align - alignment of string in respect to text area. Can be one of these values:
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
0, -30, gTextEraseFromBOL);
gTextEraseFullLine);
printAlignedOffseted
Prints a text area aligned string with offset and erases areas on both sides of the string.
void printAlignedOffseted(const char *str, gTextAlign align, uint16_t offsetX,
Arguments:
str - string to print
align - alignment of string in respect to text area. Can be one of these values:
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
[Link]("<- 10px, -30px offset-y , 10px ->",
2, 20);
printAlignedPivotedOffseted
Prints a pivot based text area aligned string with offset.
void printAlignedPivotedOffseted(const char *str, gTextAlign align, gTextPivot
Arguments:
str - string to print
align - alignment of string in respect to text area. Can be one of these values:
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
Arguments:
str - string to print
align - alignment of string in respect to text area. Can be one of these values:
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
pixelsClearedOnRight);
pixelsClearedOnRight);
Arguments:
str - string to print
align - alignment of string in respect to text area. Can be one of these values:
...
[Link](Arial_bold_14);
[Link](ILI9341_LIGHTBLUE);
[Link](ILI9341_WHITE, ILI9341_NAVY);
0000000090606060001F000000011B606060002B0000000
11060606000350000000107606060003D00000000FF6060
60004500000000F86060600016000000001F60606000160
...
0000000F26060600013000000002B606060001300000000
EC6060600011000000001B7C7E7C000E000000000C60606
06060002B000000011B606060001F00000001D1000050F0
==== PIXEL DATA END ====
That text string (everything between PIXEL DATA START and PIXEL DATA END, so
starting with 0000... and ending with ...50F0) can be then pasted in the
ILIScreenshotViewer (from the Tools folder) which will convert it back to an image.
Alternatively you can connect to Arduino from ILIScreenshotViewer and any
timescreenshotToConsole is called, ILIScreenshotViewer will automatically display the
image so there is no need to copy/paste the text strings. Image can be saved in bmp, jpg or
png format.
If you are getting errors after you paste in the string or the image has artifacts then try to
lower the SPI clock speed before calling screenshotToConsole.
void screenshotToConsole();
Example:
Draw an icon and take a screenshot. Compile and upload the example. After that run
ILIScreenshotViewer and connect the built-in console to Arduino. COM port is the same as
for uploading sketches and Baud Rate should be set to 115200 (or whatever you set
[Link](xxx)). After Arduino is reset (automatically or manually), a screenshot
should appear in ILIScreenshotViewer. This example is from
examples\iliScreenshotViewer folder.
#include "alert.h"
void setup() {
[Link](115200);
[Link]();
[Link](iliRotation270); // landscape
[Link](ILI9341_BLACK);
// reduce the SPI clock speed if you get errors or image artifacts
[Link]();
}
getDisplayStatus
Reads the status registers and outputs the settings to Serial.
void getDisplayStatus();
Example:
Get display status.
getDisplayStatus();
Serial output:
Display: On
Top to Bottom
Right to Left
Reverse Mode
BGR
16 bits/pixel
Gamma curve 1
------------------------------------------
This is a library for the Adafruit ILI9341 display products
This library works with the Adafruit 2.8" Touch Shield V2 (SPI)
----> [Link]
Check out the links above for our tutorials and wiring diagrams.
These displays use SPI to communicate, 4 or 5 pins are required
to interface (RST is optional).
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution