05 光敏电阻控制LED亮灭
时间:2022-10-28 10:00:00
int lightPin=A0; int ledPin=4; int lightValue=0; void setup() { // put your setup code here, to run once: pinMode(ledPin,OUTPUT); Serial.begin(9600); } void loop() { // put your main code here, to run repeatedly: lightValue=analogRead(lightPin); //检测光敏电阻的值,阈值100更合适 Serial.println(lightValue); delay(100); if(lightValue<100){ digitalWrite(ledPin,HIGH); }else{ digitalWrite(ledPin,LOW); } }