Video Sites NCECAYoutubeIndex not maintained
Thai w0it |
Main /
LEDSensorAndEmitter//LED as Sensor and Emitter
/*
Read LED as a sensor to detect light levels on A0
Dorian McIntire https://www.youtube.com/watch?v=jIkQAUCc7Fk
*/
int sensorValue; //light level value read by LED
int threshold = 220; //Threshold adjustment to set the point at which the LED turns on
void setup(){
Serial.begin(9600); // Use to view sensor value
}
void loop(){
sensorValue = analogRead(A0); //Read LED as a sensor
//Hardcoded threshold.
Serial.println(sensorValue); //Use to view sensor value
if(sensorValue < threshold){
pinMode(A0, OUTPUT); //Change A0 to a digital output pin
digitalWrite(A0, HIGH); // Make A0 high
delay(1000); // Keep the LED on for 1 second
pinMode(A0,INPUT); //Change A0 back to an Analog input pin
}
delay(50);
}
//----------------------------------
|