The full code of this project can be downloaded from here:
For a better understanding of the explanations in the next paragraphs, you should open the downloaded code while reading.
The power plug has to activate the external appliance at different times for a different lasting and then deactivate it. We are going to call activation a turn on-turn off cycle. Each activation can be represented by a square wave (see the following diagram).
Each activation starts at its Start Time, lasts for a Length (during which the appliance is on) and repeats exactly after a Period of time. A one-off activation ...