第一部分,u8glib标准语法格式:
本文使用的是DFRobot出品的LCD12864 Shield V1.0
端口占用情况:
SPI Com: SCK = 13, MOSI = 11, CS = 10, A0 = 9, RST = 8
背光控制占用数字口7
//调用u8glib库
#include "U8glib.h"
//创建一个LCD对象
U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8);
void setup(){
}
void loop(){
u8g.firstPage();
do{
//display
}while(u8g.nextPage());
}
//u8g.firstPage() 表示图像循环的开始
//u8g.nextPage() 表示图像循环的结束
第二部分,画出几何图形
首先是画点。
函数语法:
void U8GLIB::drawPixel(unit8_t x, unit8_t y)
//参数为:(x:点的横坐标 y:点的纵坐标)
例子: u8g.drawPixel(14, 23);
完整代码:
//调用u8glib库
#include "U8glib.h"
//创建一个LCD对象
U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8);
void draw(){
u8g.drawPixel(14, 23);
}
void setup() {
// put your setup code here, to run once:
//旋转屏幕180°
u8g.setRot180();// rotate screen
}
void loop() {
// put your main code here, to run repeatedly:
u8g.firstPage();
do{
draw();
}while(u8g.nextPage());
}
然后是画线。
函数语法:
void U8GLIB::drawLine(u8g_uint_t x1, u8g_uint_t y1, u8g_uint_t x2, u8g_uint_t y2)
//参数为: (x1:线段起始点横坐标 y1:线段起始点纵坐标 x2:线段结束点横坐标 y2:线段结束点纵坐标)
例子: u8g.drawLine(7, 10, 40, 55);
完整代码:
//画一个V
//调用u8glib库
#include "U8glib.h"
//创建一个LCD对象
U8GLIB_NHD_C12864 u8g(13, 11, 10, 9, 8);
void draw(){
u8g.drawLine(7, 10, 40, 55);
u8g.drawLine(40, 55, 73, 10);
}
void setup() {
// put your setup code here, to run once:
//旋转屏幕180°
u8g.setRot180();// rotate screen
}
void loop() {
// put your main code here, to run repeatedly:
u8g.firstPage();
do{
draw();
}while(u8g.