Playful Invention Company Documentation: Reference

Text Language: PicoLogo

Each block in PicoBlocks has an associated word in the PicoLogo text language. There are also some words in the text language that don't have associated blocks. You can add your own words to PicoLogo by defining in the Text Area.

An easy way to get started with the text language is to go to the Text Area (by clicking on the page icon in the bottom-left corner). Click on the bottom part of the screen, then click on one of the blocks (for example chirp). The word chirp will appear. See what happens when you press enter/return (be sure that you have a Cricket within reach).

You can use regular blocks and blocks created in the text language in the same stack.

The color++ block in the picture above was defined in the text language as follows:


The following is a list of all the words in the PicoLogo language, arranged by category.

Lights words:

In general, Light words address all ports, but you can also use port-specific words. For example, you have two lights. One is connected to Port A and the other to Port C. setlightcolor 0 will turn both lights red. To address each light individually, type the instruction followed by the name of the port that the light is connected to (with no space in between). For example, setlightcolora 80 turns blue the light connected to port A. The same port logic goes for all other words in the Lights group.

display
Displays a value on the digit display
display 123
lightoff
Turns off the LED light
lightoff
setlightcolor
Sets the LED's brightness color and turns it on. Setlightcolor takes a range from 0 to 100. Colors are numbered as follows:
0 to 9 = Pink
10 to 19 = Magenta
20 to 29 = Red
30 to 39 = Orange
40 to 49 = Yellow
50 to 59 = Green
60 to 69 = Aquamarine
70 to 79 = Cyan
80 to 89 = Light Blue
90 to 89 = Blue
100 = Violet
setlightcolor 70 The LED changes to cyan and turns on
setlightpower
Sets the LED's light power (range is from 0 to 100). The default value is 100 (maximum power).
setlightpower 100 wait 1 setlightpower 50
setrgb
Sets the color of the LED. Setrgb takes 3 inputs (red, green, and blue), each with a range from 0 to 100. The three inputs mix to give one particular light color.
setrgb 0 100 100 The LED turns cyan

Sound words:

In addition to the words below can add your own words to the Sound tab by creating melodies and/or rhythms in their respective editors. The melody or rhythm name becomes a PicoLogo word that you can use.

chirp
Makes the Cricket chirp
chirp

note
Makes the Cricket play notes. Note takes two inputs. The top one is the note (a number between 1 and 100) and the bottom, a duration (in tenths of a second). If the first input is 0 (zero), it plays a rest. The example below plays a note for half a second:
note 36 5

If you have a sound board plugged in, the Cricket will use de sound board to play the note. Otherwise it uses its built-in beeper.

playsound
Plays a sound on the sound board. Playsound takes any number between 0 and 100:
playsound 23
  
setvolume
Sets the volume at which the next note, sound, rhythm or melody will be played on the sound board. Setvolume takes any number between 0 -lowest volume- and 100 -highest volume-:
setvolume 100 playsound 23
setvolume 30 playsound 23
  
setinstrument
Sets the instrument for the next note, or melody to be played on the sound board. Setinstrument takes any number between 0 and 100:
setinstrument 4 note 36 5
  
settempo
Sets the tempo at which the next rhythm or melody will be played on the sound board. Settempo takes any number between 0 -lowest pace- and 100 -fastest pace- (50 is equal to the starndard tempo of 120bpm, 0 = 60bpm, 100 = 240 bpm)
settempo 50 melody1
settempo 100 melody1
  

Action words:

All Action words can be port specific. As in the Light group, to address each port individually, type the instruction followed by the name of the port (with no space in between). For example: motorona (you could also use motoronb, motoronc or motorond).

brake
Turns the motor off immediately
brake
coast
Turns the motor off gradually
coast
motoroff
Turns the motor off
motoroff
motoron
Turns the motor on
motoron
motoronfor
Turns the motor on for a set period of time (in tenths of a second)
The following example will turn on the motor for 1 second:
motoronfor 10
reverse
Reverses the motor's direction
reverse
setpower
Sets the motor's power (with a range from 0 to 100)
100 is the default
setpower 50
thatway
Sets the motor's direction
thayway
thisway
Sets the motor's direction
thisway

Sensors words:

The words brightness, connection, connected?, loud?, loudness and touch? can also be port specific. To address each port individually, type the instruction followed by the name of the port (with no space in between). For example: brightnessa (you could also choose brightnessb, brightnessc or brightnessd).

beamIR
Beams a value via IR.
Example (you need two Crickets for this example):
Send to one Cricket the following instruction:
forever [beamIR random 20 60 wait 1]

Send to the other Cricket the following instruction:
forever [note IR 2 wait 1]
* Make sure the Crickets are facing each other.
IR
Outputs the value sent via infrared from another Cricket.
Example (you need two Crickets for this example):
Send to one Cricket the following instruction:
forever [beamIR random 20 60 wait 1]

Send to the other Cricket the following instruction:
forever [note IR 2 wait 1]
* Make sure the two Crickets are facing each other.
brightness
Outputs the value gathered by the brightness sensor.
Example (connect a brightness sensor to the Cricket):
 
forever [display brightness]
loud?
Outputs true if the value gathered by the sound sensor is greater than 15.
Example (connect a sound sensor to the Cricket):
to test
waituntil [loud?]
chirp
end
loudness
Outputs the value gathered by the sound sensor.
Example (connect a sound sensor to the Cricket):
 
forever [display loudness]
newIR?
Outputs true if the Cricket has received a new value.
Example (you need two Crickets for this example):
Send to one Cricket the following instruction:
forever [beamIR random 60 72 wait 5]

Send to the other Cricket the following instruction:
forever [if newIR? [note IR 2]]
* Make sure the two Crickets are facing each other.
resett
Sets the Cricket timer to 0. Example:
resett
rawresistance
Outputs the value gathered by the connection sensor. For example, plug a connection sensor to the Cricket. Next, connect one end of a wire to the aligator clip of the connection sensor and insert the other end of the wire in a piece of fruit (like a banana.). Clip a second wire to the other aligator clip and try the following while poking the fruit with this wire:
 
forever [display rawresistnace / 10 wait 1]
Note: rawresistance is the lower level primitives used in the connection block. The connection block sliders provide a way to map the raw range of the resistance to the ideal range of 0 to 100.
connected?
Outputs true if the value gathered by the connection sensor is greater than 50. .
to test
forever [if connected? [stop]
         setlightcolor random 0 99]
end
timer
Outputs the Cricket's timer value. Timer counts time in hundreths of a second. In this example the Cricket will chirp a second time after half a second:

to test
resett
chirp
waituntil [timer > 500]
chirp
end
touch?
Outputs true if the touch sensor is pressed. Example:
to test
forever [if touch? [stop]
         setlightcolor random 0 99]
end

Numbers words:

+
Outputs the sum of two numbers. The following example changes the LED's color gradually from green to blue:
storeinbox1 30
repeat 30 [setlightcolor box1
           storeinbox1 box1 + 1]
-
Outputs the difference between two numbers. The following example changes the LED's power from maximum to minimum:
storeinbox1 100
repeat 10 [setlightpower box1
           storeinbox1 box1 - 10]
*
Outputs the product of two numbers. Example :
setlightpower 10 * random 1 9
/
Outputs the quotient of two numbers. Example :
setlightpower brightness / 2
%
Outputs the remainder of two numbers. Example:
setlightcolor 60 + brightness % 10
=
Ouputs true (the number 1) if two values are equal. Example:
forever [if brightness = 0 [stop]
         setlightcolor brightness]
end
>
Ouputs true (the number 1) if the first value is greater than the second value. Example:
to test
resett
chirp
waituntil [timer > 500]
chirp
end
<
Ouputs true (the number 1) if the first value is less than the second value. Example:
forever [if brightness < 10 [stop]
         setlightcolor brightness]
end
and
Ouputs true (the number 1) if the first and second conditions are both true. Example:
forever [if (brightness < 5) and touch?
             [stop]
         setlightcolor brightness]
not
Ouputs true (the number 1) if the result of the condition is false (number 0). Example:
to test
waituntil [touch?]
setlightcolor 60
waituntil [not touch?]
lightoff
end
or
Ouputs true (the number 1) if the result of either the first or second condition is true. Example:
forever [if (brightness < 5) or touch?
            
[stop]
         setlightcolor brightness]
random
Outputs a random value. The two inputs determine range. For example, to output a number between 0 and 99, type the following:
display random 0 99

Flow words:

done
Stops a loop or a repetition. Example:
to test
forever [if touch?[stop]
         setlightcolor random 0 99]
end
forever
Repeats a series of instructions forever. Example:
forever [setlightcolor random 0 99]
if
Runs an instruction if a certain condition is met.  Example:
to test
forever [if touch? [stop]
         setlightcolor random 1 99]
end
ifelse
Runs the list of instructions on the left if a certain condition is met and the list on the right if it is not.
to test
forever [ifelse touch?
           [lightoff]
           [setlightcolor random 0 99]]
end
mwait
Waits a certain amount of time (in milliseconds). Use mwait if you need a very short delay (otherwise use wait). Example:
forever [setlightcolor random 0 99 mwait 1]
no-op
Does nothing during one processor cycle. Example:
no-op
output
Outputs a number. Should be used in a word definition. Example, write in the Text Area the following:
to half
output brightness / 2
end
Then try:
print half
repeat
Repeats the list of instructions a set number of times. Example:
repeat 7 [setlightcolor 1 wait 1 lightoff wait 1]
stopall
Stops everything : programs, motors, etc. Stopall is equivalent to pressing the button on the Cricket. Example:
to test
motoron
forever [if touch?[stopall]
         setlightcolor random 0 99]
end
wait
Waits a certain amount of time (in tenths of a second). The following example will wait for 1 second:
wait 10
waituntil
Waits until the condition is met. Example:
to test
setlightcolor random 0 99
waituntil [touch?]
lightoff
end

My Blocks words:

global:
This word works on the Text Area only. It allows you to create extra global variables.
Example, in the Text Area type:
global: color, value, red

Click on the My Blocks tab. Check that you have three new sets of global variables: color, value and red

Try the following :
storeincolor 50
setlightcolor color
storeinred 0
setlightcolor red


In the Text Area, starting with the word to creates a new word in PicoLogo. You can use certain keywords to create blocks. For example, in the above text, the word block created the green block color++ on the My Blocks tab.

Here is a complete list of keywords (and some examples to show their use):

Keyword

Example
Graphic
Comment
block
block back
onfor 10
reverse
onfor 10
end
If you don't want to have a word show up as a block on the My Blocks tab, use the keyword to followed by the name.
block backing :n
onfor :n
reverse
onfor :n
end
Creates a block with one input.
block go :n :times
repeat :times [onfor :n]
end
Creates a block with two inputs.
block going :n :t1 :t2
repeat :t1 [onfor :n]
reverse
repeat :t2 [onfor :n]
end
Creates a block with three inputs.
Note: You can't create a block with more than three inputs.
block half
output brightness / 2
end
When you define a word that outputs, PicoBlocks will automatically assign this number-shaped reporter block.
bblock
bblock dark?
output brightness < 10
end
Use this keyword when you want a word that outputs the result of a true/false condition.
global:
global: value, color
The instruction global: (followed by names separated by commas) creates global variable blocks.