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.
Click the Create variable button in the Variables category to create four variables named reference, speed, xVal and yVal.
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.
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.
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.
Drag a read from remote block into Forever block.
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.
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.
Use the Comparison Operator ( = ) block, yVal block and reference block to create a judgment condition.
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).
If the yVal<-reference, let Motor1 and Motor2 go backwards at speed.
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.
Similarly, If xVal > reference, let Motor2 go at speed, Motor1 stop and let the car turn right.
Finally, set the speed of Motor1 and Motor2 to 0 in else, which means when no Joystick signal is received, let the car stop.
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.