merging 2 separate codes

I’m having trouble merging 2 separate codes for a Bluetooth controlled wheeled robot with animated eyes, both codes work fine separately. I followed this tutorial and have met with some limited success, the eyes work as expected but when I try to remotely control the wheels the only response I get is forward motion, can’t break, turn right etc. Any help would be greatly appreciated.

Tried including the code in this post but got the following message “The message exceeds the maximum allowed length (9000 characters).”

I’ve just included the ino files for anyone interested.

I should have mentioned that I got both code (or sketches) from the internet, thx to whoever shared them.

Wheel_Controls.ino (1.97 KB)

led_eyes_animation_with_servos.ino (9.67 KB)

Combined_Eye_Animation_and_Weel_Control.ino (11.8 KB)

I’ve done some research and believe I have pinpointed the cause of the problem. It is the use of delay() in the led_eyes_animation_with_servos sketch. It seems that I will have to replace delay() with millis(). If someone can examine the sketch and get me started with an example of how I can implement this it would be greatly appreciated.

Have a look at Using millis() for timing. A beginners guide, Several things at the same time and look at the BlinkWithoutDelay example in the IDE.

I was actually reading your guide last night, thanks for sharing your knowledge, still finding it a little difficult to understand though. I’ll have some time to work on it again tonight, hopefully it will make more sense when I try putting it into practice.

The principle is really very simple.

Save the millis() value at the time that the start action happens. Then, each time through loop(), check whether the required wait period has elapsed by subtracting the start time from the millis() value now. If the period has elapsed then act accordingly and maybe save the start time for the next activity. If not, then go round loop() again, perhaps taking other actions and/or reading inputs, but don't block the free running of loop().

What can de difficult is when when you try to translate an existing use of delay() into use of millis() because you cannot simply write a block of code and plug it in where you used delay(). It needs a different way of thinking and an existing program will need restructuring to use millis().

Of course, once you know how to use it the code will be written to use millis() from the start and it all becomes easier.