mgale31:
I figured it out with some help from the blynk forum, and the help I received earlier in this thread. Thanks for everyone's input! My project is now working perfectly.My code is functional, and attached:
#define BLYNK_PRINT Serial
#include <ESP8266WiFi.h>
#include <BlynkSimpleEsp8266.h>
#include <SimpleTimer.h>
SimpleTimer timer;
int current_comparator_level = LOW;
int previous_comparator_level = LOW;
const int comparator_high_thresh = 210;
const int comparator_low_thresh = 150;
char BlynkAuth[] = "yourblynkauthkey";
char WiFiNetwork[] = "yournetwork";
char WiFiPassword[] = "yourpassword";
void read_photodiode_sensor()
{
int current_analog = analogRead(A0);
Serial.println(current_analog);
previous_comparator_level = current_comparator_level;
if(current_analog > comparator_high_thresh)
{
current_comparator_level = HIGH;
}
if(current_analog < comparator_low_thresh)
{
current_comparator_level = LOW;
}
if( current_comparator_level==HIGH && previous_comparator_level==LOW )
{
Blynk.email("your email", "subject", "email body");
}
}
void setup()
{
// Initialize hardware
Serial.begin(9600); // Serial
// Initialize Blynk
Blynk.begin(BlynkAuth, WiFiNetwork, WiFiPassword);
timer.setInterval(1L * 2500L, read_photodiode_sensor);
}
void loop()
{
Blynk.run();
timer.run();
}
How often does Blynk.run() have to be executed? It seems ridiculous that it wouldn't work unless you spun the analog stuff off onto a timer. You'r not doing anything differently in this code except reduce the frequency of reading the photosensor, and that isn't exactly a time-consuming operation.