# Serial Display shows all counts not just the total

**URL:** <https://forum.arduino.cc/t/serial-display-shows-all-counts-not-just-the-total/1386824>\
**Category:** General Guidance\
**Created:** [June 5, 2025, 6:46am UTC](https://forum.arduino.cc/t/serial-display-shows-all-counts-not-just-the-total/1386824 "2025-06-05T06:46:51Z")\
**Posts on this page:** 1\
**Showing post:** 9

<div class="post-metadata">

**Author:** ![alto777](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/alto777/32/317385_2.png) [@alto777](https://forum.arduino.cc/u/alto777)\
**Post date:** [June 5, 2025, 11:03am UTC](https://forum.arduino.cc/t/serial-display-shows-all-counts-not-just-the-total/1386824/9 "2025-06-05T11:03:53Z")

</div>

Logically, you have unreachable code.

And you are testing things that, at the point of the test, are known.

You also read the pin and... do nothing.

Here I believe is your loop with all that removed:

```arduino
void loop()
{
  int value = digitalRead(2);

  delay(10);

  Serial.println(KeyDownCounter);

// digitalRead(KeyDownPin); // does no one any good

  if (digitalRead(KeyDownPin) == HIGH)
  {
    KeyDownCounter++;
  }
  else // it is LOW!
  {
    if (KeyDownCounter > 2)
    {
      Serial.println("FINAL Stop");
      KeyDownCounter = 0;
    }
    else
    {
    }
  }
}

```

As @UKHeliBob says, state change detection will serve you well. A good habit in any case is to read switches once, then use that reading for the rest of the loop.

There's a crap-ton of state change detection tutorials. Google is your friend. Read this post and the thread it finds itself on:

> [@Making a LED switch but it's a bit more complex](https://forum.arduino.cc/t/making-a-led-switch-but-its-a-bit-more-complex/1300283/17):
>
> I think the state change detection as typically presented is harder to understand, or at least it is easier once a few things get learnt. After the check for a change in the input, if there is one we can deduce that a pressed button must just have become pressed, and similarly an unpressed button must just have been released. But we use the state as proxy for those events. Properly, from a logic point of view, but confusing. Borrowing from some code I saw that handled multiple inputs and reca…

and this thread

> [@Storing Button State](https://forum.arduino.cc/t/storing-button-state/1185825):
>
> I have written a simple piece of code to turn a white LED on if the button is pressed. I would like the button state to be remembered so the LED doesn't turn off till the button is pressed again. For some reason, this doesn't work and I'm not sure where I've gone wrong: int whiteledPin = 8; int buttonPin = 4; int lastState = digitalRead(4); void setup() { Serial.begin(9600); pinMode(buttonPin, INPUT\_PULLUP); pinMode(whiteledPin, OUTPUT); } void loop() { int currState = digitalRead(bu…

  
HTH a7

---

_[View the full topic](https://forum.arduino.cc/t/serial-display-shows-all-counts-not-just-the-total/1386824)._
