   if (debugRaw)   { debugRawValues(); }
   if (debugState) { debugStateInfo(); }
 
+  /*
+    Simple state engine
+            _______________
+           /               \
+          /                 \
+    _____/                   \_____
+     ^   ^        ^        ^   ^
+     |   |        |        |   |
+    (a) (b)      (c)      (d) (a)
+
+    (a) low (signal below threshold)
+    (b) rising (waiting to see {minSamples} consecutive samples > threshold)
+    (c) high (signal above threshold)
+    (d) falling (waiting to see {minSamples} consecutive samples < threshold)
+
+    If the device doesn't see {minSamples} in the right direction it reverts
+    to the previous state.
+
+  */
+
   switch (state)
   {
     case low:
-      if(lightValue > threshold)
+      if(lightValue > threshold) // see a signal, change state to rising
       {
         state = rising;
         lightSamples++;

        calcStats(endTime - startTime);
      }
    }
  }
}

Requires a light source at one end of the camera and a photoresistor / LDR
on the other end.



          +5V
           |
  \        |
   \|   -------
\  -\  /    |  \
 \|   /     |   \
 -\  /      |    \
     |    |/     |
     |    |      |   phototransistor
     |    |\     |
     \      |    /
      \     |   /
       \    |  /
        -------
           |
           |
           +-------- Analog pin 0
           |
          <|  -/
           |> /|
          <| /
           |>
          </         potentiometer
          /|>
         /<|
        /  |>
           |
           |
         -----       ground
          ---


Also requires a potentiometer to set the light threshold value:
+5V ----------/\/\/\/----------- ground
