Rotary encoder module for arduino KY-040
สั่งสินค้าสามารถพิมพ์ใน email ว่าต้องการอย่างละกี่ชิ้นชื่อสินค้าอะไรบ้าง
แล้วส่งมาที่ circuitshops@hotmail.com
แล้วจะมีคนตอบ email แจ้งราคาพร้อมค่าจัดส่งไปให้ครับ
..
Description:
100% brand new and high quality
Type: Power module
Model: KY-040 FOR ARDUINO Arduino module
Operating voltage: 5V
Number of pulses: 20
The rotary encoder can count the number of pulses output in the forward and reverse directions by rotation, and the rotation count is not like the potentiometer. This rotation count is not limited. With the key on the rotary encoder, you can reset to the initial state, that is, counting from 0.
ราคา 90 บาท
******************
ARDUINO test code:
const int interruptA = 0; / / Interrupt 0 (pin 2)
const int interruptB = 1; / / Interrupt 1 (pin 3)
int CLK = 2; / / PIN2
int DAT = 3; / / PIN3
int BUTTON = 4; / / PIN4
int LED1 = 5; / / PIN5
int LED2 = 6; / / PIN6
int COUNT = 0;
void setup ()
{
attachInterrupt (interruptA, RoteStateChanged, FALLING);
/ / AttachInterrupt (interruptB, buttonState, FALLING);
pinMode (CLK, INPUT);
digitalWrite (2, HIGH); / / Pull High Restance
pinMode (DAT, INPUT);
digitalWrite (3, HIGH); / / Pull High Restance
pinMode (BUTTON, INPUT);
digitalWrite (4, HIGH); / / Pull High Restance
pinMode (LED1, OUTPUT);
pinMode (LED2, OUTPUT);
Serial.begin (9600);
}
void loop ()
{
if (! (digitalRead (BUTTON)))
{
COUNT = 0;
Serial.println ("STOP COUNT = 0");
digitalWrite (LED1, LOW);
digitalWrite (LED2, LOW);
delay (2000);
}
Serial.println (COUNT);
}
/ / -------------------------------------------
void RoteStateChanged () / / When CLK FALLING READ DAT
{
if (digitalRead (DAT)) / / When DAT = HIGH IS FORWARD
{
COUNT;
digitalWrite (LED1, HIGH);
digitalWrite (LED2, LOW);
delay (20);
}
else / / When DAT = LOW IS BackRote
{
COUNT -;
digitalWrite (LED2, HIGH);
digitalWrite (LED1, LOW);
delay (20);
}
}