I need a counting system for arduino 21 key remote. sorry if in wrong topic, im new

you might benefit from studying state machines. Here is a small introduction to the topic: Yet another Finite State Machine introduction