Version 1.2A - simplified and 'arduino-ized' by Michael Margolis