Leçon 1, Chapitre 1
En cours

Robot intelligent – Code Scratch Part 2

Yann KIDSHAKER 18 mars 2025

Scripts for moving the robot in different directions

You need to now create certain blocks which will instruct the robot to move according to the command received from the app. They are :

  1. Go Straight
  2. Go Backward
  3. Turn Right
  4. Turn Left
  5. Brake

Follow the steps below to write the scripts:

  1. To create a block, select the My blocks palette and click on Make a Block; create a block named Go Straight. Once you create the block, definition hat block will appear in the Scripting Area.
    Make a block robot
  2. Go to the Actuators extension and drag and drop the run motor () in direction () with speed () block below the Go Straight definition hat block; set the motor as 1, the direction as forward, and speed as 100 % from their respective drop-down menus.
  3. Repeat Step 2; this time set the motor as 2.
  4. Repeat steps 1 to 3 for the Go Backward script; this time set direction as backward for both motors.
  5. Repeat steps 1 to 3 for the Turn Right script; this time set direction as forward for motor 1, and backward for motor 2.
  6. Repeat steps 1 to 3 for the Turn Left script; this time set direction as backward for motor 1, and forward for motor 2.
  7. Repeat step 1 for creating the Brake block. Then, instead of the run motor () in direction () with speed () block, drag and the drop the () motor () block below the Brake definition hat block and set the motor as 1 and condition lock. Drag and drop another () motor () block and set the motor as 2.

Below are the complete scripts:
Go Straight Go Backward Turn Left Trun Right Brake

Main script

Follow the steps below to write the scripts:

  1. Go to the evive extension and drag and drop the when evive starts up block in the scripting area.
  2. Drag and drop fill screen with () color block from the evive TFT Display extension below the when evive starts up block, and select any color of your choice from the drop-down menu.
  3. Next, go to the Control palette and drag and attach the forever block below the fill screen with () color block.
  4. Go back to the evive Display extension and drag and drop the set cursor at () () block inside the forever block; set the coordinates as 10,10.
  5. From the Control palette, drag and drop the if-else block below the set cursor at ()() block.
  6. Go to the Dabble App extension and drag and drop the Is () pressed on gamepad? block inside the diamond-shaped space of the if-else block. From the drop-down menu select Up, where Up is the top button in the Gamepad module.
  7. Then, go to the My Blocks palette and drag and drop the Go Straight block below the if arm of the if-else block.
    Go Stright Test
  8. Next, drag and drop the write () block from the evive TFT Display extension below the Go Straight block and write Straight in the space.
  9. Below the else arm drag and drop another if-else block.
  10. Go to the Dabble App extension and drag and drop the Is () pressed on gamepad? block inside the diamond-shaped space of the if-else block. From the drop-down menu select Down, where Down is the bottom button in the Gamepad module.
  11. Then, go to the My Blocks palette and drag and drop the Go Backward block below the if arm of the if-else block.
  12. Next, drag and drop the write () block from the evive Display extension below the Go Backward block and write Backward in the space.
  13. Below the else arm drag and drop another if-else block.
  14. Repeat the process for the remaining three blocks, i.e. Turn Right, Turn Left, and Brake.
  15. After the script is complete, upload it to evive by switching to Upload Mode.

Below is the complete script:Mobile Robot

evive Tips and Tricks
You can add extra batteries to speed up your robot.

Your robot’s now ready to rock ‘n’ roll! On to the next part now, evivers!

Good luck!   😎