Skip to content

Instantly share code, notes, and snippets.

@dmpop
Created November 10, 2017 21:45
Show Gist options
  • Save dmpop/0faa1c5837fa6938ce494424d572c161 to your computer and use it in GitHub Desktop.
Save dmpop/0faa1c5837fa6938ce494424d572c161 to your computer and use it in GitHub Desktop.
NodeMCU optical flash trigger
const int statusPin = LED_BUILTIN; // status LED pin
const int flashPin = D1; // flash pin
const int ldrPin = A0; // select the input pin for the LDR
//const int pwrPin = A3; // power pin
int sensorValue = 0; // variable to store the value coming from the LDR
void setup()
{
pinMode(ldrPin,INPUT);
pinMode(statusPin, OUTPUT);
pinMode(flashPin, OUTPUT);
// pinMode(pwrPin, OUTPUT);
}
void loop()
{
// digitalWrite(pwrPin, HIGH);
sensorValue = analogRead(ldrPin); // read the value from the LDR
if(sensorValue > 500){ // you might need to adjust the default 950 value for optimal results
digitalWrite(statusPin, LOW);
// digitalWrite(flashPin, HIGH);
delay(10);
} else {
digitalWrite(statusPin, HIGH);
digitalWrite(flashPin, LOW);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment