Timeout function ported from C lib(BrickPi.h)