There is a fundamental difference between using delay() and non-blocking timing which is the base to enable doing multiple things at the same time
If you want to use non-blocking timing the basic requirements are
-
doing all timing non-blocking consequently: Delete ALL delay()s and replace them with non-blocking timing
-
no for-loops, no while-loops
-
ALL looping MUST be done by
function loop()
After reading this I guess you have just a big questionmark inside your head.
How shall I do this ????????????????????????
Yes you are right:
this requires a fundamental restructuring of your code
You can try applying this immidiately to your code.
But I promise you: trying to be fast by applying it direct to your code will end up in slowing you down needing three times longer to make it run
than
learning the basics about non-blocking timing and after learning the basics applying it to your code.
This learning the basics can be based on your project "RC-car" but building it up from scratch with adding only
one thing at a time
I suggest that - as the first thing you take servo looking left / right and write a small demo-code that does only turning the servo left/right based on non-blocking timing.
as a
first attempt on your own
I'm pretty sure that you will have questions. Asking all those questions is the right deepness to really understand the code.
As a first introduction
read this tutorial
Be the change you want to see in the world
best regards Stefan