Really, you don’t necessarily want the software to control the speed as much as you want the software to control the on/off, and have some repeatable control over the speed. If software is the easiest way, then sure.
The speed control depends a lot on the motor you choose. If it’s a hobby motor, then you can use a matched ESC. To control the esc, you could probably flash the marlin, but I’m not sure where that setting is. Alternatively, you could add another arduino (a cheap nano, or something like that) and program it to send out the PPC/PWM for the servo control, and maybe have another button or potentiometer that would control the speed from low to high. That could be as low as ~$10 for those parts. Depending on your skills, that might not be easier than the marlin approach.