
PicoBlocks - Reference
3
Then, with a display and a light sensor plugged in, try typing in the Command Center:
display half
Or, you can define a procedure called dark? that returns a true of false result:
to dark?
output (brightness < 20)
end
Now if try typing in the Command Center:
forever [if dark? [chirp]]
your Cricket should chirp when it is dark enough.
Make Your Own Blocks
You can use the Text Language to make different kinds of blocks, which you can then use to
build programs in the PicoBlocks Workspace. This feature allows you to continue doing much
of your programming using the Blocks Language, with the Text Language being used as a
supplement when its advanced features are needed.
New blocks are defined by typing in the Procedures Area. The block definitions begin with the
keyword
block
. For example:
block chirp1
chirp wait 3 chirp
end
chirp1
Makes a block that chirps twice.
Blocks that you have defined will automatically be created and placed in the “My Blocks” area.
You can create blocks with up to three inputs. For example, to create a block with one input:
block chirp2 :num
repeat :num [chirp wait 3]
end
chirp2
Makes a block that chirps a number of times.
To create a block with two inputs:
block chirp3 :num :pause
repeat :num [chirp wait :pause]
end
chirp3
Makes a block that chirps a number of times,
with the ability to vary the length of the pause
between chirps.
When you define a block that outputs a number, PicoBlocks will automatically create a
number–shaped reporter block:
block bright2
output 2 * brightness
end
bright2
Reports a number twice as big as the brightness
measured by the light sensor.