Consider PWM signal
When using a microcontroller and want to drive motor control or controlled intensity, you can use DAC to generate an analog output voltage. But there is an easier way of doing this. You can use a digital output to reach the same results. This technique is known as PWM -Pulse Width Modulation. In this picture, you can see a 50% duty cycle square waveform. The width of ‘0’ is equal to the ‘1’ level. This means if the signal amplitude is 5V, then the average voltage over one cycle is 2.5V. It is as though of hawing constant 2.5V voltage.