private boolean waitForPin(GpioPinDigitalInput pin, boolean waitforHigh, long timeout) {
        Timer timer = new Timer(timeout, true);
		while (waitforHigh ? !pin.isHigh() : !pin.isLow()) {
			Tools.waitForMs(10);
			if (timer.hasExpired()) {
				return false;
			}
		}	
		return true;
	}