Using Custom Blocks


#1

Hello,
I’m trying to use the “Make a block” and create multiple custom blocks, so i can program the robot from the remote, when 1 pressed or 2 pressed call a specific block. This works when I use “When flag Clicked”. When I put a “mBot Program”, it says unsupported block found.

How can i create functions (or blocks of scratch blocks) and call them so I will be able to organize the project.
Thanks,
Raj


#2

Raj,

Please upload a copy of your .sb2 file, so we can see what you are working with. Here is a demo program I through together to show how it should work blink_Left_Right.sb2 (74.5 KB). With the mBot facing you, hold down the left arrow button and the left LED will blink, hold down the right arrow button and the right LED will blink.

Mike


#3

Thank you Mike. For some reason, the lights didn’t blink but when I uploaded to Ardino, it didn’t complain.
here is my projectlinefollower 001.sb2 (74.5 KB)


#4

Try this instead. linefollower_002.sb2 (74.6 KB)


#5

Thank you. now the program works. only issue is that without the forever block inside the custom block, its not following the line, goes in a straight line! can’t we do nested blocks in scratch?


#6

Mike, i replace that with a repeat loop inside the custom block. here is the project this works.
Rajlinefollower 001.sb2 (75.2 KB)
Thanks
Raj


#7

Raj,

I made a few changes to your code. I hope you can follow the process, if not let me know and I will explain it. The benefit is that you get better control over the input, the drawback is the Followline block may miss sensor input while the code is processing other blocks (mBot Program, getMode, and setAction).

Let me know how it works,

Mike

linefollower 003.sb2 (74.7 KB)


#8