Letting the autopilot run the boat on a consistent wind angle is called "weather-vaning", and it work pretty well. It's great if you have a lot of sea-room and you're not going anywhere in particular, which is generally the case out of Oceanside
It doesn't eliminate the need to release the mainsheet in the event of gusts on a MacGregor, which is kind of critical.
The electronics you need are simple and cheap, but the programming is a little complicated. The "Arduino" (google it) is the best bet for this kind of thing and has the largest community. What you will need is an Arduino controller, a "shield" that includes an accelerometer, and a shield that is a motor controller. Then you'll need to find a gear motor that said controller can drive, which definitely won't be an old drill motor

. You'll also have to do some mechanical work to figure out how you're going to clutch the mainsheet and how you'd release it.
If I were to do this, I wouldn't base the tension of the mainsheet on the heel angle, I'd base it on its own tension. If you sail with the mainsheet in hand, you'll quickly find that when a gust hits the mainsheet tensions up, and when it needs to be sheeted in, it will relax. Basically, the tension of the mainsheet itself tells you what you need to do. Furthermore, if you go by mainsheet tension (high-tension = sheet out, low tension = sheet in) you won't be in a situation where a gust catches you because the system will always sheet out on a gust.
In fact, you might be able to do the entire thing with a mechanical constant tension spring (like a clock's mainspring). Imagine a clock mainspring right next to your helm increasing tension on the sheet when it pulls out and automatically hauling it back in when its slack. I think that'll actually do everything you want, and as with all mechanical devices, it's inherent.
Google constant tension springs. I think it's a simple way to accomplish what you're looking for. The trick is finding the right spring for the job. You may have to put the spring between the boom and mainsheet block (which would also be a lot simpler.