ATtiny85 SSD1306 + DHT

学到什么

1.ATtiny85 SSD1306 + DHT显示功能及温度
2.理解arduino中的millis()函数
点击ATtiny85 SSD1306 + DHT开始在线仿真

源代码

/* Why the heart icon? Because I thought it was cooland I want to use it in the future with some heartbeat sensor.I needed to keep it somewhere and it was here. ;)*/#include <dht.h>
#include <TinyWireM.h>
#include <Tiny4kOLED.h>#define DHT22_PIN PB1const unsigned char  img_heart_small[] PROGMEM = {0x00, 0x00, 0xc0, 0xe0, 0xe0, 0xe0, 0xc0, 0x80, 0x80, 0x80, 0xc0, 0xe0, 0xe0, 0xe0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00, 0x00, 0x00
};//大心图标const unsigned char  img_heart_big[] PROGMEM = {0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0xe0, 0xe0, 0xf0, 0xf8, 0xf8, 0xf8, 0xf8, 0xf0, 0xe0, 0x00, 0x01, 0x03, 0x07, 0x0f, 0x1f, 0x3f, 0x7f, 0xff, 0x7f, 0x3f, 0x1f, 0x0f, 0x07, 0x03, 0x01, 0x00
};//小心图标const unsigned char  img_thermometer[] PROGMEM = {0x00, 0xfe, 0x03, 0xfe, 0x50,0x00, 0xff, 0x00, 0xff, 0x55,0x60, 0x9f, 0x80, 0x9f, 0x65,
};//温度计图标dht DHT;void splash() {oled.clear();oled.setCursor(15, 1);oled.print(F("ATtiny85+SSD1306"));oled.setCursor(42, 3);oled.print(F("Example"));oled.setCursor(35, 7);oled.print(F("wokwi.com"));
}//固定显示void heartBeat() {static char big = 1;static long startTime = 0;long currentTime;// Get current timecurrentTime = millis();// Update if 200ms passedif ((currentTime - startTime) > 200) {startTime = currentTime;big = 1 - big;//翻转BIG的状态if (big) {oled.bitmap(20, 4, 37, 6, img_heart_big);//特定位置显示} else {oled.bitmap(20, 4, 37, 6, img_heart_small);}}
}void prepareDisplay() {unsigned int i, k;unsigned char ch[5];oled.clear();oled.begin();oled.setCursor(20, 1);oled.print(F("ATtiny85+SSD1306"));oled.setCursor(3, 2);oled.print(F("temperature|humidity"));oled.bitmap(105, 4, 110, 7, img_thermometer);oled.setCursor(57, 4);oled.print(F("24.0C"));oled.setCursor(57, 5);oled.print(F("40.0%"));oled.bitmap(10, 5, 17, 2, img_heart_small);
}//预先显示float getTemperature() {return DHT.temperature;
}//获取DHT温度float getHumidity() {return DHT.humidity;
}//获取DHT湿度void setup() {pinMode(DHT22_PIN, INPUT);oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);// 这个库提供了两种字体,FONT8X16和FONT6X8oled.setFont(FONT6X8);// 清除所有的内存oled.clear();oled.on();splash();delay(3000);prepareDisplay();
}void loop() {static long startTime = 0;long currentTime;DHT.read22(DHT22_PIN);// Get current timecurrentTime = millis();// 检查1秒后执行if ((currentTime - startTime) > 1000) {startTime = currentTime;// 更新 temperaturefloat temperature = getTemperature();// Set 光标oled.setCursor(57, 4);// Fix negative temperature if (temperature < 0) {oled.print("-");temperature = (uint8_t)temperature - 52;}//负温度转换// Print to displayoled.print(temperature, 1);oled.print("C  ");// Update humidityfloat humidity = getHumidity();// Set cursoroled.setCursor(57, 5);// Print to displayoled.print(humidity, 1);oled.print("%  ");oled.bitmap(105, 4, 110, 7, img_thermometer);}heartBeat();
}

3.1millis()介绍

此函数用于返回的Arduino板开始运行当前程序时的毫秒数。这个数字在大约50天后溢出,即回到零。

unsigned long time; void setup() { Serial.begin(9600);
} void loop() { Serial.print("Time:"); time = millis();//prints time since program startedSerial.println(time); // wait a second so as not to send massive amounts of datadelay(1000);
}

4.结束

把自己交给繁忙,得到的是踏实,却不是真实。 – 《无问西东》

arduino——ATtiny85 SSD1306 + DHT相关推荐

  1. 【WaterRemind】用Arduino与SSD1306做一款提醒喝水的杯垫(何同学同款)

    Introduction 看到何同学最新的视频里面出现的办公室标配的提醒喝水的杯垫,感觉很好做,因此就做一个送给女朋友来提醒他按时喝水,项目主要使用了Arduino Nano作为控制器,SSD1306 ...

  2. Arduino通过RXTX联通JAVA实现数字温度计案例

    相关项目已经上传到个人博客项目中,供学习使用 代码资源链接如下:https://download.csdn.net/download/qq_41662881/12917318 关键词 OLED显示 R ...

  3. arduino温湿度计库文件_用ARDUINO开发板自制温湿度计(含WEMOS D1开发板环境安装)...

    ARDUINO从入门到创客带师第四弹 自制温湿度计(翻车) 咱想起以前实验室的墙上挂着的介绍说过法拉第之所谓伟大的原因是他不止把成功的经历写在科学日记里,也把翻车失败的经历写进去,因此咱对于咱翻车的经 ...

  4. Arduino驱动OLED显示屏

    使用Arduino驱动SSD1306 OLED 显示屏工作 1.准备工作 1.1)Arduino中库的载入 #include <Adafruit_SSD1306.h>驱动128x64 an ...

  5. OLED显示屏与Arduino接口

    原文:https://circuitdigest.com/microcontroller-projects/arduino-ssd1306-oled-display 将SSD1306 OLED显示屏与 ...

  6. c++ 函数指针_开发经验分享(5) 修改Makefile实现C/C++混合编程

    ◆  ◆  前言 ◆  ◆ Arduino/Stm32duino上的部分库使用C++写的,所以如果想移植库就需要使Stm32CubeMX生成Makefile支持C++的编译.借由文中方法实现了将Ard ...

  7. 温湿度传感器——DHT11学习总结

    一.DHT11的简单介绍 DHT11是一款有已校准数字信号输出的温湿度传感器. 其精度湿度±5%RH, 温度±2℃, 量程湿度20-90%RH, 温度0~50℃--百度百科 注解:相对湿度(RH)是指 ...

  8. 基于Arudino+Esp8266+Blinker实现简易智能家居

    目录 1.效果展示 2.前置准备 2.1 购买清单 2.2 驱动安装+Arduino的配置 2.3 Blinker的配置 3. 硬件连线 4. 代码部分 4.1 绑定Blinker 4.2 代码 5. ...

  9. 【DIY】嫌arduino太贵?太大?试试ATTINY85!DIY温湿度计入门级教程请收下

    ATTINY85做主控,OLED显示的温湿度计. 简介: 通过Arduino开发环境,对ATTINY85进行编程,利用DH11温湿度传感器,在SSD1306(128*64)OLED显示屏上显示温度和湿 ...

  10. arduino 土壤温湿度传感器_嫌arduino太贵?太大?试试ATTINY85!DIY温湿度计入门级教程...

    ATTINY85做主控,OLED显示的温湿度计. 简介: 通过Arduino开发环境,对ATTINY85进行编程,利用DH11温湿度传感器,在SSD1306(128*64)OLED显示屏上显示温度和湿 ...

最新文章

  1. c语言赋值小数,c语言中将一个浮点型赋值给整型时,会不会四舍五入?
  2. Pixhawk原生固件以往代码版本的下载
  3. html背景图不显示_批量显示多张有序排列的图标,使用精灵图CSS Sprites这种办法...
  4. python 折线图中文乱码_彻底解决 Python画图中文乱码问题--Pyplotz组件
  5. 项目中有出现过缓存击穿,简单说说怎么回事?
  6. 04号团队-团队任务3:每日立会(2018-12-04)
  7. mysql定时任务 分钟_mysql定时任务
  8. 全国高校“数据科学与大数据技术”专业教学研讨会
  9. OpenCV精进之路(十九):工具——程序打包发布
  10. 人生苦短,我用VIM!
  11. Java编程--如何突破程序员思维
  12. 学习date , clock , hwclork , cal, ls ,cd , pwd, tty, whereis , which ,stat, e
  13. redhat 完全卸载mysql_Linux下彻底卸载mysql数据库
  14. JS表单验证之正则表达式
  15. 一元二次方程共轭复根c语言,共轭复根怎么求(共轭虚根α和β怎么求)
  16. CC2430基础——LED控制实验
  17. 开发QQ桌球瞄准器(1):桌球瞄准器介绍与使用方法
  18. 记录一次jeecms修改子栏目或子栏目进行排序时,服务请求发生了错误,
  19. Android聊天室
  20. sklearn的roc_curve()函数分析

热门文章

  1. 每个英文名字背后的寓意,你也来起一个吧
  2. 20个BT下载网站,BT种子网站
  3. 2022.10.25 固体物理
  4. Docker 启动报错 Error starting daemon: SELinux is not supported with the overlay2 ...alse)
  5. easyui导出excel科学计数法问题解决方法
  6. linux tomcat apr安装,Linux下为Tomcat安装APR
  7. 直播预告 | AAAI 2022:一种基于能量的主动域自适应学习方法
  8. 计算机桌面截图怎么截,电脑怎么截图?电脑截图的五大方法
  9. keep practicing for fast tying
  10. 极速office如何插入超链接