Lego® EV3 with Scratch - Flight simulatror game #1

EV3 motor as a sensor in Sratch? It's possible beccouse Scratch implements variable "motor position".

When we set the motor in a specific position and connect it to the EV3 brick, this variable will be 0. Since this moment, the movement of the motor will change the variable "motor position" from 0 to 360.

Using this variable, we can control the sprite by the motor. The steering wheel moves to the right around 45 degrees. To simplify the calculations, let's take 48 degrees (from 0 to 48). The range of the movement to the left is from 360 to 312.

Now we have to convert it into steps in Scratch (from -240 to 240):
- right from 0 to 240  ->  5 * MotorAPosition
- left from 0 to -240   ->  5 * (MotorAPosition - 360)

If the MotorAPosition < 180 you're turning right else you're turning left.

 

EV3 with Scratch - flight simulatror - rocket program
EV3 with Scratch - flight simulatror - star 1 program
EV3 with Scratch - flight simulatror - star 2 program