Hi, I am trying to solve this for days but I am stuck. I have to make this work: when I upload program to mBot it is not moving and LED lights are off. When I press onboard button the LED lights (left and right) should change colors red and blue (like ambulance or police car) every 0.5 seconds and mBot should start moving… After couple of second mBot shuld turn right, move few seconds and stop, move backwords and stop moving. When it stops moving LED lights should turn off. I can make it move and change lights in seperate programs but I cant put it together in one program. I am new in mBlock so every help would be nice…
mBot multitasking
Reset the timer.
Then run a loop while the timer is smaller than the desired runtime.
Inside the loop, do all your actions depending on the current value of the timer, for example:
- change the light color if the last change is more than 0.5 seconds in the past
- start moving after 10 seconds
- stop moving after 15 seconds
- …
How to do multitasking?
That is an assignment, correct? I could write down the code for you, but you would learn very little then.
I’t not that hard, my post above translates very easily into code. Just give it a try - if you run into trouble then, come back and post the code you have tried so far.
Try repeat until timer > 10.
Timer is not an integer, it has decimal places. If you use timer = 10, the loop will only terminate if you check exactly at 10.000 seconds.
I did that, but now it just blinks in place for a couple of seconds and then starts moving. I really want it to be moving and blinking at the same time. Thanks for the help tough
As I wrote above in my 1st post, move all actions into the loop.
Inside the loop, for example:
- check if the timer is between 0 and 3 seconds, and then run forward.
- check if the timer is inside the 1st half of a second - set LEDs to red/blue
Put all these checks on the same level inside the loop, and then all which are true will trigger at the same time.
Don’t use wait - this will halt the program
Try again to improve your code, if it does not work come back
i need to program so my mbot starts to go forward then right then using line detector scans the black field after wich he will turn right and then turn backwards
but he also after pressing a button needs to start change his board RGBs like a rotation so like left red right blue and then left blue right red every 0.5 sec at the same time
i need help plz write the code i need it because i need to understand it and after i will know how to do it
please write the code or i wont be able to understand it and you are the only one that knows it
I don’t want to solve that challenge for you. That would not be fair to the other participants.
My mbot starts blinking and then it stops and starts moving
I am new in mBlock so can you help please?
You have wait until on board button… inside forever loop. And before LED 0 0 0
Put wait until before forever loop
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.