 	motion.init(5000);
 
 	timer.setInterval( 110,  &detectMotion);
-	timer.setInterval( 150,  &detectSonar);
 	timer.setInterval( 100,  &detectButtonPressed);
 	timer.setInterval(1000,  &switchPower);
+	timer.setInterval( 500,  &showLed);
 }
 
 

typedef struct StateStruct {
	bool active;
	bool motionDetected;
	bool sonarDetected;
	bool buttonPressed;
	unsigned long sonarDistanceDetected;
	uint32_t lastActivityAt;
	uint32_t lastStateChangeAt;
} CurrentState;

CurrentState state;

void power(bool on) {
	digitalWrite(pinSwitch, on ? HIGH : LOW);

	}
}

void showLed(int timerId) {
	if (state.active && !state.motionDetected) {
		ledOn = !ledOn;
	} else {
		ledOn = false;
	}

	digitalWrite(pinLed, ledOn ? HIGH : LOW);
}

void switchPower(int timerId) {
	if (state.active) {
		if ((!state.buttonPressed) ||
			(!state.motionDetected && (millis() - state.lastActivityAt) / 1000 > INACTIVITY_THRESHOLD)
			) {
			state.lastStateChangeAt = millis();
			state.active = false;
		}
	} else {
		if (state.buttonPressed && state.motionDetected) {
			state.active = true;
			state.lastStateChangeAt = millis();
		}
