垃圾分类子项目三 - 添加oled显示

本文继承自: 垃圾分类子项目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); 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值