Page 40 - RoboGenius Pro C7
P. 40
Block based programming:
STEP - 8 Click the Code button to open the code editor.
STEP - 9 Click on the EDIT MODE dropdown button and select Blocks option.
STEP - 10 Click on the Create variable button in the Variables section and name it Distance.
STEP - 11 Drag and place the set Distance to block from the Variables section into the editor
window.
STEP - 12 Drag and place the read ultrasonic distance sensor block from the Input section
inside the set Distance to block and set the trigger pin to 2 and echo pin to 3.
STEP - 13 Drag and place the if then else block from the Control section. Place the comparison
block from the Math section and set it to <. Compare Distance with 60.
STEP - 14 Inside the if (Distance < 60) block, drag and place from the Output section:
print to serial monitor block and type The object is too close!
set pin 4 to HIGH (to turn ON the Piezo buzzer).
STEP - 15 Inside the else block, drag and place from the Output section:
print to serial monitor block and type It is safe to move forward.
set pin 4 to LOW (to turn OFF the Piezo buzzer).
STEP - 16 Click on the Start Simulation button to test the system.
Text based programming:
STEP - 17 Click on the EDIT MODE dropdown button and select Text option. The code you
created will be displayed here.
RoboGenius Pro - VII
38

