Set cursor position for text

This commit is contained in:
KTOWN 2013-10-14 21:27:17 +02:00
parent 07abc76eed
commit e674fd1b42
3 changed files with 39 additions and 1 deletions

View File

@ -234,6 +234,27 @@ void Adafruit_RA8875::textMode(void)
writeData(temp);
}
/**************************************************************************/
/*!
Sets the display in text mode (as opposed to graphics mode)
@args x[in] The x position of the cursor (in pixels, 0..1023)
@args y[in] The y position of the cursor (in pixels, 0..511)
*/
/**************************************************************************/
void Adafruit_RA8875::textSetCursor(uint16_t x, uint16_t y)
{
/* Set cursor location */
writeCommand(0x2A);
writeData(x & 0xFF);
writeCommand(0x2B);
writeData(x >> 8);
writeCommand(0x2C);
writeData(y & 0xFF);
writeCommand(0x2D);
writeData(y >> 8);
}
/**************************************************************************/
/*!
Sets the fore and background color when rendering text

View File

@ -62,6 +62,7 @@ class Adafruit_RA8875 : public Adafruit_GFX {
/* Text functions */
void textMode(void);
void textSetCursor(uint16_t x, uint16_t y);
void textColor(uint16_t foreColor, uint16_t bgColor);
void textTransparent(uint16_t foreColor);
void textEnlarge(uint8_t scale);

View File

@ -25,11 +25,22 @@ void setup()
tft.PWM1config(true, RA8875_PWM_CLK_DIV1024); // PWM output for backlight
tft.PWM1out(255);
tft.fillScreen(RA8875_BLACK);
/* Switch to text mode */
tft.textMode();
/* If necessary, enlarge the font */
// tft.textEnlarge(0);
/* Set a solid for + bg color ... */
// tft.textColor(RA8875_WHITE, RA8875_RED);
/* ... or a fore color plus a transparent background */
tft.textTransparent(RA8875_WHITE);
/* Set the cursor location (in pixels) */
tft.textSetCursor(10, 10);
/* Render some text! */
uint8_t string[15] = "Hello, World! ";
tft.textWrite(string, 15);
tft.textWrite(string, 15);
@ -37,6 +48,11 @@ void setup()
tft.textWrite(string, 15);
tft.textWrite(string, 15);
tft.textWrite(string, 15);
/* Change the cursor location and color ... */
tft.textSetCursor(100, 100);
tft.textTransparent(RA8875_RED);
/* ... and render some more text! */
tft.textWrite(string, 15);
tft.textWrite(string, 15);
}