로터리 인코더 모듈 -손잡이, 나선 너트, 회전당 20펄스
(Rotary Encoder Module with Knob, Thread Nut - 20 PPR)
개요
- 본 제품은 로터리 인코더 모듈 -손잡이, 나선 너트, 회전당 20펄스입니다.
- 나선을 가진 로터리로 너트와 손잡이 노브가 포함되어 있는 제품입니다.
- 한 회전당 20 펄스를 출력합니다.
- 로터리 모듈에는 10K 풀업저항이 장착되어 있어 외부 풀업저항이 필요가 없습니다.
- SW핀은 스위치 핀으로 GND에 연결되어 있으며, 샤프트를 누를시 동작합니다.
특징
- Working voltage: 5V
- Pulses per rotation: 20
- Pinout
1...GND
2...+5V supply
3...SW connects pin to GND whebn shaft is pressed
4...DT direction pulse. Pin has 10K pullup connected to supply.
5...CLK clock pulse. Pin has 10K pullup connected to supply.
문서
- 아두이노 코드
-
/* Define digital pins used to read the encoder */
#define DT 2
#define CLK 3
#define SW 4
void setup()
{
Serial.begin(9600);
pinMode(DT, INPUT);
pinMode(CLK, INPUT);
pinMode(SW, INPUT);
digitalWrite(SW, HIGH);
}
/* Main program */
void loop()
{
int counter;
byte DialPos;
byte Last_DialPos;
/* Reset the counter */
counter = 0;
/* Continiouously read the state of the encoder */
while(1)
{
/* Read the status of the dial */
DialPos = (digitalRead(CLK) << 1) | digitalRead(DT);
/* Is the dial being turned anti-clockwise? */
if (DialPos == 3 && Last_DialPos == 1)
{
counter--;
}
/* Is the dial being turned clockwise? */
if (DialPos == 3 && Last_DialPos == 2)
{
counter++;
}
/* Output the counter to the serial port */
Serial.println(counter);
/* Is the switch pressed? */
if(!digitalRead(SW))
Serial.println("Switch pressed!");
/* Save the state of the encoder */
Last_DialPos = DialPos;
}
}
연관제품
- 연관제품 1