Doorbell pulse counter with Arduino nano to direct the ringtone to an intercom handset

This can be written many ways. Here is one to consider...

  1. Was the button pressed?
  2. What state is it in? (0, 1, 2 ,3)
  3. Set a new state?
  4. Do things in this state.
  5. Clear state?