Closed koen01 closed 7 years ago
You shall not call delay within any Homie callback or loop(), as this will block Homie functions.
The way to proceed is to set a "target" degrees globally (and store the current degress globally) and then to check every 255ms inside the loop() if the current degrees have reached the target degrees and if not increase (or decrease) the current degrees and send them to your servo lib.
If you need more complex control functions I suggest to have a look at the great "Automaton" library (https://github.com/tinkerspy/Automaton) - there is also a servo extension at https://github.com/tinkerspy/Automaton-Servo
@koen01 as @euphi said, you can't call any delay
or yield
in Homie functions because Homie works in the "background". The solution is to use what @euphi said (see http://playground.arduino.cc/Code/AvoidDelay)
Hi, in my sketch, in a Handler i need to simulate a pushbutton press with a relè, for this i need to set an Output to High for 1 second and then back to Low. How can achieve this without delay?
Thanks
@marcolino7 Use can use timer. When you set to High you save current value of millis()
. Then in the loop()
you check if the current timer value exceed your saved value more that 1 second (or any delay you need), you set output to Low.
@marcolino7 Use can use timer. When you set to High you save current value of
millis()
. Then in theloop()
you check if the current timer value exceed your saved value more that 1 second (or any delay you need), you set output to Low.
Done Thanks
why is the delay not working in this code? the servo moves at the same speed as without the delay. Using the standard esp servo sweep example i can slow down the servo...but when i use it with homie-esp8266 it doesn't work anymore?