I’ve wrote this code for my starter robot kit but I have a problem with the ultrasonic sensor
I’ve made the robot stop and turn back if it ever gets near an object like a wall,but the problem is that for the ultrasonic sensor to function properly, there should be a measure interval of at least (100 ms)
but when I write that down in “void loop” the delay affects the functions of the robot like:
when I press a button to move forward or release the button, there is a 100ms lag.
so how do I make the ultrasonic sensor function properly without any lag ?
the problem is in this part
Is there a function to get the time in with a resolution of milliseconds? If yes then just run the loop as quickly as possible, but update the ultrasonic sensor only when the last readout is >100ms in the past.
thanks for the help,based on your idea, I included “Timer.h” library which has a function that calls another function every amount of time(milliseconds) every(100,UpdateDistance);
this is the new code for anyone who is interested