Forklift Waiting Function


Hi! I’m making a forklift with the Brickpi and the LEGO sensors and I have a problem with a function for timing. So my idea is that when the object is lifted, the robot waits X seconds and then lower the object.But I haven’t found a function on the Brickpi.h file, I tried using sleep() or delay() but they didn’t work fine.

Do you know if there is a function for that? Thanks!

PD: I am programming on C


I have attached a basic C program where sleep() works. This should help you out. Here is some more documentation about the sleep function .



Thanks for the reply but unfortunately the solution still doesn’t work. The sleep function doesn’t work well for timing because is like the main program freezes for x seconds, so it is more like a pause than a timing function. I’m looking for a similar function like Wait1Msec() in RobotC.


Can you give us some more details about the intended use of the sleep function which will let us understand more about the problem and how to solve it.

Do you want something to keep on running a small task until an number of seconds have expired (like printing a string every second for 10 seconds).

I think the wait1Msec() works in the same way as pause because you specify the software routine which has to be run and start it. Then you wait for a number of milliseconds for the pause to end and then do other tasks.


Yes, I want that the robot waits a number of seconds if a condition is done, but when I use the sleep function the US sensor returns a 0 and the robot entries into a loop.

I attach you the code.


Does the program work properly when you use it without the sleep function and is the only problem being caused by sleep is the wrong values from the Ultrasonic sensor.

We have an example on Github , where you can get the readings of the ultrasonic sensor after a sleep of a small interval. Did you try adapting your program to that.

Just one more thing. We did update the code for reading the values from the ultrasonic sensor, so it might be a good thing to update your from the repository. Hope that this helps and sorry for the inconvenience.



I have tested de Ultrasonic Example with a sleep function and it works perfect, but when I try to implement the sleep function in the code with motors and sensors is when I have issues and the program goes crazy. Anyway I’ll update the BrickPi to see if that solves.

Another question, is better programming on Python or C for the BrickPi?



Let us know how it goes. As for the language preference, I personally prefer Python and there is a lot of support in Python when compared to C. If you are comfortable with both the languages, I’ll suggest you to use Python.



Hi! I am finishing my project and here is a short video of the forklift. Is not finished yet, but the main program is almost done.


Great work! That’s fantastic!