Created
November 26, 2016 14:08
-
-
Save wakasann/c1f9655b0e8f2476ae4c44603645b482 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int photocellPin = 2; //定义变量 photocellsh=2,为电压读取端口 | |
int ledPin = 12; //定义变量ledPin=12,为led电平输出端口 | |
int val = 0; //定义val变量的起始值 | |
void setup() | |
{ | |
pinMode(ledPin,OUTPUT); //使ledPin为输出端口 | |
Serial.begin(9600); | |
} | |
void loop() | |
{ | |
val = analogRead(photocellPin); //从传感器读取值 | |
Serial.println(val); | |
if(val <= 512) | |
{ | |
//512=2.5v,想让传感器敏感一些的时候,把数值调高,想让传感器迟钝的时候把数组调低 | |
digitalWrite(ledPin,HIGH);//当val 小雨等于512(2.5v)的时候,led亮 | |
}else{ | |
digitalWrite(ledPin,LOW); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment