Use parts: Let's move the motor

Let's connect the components to obniz and run it as a block program.

This time, we will connect a small DC motor. This is a motor that rotates when electricity is applied, and is often used in toys.


In the case of obniz, you can connect it anywhere on the io, but this time we will connect it to pins 0 and 1.

Now, if you apply current to 0 and 1 of obniz, the motor will turn.

Motor block

Since the DC motor is prepared as a block, the block program will use it.

In the "Moving" category, there is a "DCMotor".This will be the block for the motor.

Let's use it right away.


Here is the program that was completed earlier.

This time the challenge is to make the motor turn only while the button is pressed on the screen where the program is running.

First, we need to set up where the motors are connected so that we can use them.
This is done after connecting to obniz and displaying the button on the screen.

There are forward:0, back:1.This means that you have connected the two wires of the motor to 0 and 1.

Then, in a loop, check to see if the button on the screen is pressed repeatedly.
If the button is pressed, the "rotate dcmotor to forward" block will be executed, so the command to turn the motor will reach obniz and the motor will turn.
On the other hand, if it is not being pushed, it will try to stop the motor.

This is what it will look like when you run it.