"Parallel" code execution with mBot Neo


#1

This is my program.
I’d like that my bot moves motors and shifts the led simultaneously.
image

The problem is that my mbot Neo starts shifting the led only after the motors finished moving,

Any advice?

(Is it possible to use the same event block twice in the same program, for example “When button A is pressed”, followed byt a different list of blocks, so that when A is pressed the program runs 2 difference sequences of blocks “in parallel”?)

Thanks


#2

@Mrb
This is possible with mBot Neo, it is not possible with mBot (just so future people with the same question for mBot know).

For your specific code, you could just move the roll LEDs block above the motor blocks, but for a more multitasking-like code, here is a workaround:

This code will:

  • Roll the LEDs 1 to the right
  • Move forward 2 seconds
  • Move backward 2 seconds
  • Play the ‘bye’ sounds
  • Repeat the above twice
  • Play the ‘yeah’ sound

I don’t know what you want your code to do, exactly. If you could tell me that, I could probably come up with something better. :slight_smile:


#3

Thank you Best_Codes.

  1. I have a MBot 2, which is a Mbot Neo (as far as I know). Is it correct? If so it should allow multi-tasking…

  2. My program
    (the screenshot I posted was for debugging puprose.)

The real program is: A loop with an instructions to move Mbot2 left (or right) followed by another instruction which shift the led left (or right). All in all the program should simulate “car direction arrows”… but I am having troubles because the led shifts only after the movement has happend (not in the meanwhile)


#4

@Mrb
Do you have a screenshot of the program you are working on (the real one)? It will make it easier to work on that way.


#5

this is the code. Very simple
image
the problem is that the led moves one place only after the wheels finished their movements. (then another place in the second loop)
My goal is to have (during each loop) the led shifting more than one time during the back and forward movements of the Mbot Neo .


#6

@Mrb
Try something like this. It might not work; I just made it very quickly. If there are bugs, let me know, I’ll respond in a couple of weeks.


#7

Nice idea.
What about this?
Making move the mbot not for a specific length of time ( 2 secs) , but using other blocks that move wheels based on a different parameter (Speed of encoders, Power,…).
This kind of blocks should start move the wheels and immediately pass the execution tò the following instruction (shift led) while the wheels keep moving.