getEncoderPeriod()


Description

This function gets the period of an encoder's output.

Syntax

dcmotor.getEncoderPeriod()

Parameters

none

Returns

the period of an encoder's output in microsecond unit

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.setEncoderPSR(64);
    dcmotor.setPeriod(10000);
    dcmotor.setWidth(width);
}

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

        Serial.print(width);
        Serial.print("=>");

        // get the period of an encoder's output
        Serial.println(dcmotor.getEncoderPeriod());
    }
    else
        dcmotor.setWidth(0);
}