Make the arduino sketch a pretty faithful port of the python script from the raspberry pi.  Untested, but compiles.