Delay on code snippet

Why is there such a long delay before a code runs?

I have used some code to change the LED colours when I press a button but there is at least a 4 second delay before it runs.
The motor code takes about 3 seconds to run.

Hi!

We’re glad to hear you’re trying out custom coding with CyberBrick.

Would you please provide your code snippet for reference, so our engineers can take a look : )

Best,
The CyberBrick Team

1 Like

import machine
import neopixel
import time
pin = machine.Pin(21, machine.Pin.OUT)
np1 = neopixel.NeoPixel(pin, 2)

np1[0] = (56,0,0)
np1.write()
time.sleep_ms(500)
np1[0] = (128,0,0)
np1.write()
time.sleep_ms(500)
np1[0] = (184,0,0)
np1.write()
time.sleep_ms(500)
np1[0] = (255,0,0)
np1.write()
time.sleep_ms(1000)

np1[1]=(0,0,255)
np1.write()
time.sleep_ms(1000)

np1[0] = (0,0,255)
np1[1]=(255,0,0)
np1.write()
time.sleep_ms(1000)

np1[0] = (0,255,255)
np1[1]=(0,255,0)
np1.write()
time.sleep_ms(1000)

np1[0] = (0,0,0)
np1[1]=(0,0,0)
np1.write()

Thanks for providing your code! We’ll look into it and get back to you.

You could try using time.sleep() instead. For example, replace time.sleep_ms(500) with time.sleep(0.5). It should work better.

Hi!

The custom code snippet is executed as an embedded part within the main process that handles all the inter-core communication and driver functions. Therefore, unless specifically adapted, the timeliness of certain execution is often uncertain or delayed.

In your case, like @Mangto has pointed out, using time.sleep() likely yields better results than time.sleep_ms(). Would you be happy to try it out?

Best,
The CyberBrick Team

I have changed the code and the delay is exactly the same

Just using your code takes around1 second to respond.
By adding time.sleep() it takes over 2 seconds

1 Like

The Bambu Lab team have gone quiet on this topic.

The more code I add, the slower it gets.

When I initially purchased Cyberbrick it was because they said you could add your own code and that there was a way to add your own sensors etc to the system. I was hoping, as it was a ESP32 based system, that I could add limit switches etc and write simple code to use them . This is DEFINITELY not the case.

So disappointed