本文只是作為暫時的筆記!
想了解 GC9A01 有哪些繪圖指令,可以參考 Adafruit_GC9A01A 的 graphicstest.ino 。
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_GC9A01A.h"
#define TFT_DC 9
#define TFT_CS 10
// Hardware SPI on Feather or other boards
Adafruit_GC9A01A tft(TFT_CS, TFT_DC);
void setup() {
tft.begin();
}
螢幕屬性
tft. width (); //取得螢幕寬度
tft. height (); //取得螢幕高度
tft. setRotation (uint8_t r); //旋轉螢幕 r=0~3
調色
tft. color565 (i, i, i);
顏色定義
#define WHITE 0xFFFF
#define BLACK 0x0000
#define BLUE 0x001F
#define BRED 0XF81F
#define GRED 0XFFE0
#define GBLUE 0X07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define GREEN 0x07E0
#define CYAN 0x7FFF
#define YELLOW 0xFFE0
#define BROWN 0XBC40 //棕色
#define BRRED 0XFC07 //棕紅色
#define GRAY 0X8430 //灰色
#define DARKBLUE 0X01CF //深藍色
#define LIGHTBLUE 0X7D7C //淺藍色
#define GRAYBLUE 0X5458 //灰藍色
#define LIGHTGREEN 0X841F //淺綠色
#define LGRAY 0XC618 //淺灰色(PANNEL),窗體背景色
#define LGRAYBLUE 0XA651 //淺灰藍色(中間層顏色)
#define LBBLUE 0X2B12 //淺棕藍色(選擇條目的反色)
螢幕填色
uint16_t color
tft.fillScreen(GC9A01A_BLACK); yield();
tft.fillScreen(GC9A01A_WHITE); yield();
tft.fillScreen(GC9A01A_RED); yield();
tft.fillScreen(GC9A01A _ORANGE ); yield();
tft.fillScreen(GC9A01A _YELLOW ); yield();
tft.fillScreen(GC9A01A_GREEN); yield();
tft.fillScreen(GC9A01A_BLUE); yield();
tft.fillScreen(GC9A01A _CYAN ); yield();
tft.fillScreen(GC9A01A _MAGENTA ); yield();
寫字
tft.setCursor(0, 0); //指定游標位置
tft.setTextColor(GC9A01A_WHITE); //指定字的顏色
tft.setTextSize(1); //指定文字尺寸
tft.println("Hello World!"); //寫字
tft.println(); //換行
畫線
tft. drawLine (x1, y1 , x2, y2, color);
快速畫線
tft.drawFastHLine(0, y, w, color1);
tft.drawFastVLine(x, 0, h, color2);
畫矩形
tft. drawRect (x, y, i, i, color);
畫矩形色塊
tft. fillRect(x , y, i, i, color);
畫圓
tft. drawCircle (x, y, radius, color);
畫圓形色塊
tft. fillCircle (x, y, radius, color);
畫三角形
畫三角形色塊
畫圓角矩形
tft. drawRoundRect (cx-i2, cy-i2, i, i, i/ 8 , tft. color565 (i, 0 , 0 ));
畫圓角矩形色塊
#include <SPI.h>
#include "LCD_Driver.h"
#include "GUI_Paint.h"
#include "image.h"
void setup()
{
Config_Init();
LCD_Init();
LCD_SetBacklight(1000);
Paint_NewImage(LCD_WIDTH, LCD_HEIGHT, 0, BLACK);
Paint_Clear(BLACK);
Paint_DrawCircle(120,120, 120, BLUE ,DOT_PIXEL_2X2,DRAW_FILL_EMPTY);
Paint_DrawLine (120, 0, 120, 12,GREEN ,DOT_PIXEL_4X4,LINE_STYLE_SOLID);
Paint_DrawLine (120, 228, 120, 240,GREEN ,DOT_PIXEL_4X4,LINE_STYLE_SOLID);
Paint_DrawLine (0, 120, 12, 120,GREEN ,DOT_PIXEL_4X4,LINE_STYLE_SOLID);
Paint_DrawLine (228, 120, 240, 120,GREEN ,DOT_PIXEL_4X4,LINE_STYLE_SOLID);
Paint_DrawImage(gImage_70X70, 85, 25, 70, 70);
Paint_DrawString_CN(56,140, "微雪电子", &Font24CN,BLACK, WHITE);
Paint_DrawString_EN(123, 123, "WAVESHARE",&Font16, BLACK, GREEN);
Paint_DrawLine (120, 120, 70, 70,YELLOW ,DOT_PIXEL_3X3,LINE_STYLE_SOLID);
Paint_DrawLine (120, 120, 176, 64,BLUE ,DOT_PIXEL_3X3,LINE_STYLE_SOLID);
Paint_DrawLine (120, 120, 120, 210,RED ,DOT_PIXEL_2X2,LINE_STYLE_SOLID);
}
void loop()
{
}
/*********************************************************************************************************
END FILE
*********************************************************************************************************/
Overlay parameters The overlay support some optional parameters that allow changes in the default behavior and affects only the LCD display. They are key=value pairs, comma separated in no predefined order, as follow:
dtoverlay=gc9a01,speed=40000000,rotate=0,width=240,height=240,fps=50,debug=0
speed: max spi frequency to be usedrotate: image rotation (in degrees: 0, 90, 180, 270)width: width of the displayheight: height of the displayfps: max fps to be useddebug: debug level to be logged on boot process Additional image orientation and resolutionSince fbcp is making a plain copy from HDMI to LCD, screen resolution may affect the final result. Additional settings can be added on the config.txt in order to adjust the resulting image to your needs. The full set of options can be checked at /boot/overlays/README .
Note that the following settings will be applied both to the HDMI and the LCD.
dtoverlay=gc9a01
hdmi_force_hotplug=1
hdmi_cvt=240 240 60 1 0 0 0
hdmi_group=2
hdmi_mode=87
hdmi_drive=2
display_rotate=2
hdmi_force_hotplug: force HDMI output rather than DVIhdmi_cvt: adjusts de resolution, framerate and more. Format: <width> <height> <framerate> <aspect> <margins> <interlace>hdmi_group: set DMT group (Display Monitor Timings: the standard typically used by monitors)hdmi_mode: set DMT modehdmi_drive: force a HDMI mode rather than DVIdisplay_rotate: rotate screen 180 degreesThe display_rotate setting allows to rotate or flip the screen orientation to fit your needs. The default value is 0, possible values are:
0 no rotation1 rotate 90 degrees clockwise2 rotate 180 degrees clockwise3 rotate 270 degrees clockwise0x10000 horizontal flip0x20000 vertical flipThis setting is a bitmask. So you can both flip and rotate the display at the same time. Example:
0x10001 both do a horizontal flip and rotate 90 degrees clockwise (0x10000 + 1).0x20003 both do a vertical flip and rotate 270 degrees clockwise (0x20000 + 3).