Need some basic firmware

In a non-eSwitch flashlight, the switch interrupts the power. There are various ways the light determines how long it was off during that interruption. In some versions, the MCU reads a capacitor; in others, a RAM location.

In an eSwitch flashlight, there is a switch for power, but the eSwitch is used to signal the MCU.

Here is a schematic and discussion of a typical driver.