setDirection()


Description

This function sets the direction of rotation.

Syntax

dcmotor.setDirection(dir)

Parameters

dir - a integer value which represents the direction of rotation

dir direction
0 or greater than 0 forward (default)
otherwise reverse

Returns

none

Example

#include <PhpocExpansion.h>
#include <Phpoc.h>

byte spcId = 1;

ExpansionDCMotor dcmotor(spcId, 1);

int width = 3000;

void setup() {
    Serial.begin(9600);
    while(!Serial)
    ;

    Phpoc.begin(PF_LOG_SPI | PF_LOG_NET);
    Expansion.begin();

    Serial.println(dcmotor.getPID());
    Serial.println(dcmotor.getName());

    dcmotor.setPolarity(1);

    // set the direction of rotation
    dcmotor.setDirection(1);
    dcmotor.setPeriod(10000);
    dcmotor.setWidth(width);
}

void loop() {
    if(width > 0) {
        width -= 100;
        dcmotor.setWidth(width);
        delay(100);
    }
}