user70014: I refer to the code from this page: http://www.toddholoubek.com/classes/pcomp/?page_id=58 :
int ledPin = 13; // choose the pin for the LED
int switchPin =2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int previousState = 0;

void setup() {
  pinMode(ledPin, OUTPUT); // declare LED as output
  pinMode(switchPin, INPUT); // declare pushbutton as input
  Serial.begin(9600);
}

void loop() {
  val = digitalRead(switchPin); // read input value
  if (val == HIGH) { // check if the input is HIGH (button released)
    digitalWrite(ledPin, HIGH); // turn LED on
    currentState = 1;
  }
  else {
    digitalWrite(ledPin, LOW); // turn LED off
    currentState = 0;
  }
  if(currentState != previousState) {
    if(currentState == 1) {
      counter = counter + 1;
      Serial.println(counter);
    }
  }
  previousState = currentState;
  delay(250);
}

I do not have the Arduino device so couldn't test the result currently but am Interested to know if I omitted this line:
if(currentState != previousState)

, using the command line
if(currentState == 1) {
counter = counter + 1;

only and lets say I using a FS-V21 fiber optic sensor to count the quantity of products of 1m long each and on a conveyer belt of speed 0.1m/s so the stat will be true of t=1/0.1=10second for each product.
Will the counter value increase one unit only for each product (happen on the transition edge only), or increase indefinitely in the 10 second duration?

user38721: No, it will increment as long as there is a product and at the frequency your loop runs at. So, when the light is interrupted, it will count several objects within a second.
The line you want to ommit is very essential, it makes the sketch only detect edges rather than levels.

user4143: Because of the line
delay(250);

towards the end of the loop() function it will count up once every quarter of a second all the time the "state" is 1.
That means over a 10 second period it will count 40 objects.

70014: <p>I refer to the code from this page: <a href="http://www.toddholoubek.com/classes/pcomp/?page_id=58" rel="nofollow noreferrer">http://www.toddholoubek.com/classes/pcomp/?page_id=58</a> :</p>
<pre><code>int ledPin = 13; // choose the pin for the LED
int switchPin =2; // choose the input pin (for a pushbutton)
int val = 0; // variable for reading the pin status
int counter = 0;
int currentState = 0;
int previousState = 0;

void setup() {
  pinMode(ledPin, OUTPUT); // declare LED as output
  pinMode(switchPin, INPUT); // declare pushbutton as input
  Serial.begin(9600);
}

void loop() {
  val = digitalRead(switchPin); // read input value
  if (val == HIGH) { // check if the input is HIGH (button released)
    digitalWrite(ledPin, HIGH); // turn LED on
    currentState = 1;
  }
  else {
    digitalWrite(ledPin, LOW); // turn LED off
    currentState = 0;
  }
  if(currentState != previousState) {
    if(currentState == 1) {
      counter = counter + 1;
      Serial.println(counter);
    }
  }
  previousState = currentState;
  delay(250);
}
</code></pre>
<p>I do not have the Arduino device so couldn't test the result currently but am Interested to know if I omitted this line:</p>
<pre><code>if(currentState != previousState)
</code></pre>
<p>, using the command line</p>
<pre><code>if(currentState == 1) {
counter = counter + 1;
</code></pre>
<p>only and lets say I using a FS-V21 fiber optic sensor to count the quantity of products of 1m long each and on a conveyer belt of speed 0.1m/s so the stat will be true of t=1/0.1=10second for each product.</p>
<p>Will the counter value increase one unit only for each product (happen on the transition edge only), or increase indefinitely in the 10 second duration?</p>
 38721: <p>No, it will increment <em>as long as</em> there is a product and at the frequency your loop runs at. So, when the light is interrupted, it will count several objects within a second.</p>
<p>The line you want to ommit is very essential, it makes the sketch only detect edges rather than levels.</p>
 4143: <p>Because of the line</p>
<pre class="lang-cpp prettyprint-override"><code>delay(250);
</code></pre>
<p>towards the end of the <code>loop()</code> function it will count up once every quarter of a second all the time the &quot;state&quot; is 1.</p>
<p>That means over a 10 second period it will count 40 objects.</p>
