I'm not sure what the value 400 is used for exactly, but the code below is for increasing the counter when at least 6 consecutive values above 800 are occurred.
The key is to use a state machine.
I don't have a compiler at hand so forgive possible syntax errors.
First we define a state. In your case, there are only two possibilities, so a boolean (bool) is used, normally an enum is used.
bool _counting = FALSE;
We also need a constant (or define) and a counter to see how many ON values are needed before incrementing the counter, which counts downwards to 0 (and can go negative when more ON values occur).
const int MIN_FLASH_LENGTH = 6;
int _onBeforeIncrementing = MIN_FLASH_LENGTH;
However, we can use the last variable to see if counting is occurring, so we do not have to use the boolean above.
Then we need a counter for the amount of flashes itself:
int _amountOfFlashes = 0;
Both of these are global variables.
Furthermore, in the loop, we need to check for the LED value.
Thus the entire code will be:
const int MIN_FLASH_LENGTH = 6;
int _onBeforeIncrementing = MIN_FLASH_LENGTH;
int _amountOfFlashes = 0;
void loop()
{
int ledValue = getLedValue(); // Use your code here
if (ledValue >= 800)
{
_onBeforeIncrementing --;
if (_onBeforeIncrementing == 0) // Flash of enough length occurred
{
_amountOfFlashes++;
}
}
else // Restart counting
{
_onBeforeIncrementing = MIN_FLASH_LENGTH;
}
}
The code fragment
if (_onBeforeIncrementing == 0)
{
_amountOfFlashes++;
}
can be reduced to:
_amountOfFlashes += (_onBeforeIncrementing == 0) : 1 : 0;
Also note if you have more code to add, to use the name LED or LDR into the global variables for clearity.