Tidied up/improved Arduino code from Raspberry Pi development