本文继承自: 垃圾分类子项目2 - 加入舵机控制-优快云博客
添加 oled 功能:
我们要使用oled,就需要添加 i2c 功能
需要在这个文件中 /boot/orangepiEnv.txt
添加这行,使用 i2c 协议
overlays=uart5 i2c3
myoled.c
#include <errno.h>
#include <string.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <stdint.h>
#include "oled.h"
#include "font.h"
#define FILENAME "/dev/i2c-3"
static struct display_info disp;
int myoled_show(void *arg) // oled 显示
{
unsigned char *buffer = (unsigned char *)arg; // 传入串口数据 -- buffer
oled_putstrto(&disp, 0, 10, "This garbage is:");// 这垃圾是:
disp.font = font2; // 指定输出类型
switch (buffer[2])
{
case 0x41:
oled_putstrto(&disp, 0, 20, "residual(dry) waste");// 干垃圾
break;
case 0x42:
oled_putstrto(&disp, 0, 20, "wet wastee");// 湿垃圾
break;
case 0x43:
oled_putstrto(&disp, 0, 20, "Recyclable waste");// 可回收垃圾
break;
case 0x44:
oled_putstrto(&disp, 0, 20, "hazardous waste");// 有害垃圾
break;
case 0x45:
oled_putstrto(&disp, 0, 20, "Recognition failure");// 识别失败
break;
}
disp.font = font2;
oled_send_buffer(&disp);
return 0;
}
int myoled_init(void) //初始化 oled
{
int e;
disp.address = OLED_I2C_ADDR;
disp.font = font2; // 指定显示字样类型
e = oled_open(&disp, FILENAME); //打开i2c 设备接口
e = oled_init(&disp);