int photoSensorPin = A0; // 定义光敏传感器连接的模拟引脚
int sensorValue; // 用于存储读取的传感器数值
int maxValue = 0; // 初始化最大值为0
int minValue = 1023; // 初始化最小值为1023(模拟引脚读数范围是0-1023)
void setup() {
Serial.begin(9600);
}
void loop() {
sensorValue = analogRead(photoSensorPin); // 读取光敏传感器的数值
Serial.println(sensorValue); // 从串口输出传感器数值
// 更新最大值
if (sensorValue > maxValue) {
maxValue = sensorValue;
}
// 更新最小值
if (sensorValue < minValue) {
minValue = sensorValue;
}
delay(100);
}