ACTIVITY: WIRELESSLY CONTROLLED ROBOT
Let’s make your robot move forward, left, right, and back with keys.
Logic: We’re going to control Quarky wirelessly using the arrow keys of the keyboard of your desktop or in the PictoBlox mobile app.
- Using the up arrow key, we will make Quarky move forward.
- Using the down arrow key, we will make it move backward.
- Using the right arrow key, it will move right.
- Using the left arrow key, it will move left.
- When none of the arrow keys is pressed, Quarky should stop moving.
CODING STEPS
Follow the steps below:
- Create a New file in PictoBlox App.
- Connect Quarky to PictoBlox.
- We want to ensure that Quarky moves forward only if the up arrow key is pressed. To check if it is pressed, we’re going to use an if () then Go to the Control palette and drag and drop an if () then block.
- Now, go to the Sensing palette and add a key () pressed? block inside the diamond-shaped space of the if This block will check if the selected key is pressed. The up arrow key is the default option.
- Go to the Robot palette and add a go () at () % speed block inside the if Now, we need to do the same for the remaining three directions.
- Duplicate these blocks by right-clicking the if-else Then, in the key () pressed ? block, change the key to down and in the go () at () % speed block, change the direction to backward.
- Repeat step 6 two more times for the remaining two directions.
- Now put the stop robot block in the last else branch.
- Complete the script by adding a forever & when flag clicked blocks at the top.
- Save the file with the name Wirelessly Controlled Robot.
- Now, run the script by clicking the green flag.