read()
説明
カウンターの数値或いはパルス幅変調の読込み。フィードバック数値により、意味が違いますので、以下の説明を見て下さい。
語法
Enc0.read()
Enc1.read()
Enc2.read()
Enc3.read()
変数
Enc0、Enc1、Enc2、Enc3
:ENC0、ENC1、ENC2、ENC3のコーディング インターフェースにマッピングします。
フィードバック
Pulse/DIR、CW/CCW、A/B Pulse モード:カウンターからの数値フィードバックします。
PWMモード:パスルLOW 或いはHIGH 幅の数値をカウンターします(単位:μs、測定可能最大時間は71分)。
注意:read()はISRライブラリにしか使えないです。
SSI モード:SSIカウンターからの数値をフィードバックします。
例
ENC0をA/B Pulseモードに設定して、カウンター数値を読込みします。
#include <Encoder.h> void setup() { Serial.begin(9600); Enc0.begin(MODE_AB_PHASE); } void loop() { Serial.println(Enc0.read());// // カウンター数値を読込みする delay(100); }
// カウンター数値を読込みする
#include <Encoder.h> volatile unsigned long num1 = 0L; volatile unsigned long num2 = 0L; void encoder_isr(int flag) { // ISRライブラリ if (flag == INTR_A_PULSE_LOW)// パスルLOWの幅を読込みする num1 = Enc1.read(); else if (flag == INTR_A_PULSE_HIGH) // パスルのHIGH幅を読込みする num2 = Enc1.read(); } void setup() { Serial.begin(9600); Enc1.begin(MODE_CAPTURE); Enc1.attachInterrupt(encoder_isr);// ISRライブラリをマウントして、中断機能を起動する } void loop() { Serial.print("LOW:"); Serial.print(num1); // パスルLOWの幅(単位:μs)をプリントアウトする Serial.print(" "); Serial.print("HIGH:"); Serial.println(num2); //パスルHIGHの幅(単位:μs)をプリントアウトする delay(100); }
See also
- attachInterrupt()
The text of the 86Duino reference is licensed under a Creative Commons Attribution-ShareAlike 3.0 License. Code samples in the reference are released into the public domain.