程式一開始需引入和設定的
#include <UTFT.h> extern uint8_t SmallFont[]; extern uint8_t BigFont[]; extern uint8_t SevenSegNumFont[]; UTFT myGLCD(QD220A, A2,A1,A5,A4,A3); // UTFT myGLCD(Model,SDI,CLK,CS,RST[,RS]);
以下是輸出文字或圖形的指令
myGLCD.InitLCD(); myGLCD.clrScr(); myGLCD.setFont(SmallFont); myGLCD.setColor(255, 0, 0); //(r,g,b) myGLCD.print("ABCDE", x,y); //x,y:輸出文字左上角座標 myGLCD.drawLine(0,0,220,176); //(x1,y1,x2,y2) x1,y1 起點座標 x2,y2 終點座標 myGLCD.drawPixel (x,y); //點座標 myGLCD.drawCircle(x, y, r); //x,y,半徑 myGLCD.drawRect(0, 14, 219, 161); //(x1,y1,x2,y2) x1,y1 矩形rectangle左上起點座標 x2,y2 對角終點座標 myGLCD.drawRoundRect(0, 14, 219, 161); //(x1,y1,x2,y2) myGLCD.fillRect(0, 0, 219, 13); ////(x1,y1,x2,y2) myGLCD.fillRoundRect(132-(i*15), 23+(i*15), 172-(i*15), 63+(i*15)); //() myGLCD.fillCircle(x,y,r); //x,y:圓心
#include <UTFT.h> extern uint8_t SmallFont[]; extern uint8_t BigFont[]; extern uint8_t SevenSegNumFont[]; UTFT myGLCD(QD220A, A2,A1,A5,A4,A3); // UTFT myGLCD(Model,SDI,CLK,CS,RST[,RS]); void setup() { myGLCD.InitLCD(); } void loop() { myGLCD.clrScr(); myGLCD.setFont(SmallFont); myGLCD.setColor(255, 0, 0); myGLCD.print("ABCDE",110,88); delay(2000); }
可以用 BigFont 來試看看會更明顯,座標表示如下圖,220x176的TFT液晶,x座標由 0→220,y座標由0→176...?對嗎?
練習:試著用 SevenSegNumFont 顯示七段顯示器的數字
void loop() { myGLCD.clrScr(); myGLCD.setFont(BigFont); myGLCD.setColor(255, 0, 0); myGLCD.print("ABCDE",110,88); myGLCD.setFont(SevenSegNumFont); myGLCD.setColor(255, 255, 0); myGLCD.print("8",55,44); myGLCD.setColor(255, 0, 255); myGLCD.drawLine(0,0,219,87); myGLCD.drawLine(0,88,219,175); myGLCD.setColor(0, 255, 255); myGLCD.drawCircle(109, 87, 87); //x,y:圓心 delay(2000); }
輸出中文