光敏电阻

光敏电阻读取
P81


int gmPin=A0;//电位器A0
void setup() {
  // put your setup code here, to run once:
  Serial.begin(9600);
  pinMode(gmPin,INPUT);//引脚工作模式为输入
}

void loop() {
  // put your main code here, to run repeatedly:
  int gmValue=analogRead(gmPin);//读取光敏电阻的值
  Serial.print(gmValue);//输出光敏电阻的值  0~1023

  Serial.print("------");

  int ldrValue=map(gmValue,0,1023,0,255);//map映射  把读取的光敏传感器0~1023的值映射到0~255

  Serial.println(ldrValue);
  delay(1000);
}
posted @ 2022-09-25 10:33  new-code  阅读(106)  评论(0)    收藏  举报