旋轉編碼器 KY-40

旋轉編碼器KY-040是一個旋轉輸入裝置,與旋鈕一樣,可以顯示出旋鈕的旋轉量和旋轉方向。它是步進馬達和伺服馬達控制的常用配件,也可以用它來控制數碼電位計等設備。

HK$15.00

- +
貨號: rotary-encoder-ky-040 分類:

.3D模型:

 

.商品簡介:
旋轉編碼器KY-040是一個旋轉輸入裝置,與旋鈕一樣,可以顯示出旋鈕的旋轉量和旋轉方向。它是步進馬達和伺服馬達控制的常用配件,也可以用它來控制數碼電位計等設備。

 

.主要用途:
提供一個旋轉輸入裝置,控制步進馬達和伺服馬達

 

.商品規格:
尺寸:22*24*24mm
重量:3g
電壓:5V
品牌:Keyes
型號:KY-040

 

.商品包含:
1 x 旋轉編碼器

 

.示範短片:

.程式範例:

#define outputA 6 #define outputB 7 int counter = 0; int aState; int aLastState; void setup() { pinMode (outputA,INPUT); pinMode (outputB,INPUT); Serial.begin (9600); // Reads the initial state of the outputA aLastState = digitalRead(outputA); } void loop() { aState = digitalRead(outputA); // Reads the "current" state of the outputA // If the previous and the current state of the outputA are different, that means a Pulse has occured if (aState != aLastState){ // If the outputB state is different to the outputA state, that means the encoder is rotating clockwise if (digitalRead(outputB) != aState) { counter ++; } else { counter --; } Serial.print("Position: "); Serial.println(counter); } aLastState = aState; // Updates the previous state of the outputA with the current state }

購物車