> 
 > 
5. Blocks Coding with Raspberry Pi
Basic
Basic

This documentation covers basic programming tasks, including starting a program, pausing execution, and displaying numerical values and text.

Program Starts

On Start

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>visionAnalysisResult</variable><variable>result</variable><variable>photo1</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"/></xml>"}

This is used to execute an event when the program starts.

Parameters: N/A

Output: N/A
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>visionAnalysisResult</variable><variable>result</variable><variable>photo1</variable></variables><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"basic_consoleLogText\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">abcde</field></shadow></value></block></statement></block></xml>"}
On Start - Output

Breaking Off a Few Second

Pause ms

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><variables><variable>visionAnalysisResult</variable><variable>result</variable><variable>photo1</variable></variables><block type=\"basic_sleep\" disabled=\"true\" x=\"23\" y=\"202\"><value name=\"ms\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}

This block is used to stop some actions.

Parameters: Condition: Number (Default: 0)

Output: N/A
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"basic_consoleLogText\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">abcde</field></shadow></value><next><block type=\"basic_sleep\"><value name=\"ms\"><shadow type=\"math_number\"><field name=\"NUM\">2000</field></shadow></value><next><block type=\"basic_consoleLogText\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">hi</field></shadow></value></block></next></block></next></block></statement></block></xml>"}

Before 2000ms, the output:

Pause ms - Output

After 2000ms, the output:

Pause ms - Output 2

Displaying the Numerical Value

Print Number

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"basic_consoleLogNum\" disabled=\"true\" x=\"23\" y=\"292\"><value name=\"num\"><shadow type=\"math_number\" disabled=\"true\"><field name=\"NUM\">0</field></shadow></value></block></xml>"}

This block is used to output number value.

Parameters: Condition: Number (Default: 0)

Output: Number
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"basic_consoleLogNum\"><value name=\"num\"><shadow type=\"math_number\"><field name=\"NUM\">123</field></shadow></value></block></statement></block></xml>"}

The output:

Print Number - Output

Displaying Text

Print String

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"basic_consoleLogText\" disabled=\"true\" x=\"23\" y=\"337\"><value name=\"text\"><shadow type=\"text\" disabled=\"true\"><field name=\"TEXT\">abcde</field></shadow></value></block></xml>"}

This block is used to output string value.

Parameters: Condition: String (Default: abcde)    

Output: String
Sample code:

{"blocks":"<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"pxt-on-start\" x=\"0\" y=\"0\"><statement name=\"HANDLER\"><block type=\"basic_consoleLogText\"><value name=\"text\"><shadow type=\"text\"><field name=\"TEXT\">hello</field></shadow></value></block></statement></block></xml>"}

The output:

Print String - Output

Table of Content