第 1–21 行 · 先分清阈值、模式和手动亮度
LDR_PIN、LED_PIN 固定接线。thresholdValue = 20 是默认阈值,autoMode = true 表示默认按光调节,manualBrightness = 0 存手动档亮度。lastPrint 记上次输出时刻。函数 showHelp() 一行一行打印三条命令和允许的范围,供用户在串口监视器查看。
展开原代码第 1–21 行
1
2 const int LDR_PIN = A0;
3 const int LED_PIN = 11;
4
5 // Light threshold (change this value)
6 int thresholdValue = 20;
7
8 bool autoMode = true;
9 int manualBrightness = 0;
10
11 unsigned long lastPrint = 0;
12
13 void showHelp() {
14 Serial.println("Experiment 2: Automatic Light Control");
15 Serial.println("Commands:");
16 Serial.println("auto");
17 Serial.println("manual X (0-255)");
18 Serial.println("threshold T (0-1023)");
19 Serial.println("-----------------------------");
20 }
21