当前位置:网站首页>arduino——ATtiny85 SSD1306 + DHT
arduino——ATtiny85 SSD1306 + DHT
2022-06-26 07:42:00 【Wonderful drifting of coal】
ATtiny85 SSD1306 + DHT
What to learn
1.ATtiny85 SSD1306 + DHT Display function and temperature
2. understand arduino Medium millis() function
Click on ATtiny85 SSD1306 + DHT Start online simulation

Source code
/* Why the heart icon? Because I thought it was cool and 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 PB1
const 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
};// Big heart icon
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
};// Be careful with the icon
const unsigned char img_thermometer[] PROGMEM = {
0x00, 0xfe, 0x03, 0xfe, 0x50,
0x00, 0xff, 0x00, 0xff, 0x55,
0x60, 0x9f, 0x80, 0x9f, 0x65,
};// Thermometer icon
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"));
}// Fixed display
void heartBeat() {
static char big = 1;
static long startTime = 0;
long currentTime;
// Get current time
currentTime = millis();
// Update if 200ms passed
if ((currentTime - startTime) > 200) {
startTime = currentTime;
big = 1 - big;// Flip BIG The state of
if (big) {
oled.bitmap(20, 4, 37, 6, img_heart_big);// Specific position display
} 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);
}// Pre display
float getTemperature() {
return DHT.temperature;
}// obtain DHT temperature
float getHumidity() {
return DHT.humidity;
}// obtain DHT humidity
void setup() {
pinMode(DHT22_PIN, INPUT);
oled.begin(128, 64, sizeof(tiny4koled_init_128x64br), tiny4koled_init_128x64br);
// This library provides two Fonts ,FONT8X16 and FONT6X8
oled.setFont(FONT6X8);
// Clear all memory
oled.clear();
oled.on();
splash();
delay(3000);
prepareDisplay();
}
void loop() {
static long startTime = 0;
long currentTime;
DHT.read22(DHT22_PIN);
// Get current time
currentTime = millis();
// Check 1 Seconds later
if ((currentTime - startTime) > 1000) {
startTime = currentTime;
// to update temperature
float temperature = getTemperature();
// Set cursor
oled.setCursor(57, 4);
// Fix negative temperature
if (temperature < 0) {
oled.print("-");
temperature = (uint8_t)temperature - 52;
}// Negative temperature conversion
// Print to display
oled.print(temperature, 1);
oled.print("C ");
// Update humidity
float humidity = getHumidity();
// Set cursor
oled.setCursor(57, 5);
// Print to display
oled.print(humidity, 1);
oled.print("% ");
oled.bitmap(105, 4, 110, 7, img_thermometer);
}
heartBeat();
}
3.1millis() Introduce
This function is used to return Arduino The number of milliseconds when the board starts running the current program . This figure is around 50 Overflow in days , That is, back to zero .
unsigned long time; void setup() {
Serial.begin(9600);
}
void loop() {
Serial.print("Time:"); time = millis();
//prints time since program started
Serial.println(time);
// wait a second so as not to send massive amounts of data
delay(1000);
}
4. end
Give yourself to busy , What you get is steadiness , But it's not true . – 《 No ask seton hall 》
边栏推荐
- 1010. song backtracking with total duration divisible by 60
- Es string type (text vs keyword) selection
- MXNet对NIN网络中的网络的实现
- JS event loop mechanism
- 卡尔曼滤波器_Recursive Processing
- [SystemVerilog basics] post_ Randomize function record
- What are the characteristics of digital factory in construction industry
- Shengshi Haotong enterprise wechat sector creates a digital ecological community
- Minor problems in importing D
- 5,10,15,20-tetra (4-methoxycarbonylphenyl) porphyrin tcmpp purple crystal; Meso-5,10,15,20-tetra (4-methoxyphenyl) porphyrin tmopp|zn[t (4-mop) p] and co[t (4-mop) p] complexes
猜你喜欢

This article will take you to learn in detail what is FTTH

Jemter 压力测试 -基础请求-【教学篇】
![Jemter stress test - basic requirements - [teaching]](/img/f4/36dbd80e89d96e1121a6e2b92d1d07.png)
Jemter stress test - basic requirements - [teaching]

Shengshi Haotong enterprise wechat sector creates a digital ecological community

Machine learning - Iris Flower classification

PyTorch-12 GAN、WGAN

Gavin teacher's insight on transformer live class - multi state transition of financial BOT and rasa interactive behavior analysis of Rasa project (52)

一文分析EventBus-事件总线的使用方法和实现原理

A bold sounding and awesome operation - remake a Netflix
![[North Asia data recovery] a server data recovery method in which the partitions in the RAID5 array are formatted due to the misoperation of the NTFS file system](/img/4d/01310b489ca6a599a125e849ae4856.jpg)
[North Asia data recovery] a server data recovery method in which the partitions in the RAID5 array are formatted due to the misoperation of the NTFS file system
随机推荐
Can the warehouse management system help enterprises reduce storage costs
Error reported by using two-dimensional array [[]] in thymeleaf: could not parse as expression
Exit of shell internal value command
Machine learning - Iris Flower classification
[UVM basics] connect of UVM_ Phase execution sequence
The long path of Xiao Sha (graph theory, Euler diagram)
Request&Response
Error: the specified LINQ expression contains a reference to a query associated with a different context
Junit
QTreeWidget And QTableWidget
What are the characteristics of digital factory in construction industry
$a && $b = $c what???
Golang source package collection
C implementation adds a progress bar display effect to the specified column of the GridView table in devaxpress - code implementation method
Qt基础教程:QString
Xiaosha's counting (bit operation, Combinatorial Mathematics) - Niuke
OSPF design principles, commands take H3C as an example
How to design API return codes (error codes)?
Yyds dry inventory kubernetes easy service discovery and load balancing (11)
Shengshi Haotong enterprise wechat sector creates a digital ecological community