select pins which want to read frequency in DUE

hi
I want to use FreqMeasure library to read the frequency of 3 encoders in DUE board , how could i set for example pin 2 to measure the frequency of encoder1 and pin 3 to measure the frequency of encoder2 and pin number 4 to measure the frequency of the 3rd encoder?

for example for one encoder this code is correct :

#include <FreqMeasure.h>
int motorA1 = 4 ;
int motorA2 = 5 ;
String STR;
String inByte;
int Speed ;
void setup() {
  pinMode(motorA1 , "OUTPUT") ;
  pinMode(motorA2 , "OUTPUT") ;
  Serial.begin(9600) ;
  FreqMeasure.begin();
}
int count = 0 ;
double sum ;
void loop() {
  if (Serial.available()) {
    STR = Serial.readString() ;
    inByte = STR ;
    inByte.remove(1) ;
    String speed = STR ;
    speed.remove(0, 1);
    Speed = speed.toInt();
  }
  if (inByte == "L") {
    digitalWrite(motorA1 , LOW)  ;
    analogWrite(motorA2 , Speed)   ;
  }
  if (inByte == "R") {
    digitalWrite(motorA1 , HIGH)      ;
    analogWrite(motorA2 , 255 - Speed)  ;
  }
  //////////////////// Speed Measurement part
  if (FreqMeasure.available()) {
    sum = sum + FreqMeasure.read();
    count = count + 1 ;
    if (count > 30) {
      float frequency  = FreqMeasure.countToFrequency(sum / count) ;
      Serial.println((double) frequency / 200 * 60) ;
      sum = 0 ;
      count = 0 ;
    }
  }
}

but how can I use this code for 3 encoders?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.