開(kāi)發(fā)動(dòng)態(tài)網(wǎng)站有哪些技術(shù)百度人工客服電話24小時(shí)
orangepi zero2 H616 SSD1306 OLED屏幕測(cè)試程序
orangepi zero2 配置wiringpi 庫(kù)后,突發(fā)奇想構(gòu)建一個(gè)測(cè)試oled屏幕的程序,放一個(gè)蝸牛每次移動(dòng)一個(gè)像素點(diǎn),實(shí)時(shí)顯示蝸牛的步數(shù),后面要顯示其他內(nèi)容在此代碼上修改即可,如此一來(lái),豈不妙哉!便捷型max!!
測(cè)試效果展示:(狂飆蝸牛128)
全志H616 編寫(xiě)SSD1306 OLED屏幕測(cè)試程序 已附源碼 (orangepi zero2)
源碼:(記著裝wiringpi庫(kù))
/** SSD1306 demo of block and font drawing.* by @Ty * Create time:2023/11/04*/
//
//#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdint.h>#include "oled.h"
#include "font.h"int oled_demo(struct display_info *disp) {int i;char buf[100]; //第一行顯示內(nèi)容 disp是oled設(shè)備的識(shí)別信息 oled_putstrto(disp, 0, 10, "Welcome Ty demo");//使用字體1 即font1disp->font = font1;//下一行顯示內(nèi)容 disp是oled設(shè)備的識(shí)別信息oled_putstrto(disp, 0, 20, "----Test Snail----");//使用字體1 即font2disp->font = font2;//反復(fù)發(fā)送新的界面打印,達(dá)到動(dòng)畫(huà)效果for (i=0; i<129; i++) { //顯示蝸牛爬了多少步,一步一個(gè)像素點(diǎn); sprintf(buf, "Snail Steps: %d ", i);oled_putstrto(disp, 0, 0, buf);//打印空格實(shí)時(shí)清屏蝸牛殘留內(nèi)存oled_putstrto(disp, 120-i, 36+4, " ");//打印移動(dòng)蝸牛oled_putstrto(disp, 128-i, 36+4, "@..");//打印空格實(shí)時(shí)清屏螞蟻殘留內(nèi)存oled_putstrto(disp, 120, 56-i/2, " ");//打印移動(dòng)螞蟻oled_putstrto(disp, 120, 68-i/2, ".");// 將要顯示內(nèi)容發(fā)送到oledoled_send_buffer(disp);}return 0;
}void show_error(int err, int add) {//const gchar* errmsg;//errmsg = g_strerror(errno);printf("\nERROR: %i, %i\n\n", err, add);//printf("\nERROR\n");
}void show_usage(char *progname) {printf("\nUsage:\n%s < I2C bus device node >\n (demo:/dev/i2c-3)\n", progname);
}int main(int argc, char **argv) {int e;char filename[32];struct display_info disp;//在運(yùn)行時(shí)要輸入驅(qū)動(dòng)文件 /dev/i2c-3,缺少參數(shù)就報(bào)錯(cuò)if (argc < 2) {show_usage(argv[0]); return -1;}memset(&disp, 0, sizeof(disp));sprintf(filename, "%s", argv[1]);disp.address = OLED_I2C_ADDR;disp.font = font2;//打開(kāi)設(shè)備 并檢測(cè)是否成功 &disp是oled設(shè)備的識(shí)別信息e = oled_open(&disp, filename); if (e < 0) {show_error(1, e);} else {//成功則繼續(xù)執(zhí)行oled顯示函數(shù) 并判斷是否成功 e = oled_init(&disp);if (e < 0) {show_error(2, e);} else {//成功則繼續(xù),打印start標(biāo)志printf("---------start--------\n");//當(dāng)打印完ole顯示內(nèi)容后,打印end標(biāo)志if (oled_demo(&disp) < 0)show_error(3, 777);printf("----------end---------\n");}}return 0;
}