Working version, tested on Arduino Pro Mini

Additional debug stuff is printed to the serial console when the code
is running. But it’s all been tested and is working.