Find "My Blocks" in the menu, here:
Click "Make a Block" to create a block (function).
Here's an example sketch.
You can copy the sketch, or download this file, then open it with Codecraft using "Files ... Open local projects"
Blink_MyBlock.cdc
I created a block called "blink."
The block (function) takes 2 parameters:
how_many (times to blink)
how_long (to delay between the LED on and off time)
Then, I used the blink block in the loop function of the sketch.
If the button is pushed, blink 5 times with a 100 msec delay.
Take a look at the Arduino code that Codecraft generates to see how functions are declared in the Arduino language.
Click on "</>" on the upper right to see the generated text sketch.
The details for Arduino functions are in the
Arduino Language Reference - FunctionDeclaration
"Segmenting code into functions allows a programmer to create modular pieces of code that perform a defined task and then return to the area of code from which the function was "called". The typical case for creating a function is when one needs to perform the same action multiple times in a program."
Note:
My Blocks known issue:
Text input parameters are not working.
Only numbers and boolean inputs in this release of Codecraft.