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-6622c9215276f152489998-i/] method.
[crayon-6622c92152776996747788/]

Learn More: What’s a library?

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

Any code that starts with [crayon-6622c92152779951600343-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-6622c9215277b753286083-i/] ,enter the following to initialize the use of the DC motor within the sketch.
[crayon-6622c9215277c509923965/]
Next, inside  [crayon-6622c9215277d999548867-i/] enter the following to move the DC motor within the sketch.
[crayon-6622c9215277e022429078/]

SmartInventor.DCMotorUse( )

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

  • Entries for the name of the motor are either [crayon-6622c9215277f588752116-i/] or [crayon-6622c92152780106672384-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-6622c92152781717386576-i/] or [crayon-6622c92152783999188467-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-6622c92152785793697567-i/] to assign a time step for when the motor should change.
[crayon-6622c92152786368801101/]

delay( )

delay( time in milliseconds );

[crayon-6622c92152787508460160-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-6622c92152788393575115-i/] should be 3000.
[crayon-6622c92152789280617872/]

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-6622c9215278b200632218/]