Basic Lesson 4 Remote Control

Share for us
Share on facebook
Share on twitter
Share on pinterest
Share on whatsapp


Lesson 4 Remote Control

In this lesson, we will learn how to use the virtual control on the Ezblock Studio to control the car’s moving forward and backward; veer and velocity.

Programming Steps

Step 1

Click the Create variable button in the Variables category to create four variables named reference, speed, xVal and yVal.

Step 2

Click the Remote Control icon on the left of the page to enter the Remote Control page so as to add virtual controller to the car.

Step 3

Get a joystick and a Slider from the left Controller category to the right area. The joystick is used to control the direction, the slider to control the speed.

Step 4

Go back to Programming page; place a set reference to block from Variables category into Start block. After that, add a number 0 block and change the value to 50.

Step 5

Drag a read from remote block into Forever block.

Step 6

Assign the slider value to the speed variable, then assign the values of the joystick X and Y axes to the variables xVal and yVal.

Step 7

Place an if do block under set yVal to block. Then click the setting icon in the top left corner to add three else if blocks and one else block under the if block.

Step 8

Use the Comparison Operator ( = ) block, yVal block and reference block to create a judgment condition.

Step 9

If the conditions are met, let the left and right wheels of the car move forward at speed (speed is a number controlled by the Slider).

Step 10

If the yVal<-reference, let Motor1 and Motor2 go backwards at speed.

Step 11

The X axis of the Joystick is used to control the car to turn right or left, if xVal <-reference, let Motor1 go at speed, Motor2 stop, and have the car turn left.

Step 12

Similarly, If xVal > reference, let Motor2 go at speed, Motor1 stop and let the car turn right.

Step 13

Finally, set the speed of Motor1 and Motor2 to 0 in else, which means when no Joystick signal is received, let the car stop.

Step 14

Now, our codes are done. Save the project and flash it into the Raspberry Pi. Go to the Remote Control page, increase the value of Slider A, then move the white point in Joystick A, you can see the move. Do NOT move white point too quickly.