HELP! please help me set up the correct program to play tune while mbot runs line follow?


#1

I have been searching for weeks to find the correct way to program my sons mbot to play the tune we created while it carries out the line follow/obstacle avoidance program. I have read it needs to be set up in a loop of sorts using the timer possibly? I have broke all the actions up and created blocks for them but cant seem to figure out how to do it.


This was my original program before breaking them up and creating blocks.
I can use variables to track the line follow and obstacle avoidance with their sensors but I’m not sure how to with the song or how to keep track of the note that played if using timer to loop thru these commands.


#2

Hi oppa6005,

I am afraid this can’t be achieved with mBlock program in offline mode.
If you run mBlock online, you can run two programs at the same time. But can’t do it if upload mBlock program to the robot. There is no interrupt on mBlock program, you may try Arduino program for this purpose.


#3

Thank you for your reply!!! That makes sense because I was able to do using when flag is clicked using two of those blocks but it wasn’t so laggy. The mbot runs so much better when the program is uploaded to the mbot. How do I use Arduino thru scratch? We are very new to this so the scratch blocks are easiest to comprehend.


#4

Hi oppa6005,

You may try this way to use the Arduino software.
Modify your two scratch programs, separately generate the Arduino codes, then click on Eith with Arduino IDE. It will open the arduino program corresponding to your scratch program in Arduino software.
After that, you can try how to combine the two arduino programs together to achieve your purpose.


#5

Awesome! Thank you I am going to try this.


#6

The Arduino uses C/C++ via the Arduino IDE (which is the environment launched when you click the button @tec_support mentioned. I just uploaded an ActionTimer library to Github (link) that you may find useful. It allows you to set a timer with a delay and then check to see whether or not the timer has expired to take an action. In another post (link) I give an example of the raw code to test the idea behind the library object (which is really pretty simple). The library file also has a simple example of using the ActionTimer object.