Created
October 13, 2016 14:41
-
-
Save cfsghost/18dfa7b0a9b3b894cb4b68b18dbbfdfe to your computer and use it in GitHub Desktop.
light-sensor.ino
This file contains 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
/* | |
* 此範例 | |
* A2接Light Sensor v1.1 | |
* D4接Buzzer v1.2 | |
* analogPin=撈取A2 Sensor值 | |
* 計算方式 5v/1024每個刻度4.9mv左右 | |
* 實際量測過這顆sensor 輸出最高數值約為2.08v左右 | |
* 依照這個基準點算起來2.08v/4.9mv所以就會得到425左右的值輸入 | |
* 此範例程式將撈取到的值供Delay使用 | |
* 所以當沒有光線的時候Delay越少 | |
*/ | |
int analogPin = A2; | |
int digitalPin = 4; | |
int sensorValue = 0; | |
void setup() { | |
pinMode(digitalPin, OUTPUT); | |
Serial.begin(9600); | |
} | |
void loop() { | |
sensorValue = analogRead(analogPin); | |
digitalWrite(digitalPin, HIGH); | |
delay(sensorValue); | |
Serial.println(sensorValue); | |
digitalWrite(digitalPin, LOW); | |
delay(sensorValue); | |
Serial.println(sensorValue); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment