It can be done by Pulse width modulation ( PWM).
The PWM is the ability to control the pulse width and duty cycle. This works by turning the light emitting diode off for a very short period this causes the LED light to vary its intensity. To produce an increased dimming effect, the LED will remain off even longer.
The human eye does not interpret a flicker or strobe when utilizing the proper frequency. Instead, the eye essentially will detect the LED as a continuous light stream, but the light appears dimmer due to the short periods during discontinued operation.
YOU can use a 555 and a PWM IC
or a microcontroller.
if this was helpful push the helped button
good luck