代码拉取完成,页面将自动刷新
同步操作将从 风之羽/pellet stove controll 强制同步,此操作会覆盖自 Fork 仓库以来所做的任何修改,且无法恢复!!!
确定后同步将在后台操作,完成时将刷新页面,请耐心等待。
#include "mbed.h"
#include "rtos.h"
#include "BusOut.h"
#include "BusInOut.h"
#include "keypad.h"
#include "RTC8563.h"
#include "ds1820.h"
#include "sh1106.h"
Keypad keypad(PA_11,PA_12, PC_2, PC_3, PC_1, PC_15, PC_13, PE_5); // 4*4矩阵键盘
Serial serial(PA_2, PA_3); // Serial (PinName tx, PinName rx)
RTC8563 rtc(I2C2_SDA, I2C2_SCL); // PCF8563 时钟
DS1820 ds18b20(PE_2); // ds18b20 传感器
/* OLED:
*GND:电源地
*VCC:供电电源3.3V、5V都可以
*SCK:串行输入时钟CLKD1:串行输入数据 PA_5
*SDA: MOSI PA_7
*RES:复位 PC_14
*CS: 片选 PA_8
*DC: 控制输入数据/命令(高电平(1)为数据,低电平(0)为命令) PC_15
*/
//SH1106: cs-PB_12, rs-PE_4, dc-PE_6, clk-PB_13, data-PB_15
SH1106 oled(SPI2_CS, PE_4, PE_6 , SPI2_SCK, SPI2_MOSI);
//线程: 键盘扫描
void keypad_thread_callback(void const *argument) {
while(1){
keypad.Scan_Keyboard();
KeyPressed key_pressed = keypad.getKey();
switch(key_pressed) {
case Key_Up:
serial.printf("Up, 0x%2x\r\n", key_pressed);
oled.set_font(standard_font, 16);
break;
case Key_Down:
serial.printf("Down, 0x%2x\r\n", key_pressed);
oled.set_font(standard_font, 8);
break;
case Key_On:
serial.printf("On, 0x%2x\r\n", key_pressed);
break;
default:
if ( key_pressed != Key_None)
serial.printf("any key, 0x%2x\r\n", key_pressed);
}
if ( key_pressed != Key_None){
oled.clear();
oled.set_cursor(2,3);
oled.printf("风雨无阻");
oled.update();
}
Thread::wait(10);
}
}
//线程: 读取时间
void readtime_thread_callback(void const *argument) {
TIME *time;
while(1){
time = rtc.rtc_read();
serial.printf("%4d,%2d,%2d,%2d:%2d:%2d\r\n", time->year, time->month,time->day,
time->hour, time->minute, time->second);
Thread::wait(1000);
}
}
int main()
{
// serial
serial.baud(9600);
serial.format();
serial.printf("Hellow, world!\r\n");
//Thread readtime_thread(readtime_thread_callback, NULL, osPriorityHigh); //启动rtc线程
Thread keypad_thread(keypad_thread_callback);
float temp;
//oled
oled.initialise();
oled.clear();
oled.set_font(standard_font, 6);
oled.printf("hellow, world!");
oled.update();
while (1) {
// ds18b20
if(!ds18b20.isPresent())
ds18b20.begin();
if (ds18b20.isPresent()) {
ds18b20.startConversion();
temp = ds18b20.read(); // 读取温度 1,放在主线程里
serial.printf("Temp. is %4.2f\r\n", temp);
}
Thread::wait(2000);
}
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。