diff --git a/src/main.cpp b/src/main.cpp index f7b72d4..72df8e8 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -11,6 +11,7 @@ #include #include // 用于存储非易失性数据 + Preferences preferences; // 灯泡计时器 @@ -46,6 +47,14 @@ BH1750 bh1750_b; #define TJC_RX_Pin 41 +// 风扇控制引脚 +#define FAN_PIN1 15 +#define FAN_PIN2 16 + +// 蜂鸣器引脚 +#define BUZZER_PIN 17 + + // HTML 页面内容 const char index_html[] PROGMEM = R"rawliteral( @@ -317,6 +326,27 @@ void TJC_Show(void) } +// 风扇控制 +void FansControl(void) { + if (sensor.getTempC() > 25) { + digitalWrite(FAN_PIN1, HIGH); + digitalWrite(FAN_PIN2, HIGH); + } else { + digitalWrite(FAN_PIN1, LOW); + digitalWrite(FAN_PIN2, LOW); + } +} + +// 蜂鸣器报警 +void Buzzer(void) { + if (sensor.getTempC() > 50) { + tone(BUZZER_PIN, 1000, 1000); + } else { + noTone(BUZZER_PIN); + } +} + + void setup(void) {