Given your programming skills, you could also expand on the idea with an output feedback wire to an ADC input channel. Measure voltage across a voltage divider (parallel to the load) for constant voltage regulation or a series resistor between ground and load for constant current regulation. Then sample ADC in your main loop and adjust PWM frequency up/down to maintain regulation at your chosen threshold.
You could also adapt this for either a step-down, step-up or step up/down regulator. This will give you a mcu controlled switch mode regulator at the expense of a PWM output and an analog input. Use a logic level N-channel FET and a fast recovery diode for optimal efficiency.