Shifting code from PICAXE to Arduino

OK, you've got the basis of a spec, so see if you can translate that to C/C++