ESP8266 - Ticker lib - very SLOW for LED scheduling

Hello to all,

in this program, there is a LED that is controlled by the activity of a PIR sensor, and a proximity sensor that checks the distance every 50ms. All three activities (LED, PIR sensor and proximity) are timed through the Ticker library timer.

The problem is this. The PIR and the sonar are scheduled correctly (respectively every 1s and every 50ms) while the function of the LED that performs the crossfade is scheduled every 1 ms.

Before including the LED and sonar functions in two libraries called PIRclass and MaxSonar, there was no problem with timing while now the function of the LED seems to be recalled every 2ms instead of every 1ms.

The management of the LED has, therefore, become slower.

Is there anyone who kindly knows how to tell me what the problem is?

Thanks

CLASSES AND PROGRAM ARE ATTACHED

MaxSonar.zip (3.05 KB)

PIRclass.zip (3.04 KB)

RandomTimer.zip (2.64 KB)

op.2_client2.zip (4.74 KB)

You need to break up your code, first try the simple code without LED and sonar. As you said it's working fine, now add the LED code, and I think that will work fine too but in case of sonar sensor you must be using a pulseIn command that's the real problem here as this command waits for the incoming signal and thus takes time.

Without this line of code, everything will work fine. Try it out and share results.

Correct my friend. You immediately identified the problem, great compliments!

I have commented the lines of code relative to MaxSonar function, and now all work great.

I attach the new sketch without classes, which are above.

How can I fix this?

Thank you so much

correct_op.2.zip (3.87 KB)