상품명 | [0225] XD-88 360도 회전 인코더 모듈 |
---|---|
판매가 | 900원 |
상품요약정보 | [0225] XD-88 360도 회전 인코더 모듈 |
배송방법 | 택배 |
배송비 | 3,000원 (70,000원 이상 구매 시 무료) |
수량 |
SNS 상품홍보 | |
---|
(최소주문수량 1개 이상 / 최대주문수량 0개 이하)
사이즈 가이드할인가가 적용된 최종 결제예정금액은 주문 시 확인할 수 있습니다.
[0225] XD-88 360도 회전 인코더 모듈
특징
작동 전압: 5V
회전 펄스 수: 20
테스트 코드:
int redPin = 2;
int yellowPin = 3;
int greenPin = 4;
int aPin = 6;
int bPin = 7;
int buttonPin = 5;
int state = 0;
int longPeriod = 5000; Time at green or red
int shortPeriod = 700; Time period when changing
int targetCount = shortPeriod;
int count = 0;
void setup()
{
pinMode(aPin, INPUT);
pinMode(bPin, INPUT);
pinMode(buttonPin, INPUT);
pinMode(redPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(greenPin, OUTPUT);
}
void loop()
{
count++;
if (digitalRead(buttonPin))
{
setLights(HIGH, HIGH, HIGH);
}
else
{
int change = getEncoderTurn();
int newPeriod = longPeriod + (change * 1000);
if (newPeriod >= 1000 && newPeriod <= 10000)
{
longPeriod = newPeriod;
}
if (count > targetCount)
{
setState();
count = 0;
}
}
delay(1);
}
int getEncoderTurn()
{
return -1, 0, or +1
static int oldA = LOW;
static int oldB = LOW;
int result = 0;
int newA = digitalRead(aPin);
int newB = digitalRead(bPin);
if (newA != oldA newB != oldB)
{
something has changed
if (oldA == LOW && newA == HIGH)
{
result = -(oldB * 2 - 1);
}
}
oldA = newA;
oldB = newB;
return result;
}
int setState()
{
if (state == 0)
{
setLights(HIGH, LOW, LOW);
targetCount = longPeriod;
state = 1;
}
else if (state == 1)
{
setLights(HIGH, HIGH, LOW);
targetCount = shortPeriod;
state = 2;
}
else if (state == 2)
{
setLights(LOW, LOW, HIGH);
targetCount = longPeriod;
state = 3;
}
else if (state == 3)
{
setLights(LOW, HIGH, LOW);
targetCount = shortPeriod;
state = 0;
}
}
void setLights(int red, int yellow, int green)
{
digitalWrite(redPin, red);
digitalWrite(yellowPin, yellow);
digitalWrite(greenPin, green);
}
상품의 사용후기를 적어주세요.
게시물이 없습니다
상품에 대해 궁금한 점을 해결해 드립니다.
게시물이 없습니다