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-666c817849dc7798986894-i/] method.

Learn More: What’s a library?

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

Any code that starts with [crayon-666c817849dd1395709745-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-666c817849dd4518114152-i/] ,enter the following to initialize the use of the DC motor within the sketch.
Next, inside  [crayon-666c817849dd6206520271-i/] enter the following to move the DC motor within the sketch.

SmartInventor.DCMotorUse( )

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

  • Entries for the name of the motor are either [crayon-666c817849dd8358364626-i/] or [crayon-666c817849dd9387876843-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-666c817849dda104001124-i/] or [crayon-666c817849ddd221949540-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-666c817849dde050136432-i/] to assign a time step for when the motor should change.

delay( )

delay( time in milliseconds );

[crayon-666c817849de1970169509-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-666c817849de3503745200-i/] should be 3000.

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