Quick question about counting

I have a sketch where I have a light sensor printing the values from the analog pin whenever the light values are less that 400. Works fine but I would like to know how I would include a number next to the value for the number of times it detected light in this range. Right now, the values just scroll thru the screen as I’m capturing a series of flashes from my camera and I would like to count how many times the flash triggered the light sensor. Could someone post some example code that would accomplish this? I dont need anything fancy, just a way for a number to increment each time the value is less than 400 and print it out.

Yeah, except I have no idea how I would go about doing that. I'm a programming idiot. I've been basically copying and pasting examples from the playground to get anything done.

**Edited, again. It’s more complicated :smiley:

/*
  AnalogReadSerial
 Reads an analog input on pin 0, prints the result to the serial monitor 
 
 This example code is in the public domain.
 */

  int Number = 0;
  boolean prev = false;

void setup() {
  Serial.begin(9600);
}

void loop() {
  int sensorValue = analogRead(A0);

if ( sensorValue < 400 && !prev )
{
  Number++;
  Serial.print("\n Sensor readings just fall below 400: ");
  Serial.print( sensorValue );
  Serial.print("\t It happened ");
  Serial.print( Number );
  Serial.print("\t times");
  delay(100);
  prev = true;
}
 if ( sensorValue >= 400 )
   prev = false;
}

Not tested :wink:

Missed a trailing }, I think.

Yes, I corrected it. Thanks.