How to Program DC Motors with the Inventor Board

This lesson will go over the Motor Pins found on PINS(2~5)

First, begin the code by including the smart inventor library. Enter the following before the [crayon-62c125ae0c999230267435-i/] method.
[crayon-62c125ae0c9a1602147806/]

Learn More: What’s a library?

A library is a saved set of [crayon-62c125ae0c9a3089003998-i/]  and variables that provide users with improved functionality when coding.

Any code that starts with [crayon-62c125ae0c9a4804100688-i/]  is a function in the SmartInventor library.  Any variable that highlights ORANGE, is an initialized variable from an included library.

Learn More

Next, inside  [crayon-62c125ae0c9a6366358655-i/] ,enter the following to initialize the use of the DC motor within the sketch.
[crayon-62c125ae0c9a7964098041/]
Next, inside  [crayon-62c125ae0c9a8832517338-i/] enter the following to move the DC motor within the sketch.
[crayon-62c125ae0c9a9546191219/]

SmartInventor.DCMotorUse( )

SmartInventor.DCMotor( Name of the motor, Direction, Power);

  • Entries for the name of the motor are either [crayon-62c125ae0c9aa557146807-i/] or [crayon-62c125ae0c9ab210272449-i/] This refers to which motors you will be controlling. The pins on the smart Inventor board are paired, meaning that when M1 is called on M3 will also operate, same with M2 and M4.
  • Entries for the direction, refer to[crayon-62c125ae0c9ac062351516-i/] or [crayon-62c125ae0c9ae775738490-i/] . CW stands for Clockwise, CCW stands for Counter Clockwise, STOP will make the motor not move, and LOOSE will make the motor stall to a stop
  • Entries for power are positive numbers ranging from 1 through 100.

Lastly, input a [crayon-62c125ae0c9af191874850-i/] to assign a time step for when the motor should change.
[crayon-62c125ae0c9b0814357440/]

delay( )

delay( time in milliseconds );

[crayon-62c125ae0c9b1004074109-i/]is a function that will define how long an action should be performed. There are 1000 milliseconds in 1 second. This means that if the action should run for 3 seconds, the time entered in the [crayon-62c125ae0c9b3436239090-i/] should be 3000.
[crayon-62c125ae0c9b4755270018/]

Note: this code will only allow you to control one motor. As an activity try controlling two motors at the same time, and by inputting the CW, CCW, STOP, and LOOSE commands in the direction entry.

Final Code

[crayon-62c125ae0c9b5220306058/]