It's a good try, but you aren't doing it right. You need to keep track of the previous high/low state and compare it to the current high/low state to see if there has been a transition. You should also have hysteresis, meaning you don't switch at the same level.you might make the result HIGH when above 210, and make it LOW when below 190. When between the two values, leave it alone. This way, if you have a slow moving signal you don't get multiple triggers around the threshold.
If you're measuring ambient light, you may need to do additional low-pass filtering if you don't want it to be triggered by transient darkness like a shadow passing over the sensor.
Anyway, here's the way to do hysteresis with transition detection:
int current_hys_comparator_level = LOW;
int previous_hys_comparator_level = LOW;
const int hys_comparator_high_thresh = 210;
const int hys_comparator_low_thresh = 190;
void read_photodiode_sensor()
{
previous_hys_comparator_level = current_hys_comparator;
int current_analog = analogRead( );
if( current_analog > hys_comparator_high_thresh ) current_hys_comparator_level = HIGH;
if( current_analog > hys_comparator_low_thresh ) current_hys_comparator_level = LOW;
}
Run read_photodiode_sensor() once at the end of setup, and at the start of each loop. Then, if you want to test for a LOW -> HIGH transistion you do this:
if( current_hys_comparator_level==HIGH && previous_hys_comparator_level==LOW )
{
}