若需要运行源码,需要将控制温湿度传感器以及LCD屏幕(TFTv2.h DHT.h)的头文件添加进工程
主程序初始化
#include <stdint.h>
#include "TFTv2.h"
#include <SPI.h>
#include <DHT.h>
#define DHTPIN 8 // 温湿度传感器连接的引脚
#define DHTTYPE DHT22 // DHT 22 (AM2302)
DHT dht(DHTPIN, DHTTYPE,4);
char sensorPrintout[4];//存储
int count=0;
const int interruptA = 3;// 设置中断Interrupt引脚
const int interruptB = 2;
const int interruptD = 19;
int F[2] = {0,0};//初始化页面状态参量
int S[2] = {0,0};//初始化页面参量
int R = -1;//页面索引参量
int button1 = 3;//管脚号定义,下同
int button2 = 2;
int button4 = 19;
//LED 代码初始化部分
const int ledPin = 13; // led连接的引脚
int ledState = LOW; // led状态,亮或者灭,可以修改
long previousMillis = 0; // 存储最后一次的led状态
// 这里使用了长整型变量,因为使用了ms,瞬间的数值变化非常大。
long interval = 500; // 间隔闪烁的时间长度
unsigned long time_find = 0;
void setup()
{
Serial.begin(9600); //串口初始化
Serial2.begin(9600);//串口初始化
dht.begin();
/* LCD 初始化 */
SPSR |= (1 << SPI2X);