arduino unoでlm393スピードメーターを使用しています。そして、250 rpm モーターから 2000 rpm のような値を示します。スラムの走行距離データとして使用できますか。それは私のコードまたはエンコーダーの配置に関するものですか。20ティックエンコーダーを使用しています。私の配置は正しいです私はそれをチェックしました。
arduinoのコードは次のとおりです。
#include "TimerOne.h"
int pin1 = 4;
int pin2 = 5;
int pin3 = 6;
int pin4 = 7;
const byte MOTOR2 = 2;
const byte MOTOR2 = 3;
unsigned int counter1 = 0;
unsigned int counter2 = 0;
float diskslots = 20.00;
// Interrupt Service Routines
// Motor 1 pulse count ISR
void ISR_count1()
{
counter1++; // increment Motor 1 counter value
}
// Motor 2 pulse count ISR
void ISR_count2()
{
counter2++;
// increment Motor 2 counter value
}
void ISR_timerone()
{
Timer1.detachInterrupt(); // Stop the
Serial.print("Motor Speed 1: ");
float rotation1 = (counter1 / diskslots) *60;
Serial.print(rotation1);
Serial.print(" RPM - ");
counter1 = 0; // reset counter to zero
Serial.print("Motor Speed 2: ");
float rotation2 = (counter2 / diskslots) * 60;
Serial.print(rotation2);
Serial.println(" RPM");
counter2 = 0; // reset counter to zero
Timer1.attachInterrupt( ISR_timerone );
}
void setup() {
pinMode(pin1, OUTPUT);
pinMode(pin2, OUTPUT);
pinMode(pin3, OUTPUT);
pinMode(pin4, OUTPUT);
Timer1.initialize(1000000); // set timer for 1sec
attachInterrupt(digitalPinToInterrupt (MOTOR1), ISR_count1, RISING);
attachInterrupt(digitalPinToInterrupt (MOTOR2), ISR_count2, RISING);
Timer1.attachInterrupt( ISR_timerone );
Serial.begin(9600);
}