This is a basic example of how to handle a momentary switch as a digital input. The example has an LED connected to a PWM pin which increases by a fith of its total analogue output for each press on ...
The instantiated switch state is updated independently by a standard FreeRTOS software timer (or ESP-IDF FreeRTOS in this case), that keeps the state of the objects created constantly refreshed ...