The Motor Driver block has the ability to drive up to 4 servo motors at the same time and control their angle of rotation from the Logic Maker. In this article, you will learn how to configure the block’s outputs from the properties panel and how to use a basic combination of gates to get your servo moving.
- Connect your Motor Driver to the WiFi and Power Station blocks:
- Connect your servo motor to one of the block’s outputs. Make sure the shiny bits in the connector are facing up as shown in the picture below:
If you want to learn more about the pin configuration, please read our Pin Distribution article.
- Add the Motor Driver into the canvas by clicking on the menu icon:
- From the block’s Properties Panel, click on to ‘Custom Settings’ and locate the ‘Motors Configuration’ section, from here you can define the operation mode of each of the 4 outputs. Keep in mind that the labels on the left (Motor-X) refer to the numbers on top of the physical Motor Driver block. So, if you connected your servo to output 3, make sure that from the dropdown button corresponding to that output you select ‘Servo’. Once you change the correct output, press ‘Save’.
- Go to the Motor Driver’s Logic Maker, add and connect the following gates:
Play -> Value -> Action
- From the ‘Action’ gate’s list, select ‘M3:RotateToAngle’ (note that if you connected your servo to a different port, the action name should be that of the chosen output) and click on ‘Apply’ to save your changes. Press the ‘Play’ gate button, the servo motor should move to the angle indicated by the 'Value' gate. You can try changing this value from 0 to 180, to see how to servo moves, making sure you press ‘Apply’ every time you modify the value.
You could also create a program to make the motor rotate between 2 states by the press of a button. For this, add the following as shown in the picture below:
How Does It Work?
When you press the ‘Play’ gate, it produces an event that is then sent to the ‘Toggle’ gate, making its internal state change from true to false and vice versa. The ‘IF’ gate receives this value and compares it with its predefined condition, if the values match, then it triggers the gates connected to its ‘then’ output, if not, it triggers the gates connected to its ‘else’ output. Depending on the output, the event then pushes the value to the ‘Action’ gate forcing the servo to rotate to the specified angle.
You could alternatively automate the ‘pressing’ of the button by adding a clock gate:
Remember that you can also trigger your logic from any other Virtual or Hardware Block!