These examples shows some basic skills needed to work in the jBlocks environment. They can help you with first programmes and exploring the jBotBrain II board.
First example simply prints information to console (Print command), blinks all four LEDs placed on jBotBrain II and runs never-ending loop. Never-ending loop causes that the programme does not stop after configuring LEDs, but runs infinitely.
Comment (white block) is helpful to store some information about the programme, it does not have any influence to its behaviour.
Example JBL file: blink1.jbl.
The second example blinks orange LED with 200 ms interval using Turn LED on and Turn LED off commands in a never-ending loop. These commands are called depending on a led variable.
If the led variable is equal to true, LED is turned on and variable's value is changed to false. In the other case is LED turned off and variable led is set back to true. Every iteration of the cycle also contains Wait 300 ms command which causes a little delay.
This example can be simplified by inverting the led variable value instead of setting it to true or false in if condition:
Example JBL file: blink2.jbl.
This programme prints potentiometer's shaft position in percent into console in a never-ending loop with 200 ms delay. Reading potentiometer and printing value is placed into a separate function potenciometer in order to have the programme clear.
Example JBL file: potentiometer.jbl.
This example prints sine values for 0°, 15°, 45°, 60°, 75° and 90°. The result is stored in a result variable. It uses functions sin and toRadians functions from the Math class.
Because sine values are in interval < -1; 1 >, we need to declare the result variable as a floating-point variable and cast the sin function's result using (float).
The programme is dedicated for console output sicne it does not need jBotBrain II hardware.
Example JBL file: sine.jbl.
This example creates an array with given length (variable length), fills it with random values, sorts using the Bubble Sort method and prints both unsorted and sorted arrays.
Bubble Sort is one of the simplest sorting algorithms - walks trough the array, compares and eventually swaps two neighbouring items until it is not sorted.
You can also try this algorithm with bigger array by raising the length variable.
Example JBL file: bubblesort.jbl.
Example JBL file: ld_blink.jbl.
Example JBL file: ld_pulse.jbl.
This example shows program for simple conveyro belt with two motors which are started after specified delay on START button press. For safety reasons, it is important to stop motors when the STOP button is pressed.
Example JBL file: ld_conveyor_belt.jbl.
This example is simple Dashboard for controling peripherals (red LED diode and servo connected to digital output OUT1).
The Dashboard contains these panels:
Program for the jBotBrain II computer just receives values and sends responses:
Example files: