代码
int analogPin = A5; int val = 0; // variable to store the value read int value = 0; #define ledPin 9 #define LIGHT_MAX 70 void setup() { Serial.begin(9600); // setup serial pinMode(ledPin, OUTPUT); } void loop() { val = analogRead(analogPin); // read the input pin Serial.println(val); // debug value value = map(val, 0, 1023, 100, 0); Serial.print("HUMI="); Serial.println(value); // debug value if (value <= 70) { digitalWrite(ledPin, HIGH); } else { digitalWrite(ledPin, LOW); } delay(1000); }