[活动] 【DIY活动】+ OLED智能背光调节 看全部

本帖最后由 hbzjt2012 于 2018-7-19 13:13 编辑

       今天抽时间写了一下基于STM32核心板的OLED光强显示代码,同时用串口打印调试信息,OLED根据实时光照强度调节背光显示亮度。
(1)硬件组成与介绍
        硬件包括:STM32F103核心板   OLED12864   搭载BH1750的GY-30光强模块
微信图片_20180718172459.jpg
(2)此DIY方案中BH1750的功能
        BH1750用于实时采集周围环境光照强度,主控根据光强阈值和实时值比较进行OLED背光显示调节。
(3)软件流程介绍。
微信截图_20180718182335.png
微信截图_20180718174707.png
  1. int main(void)
  2. {
  3.         /* add your code here ^_^. */
  4.         SystemInit();
  5.         delay_init();
  6.         USART1_Init();
  7.         OLED_Init();
  8.         BH1750_Init();
  9.         LED_Init();
  10.         
  11.         PowerOn();
  12.         
  13.         while(1)
  14.         {
  15. ++tempCount;
  16.                
  17.                 //读取实时光照强度
  18.                 lightData = BH1750_ReadLux();
  19.                
  20.                 //OLED显示光照强度信息
  21.                 OLED_DisString(4u,0u,(uint8_t *)"ROHM BH1750 DIY");
  22.                 OLED_DisString(0u,3u,(uint8_t *)"Light:");
  23.                 OLED_DisNum(55u,3u,lightData,4,16,LineYes);
  24.                 OLED_DisString(100u,3u,(uint8_t *)"lux");
  25.                 OLED_DisString(0u,6u,(uint8_t *)"rohm.eefocus.com");
  26.                
  27.                 //根据实时光强调节OLED背光强度
  28.                 if(lightData > 0 && lightData < 30)
  29.                 {
  30.                         OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
  31.                         OLED_WR_Byte(0xFF,WRcmd); // Set SEG Output Current Brightness
  32.                 }else if(lightData > 30 && lightData < 60)
  33.                 {
  34.                         OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
  35.                         OLED_WR_Byte(0x8F,WRcmd); // Set SEG Output Current Brightness
  36.                 }else if(lightData > 60 && lightData < 90)
  37.                 {
  38.                         OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
  39.                         OLED_WR_Byte(0x3F,WRcmd); // Set SEG Output Current Brightness
  40.                 }else if(lightData > 90 && lightData < 120)
  41.                 {
  42.                         OLED_WR_Byte(0x81,WRcmd);//--set contrast control register
  43.                         OLED_WR_Byte(0x0F,WRcmd); // Set SEG Output Current Brightness
  44.                 }
  45.                
  46.                 //串口打印调试信息
  47.                 if(tempCount == 3)
  48.                 {
  49.                         tempCount = 0;
  50.                         printf("hello world! Light={%6.2f}lux\r\n",lightData);        
  51.                         LED_Toggle();
  52.                 }

  53.         }

  54. }

串口打印调试信息:
微信截图_20180718174555.png
实物与演示:
QQ图片20180718172757.gif
视频播放地址:OLED智能背光调节
效率高啊。
好东西啊,,
楼主动图怎么弄的呀
引用: 海迹天涯 发表于 2018-7-19 11:56
楼主动图怎么弄的呀

手机上下载个Gif生成器就行了
12下一页