50 lines
883 B
C++
50 lines
883 B
C++
#define outputA 2
|
|
#define outputB 3
|
|
#define buttonPin 8
|
|
|
|
int counter = 0;
|
|
int aState;
|
|
int aLastState;
|
|
int buttonState;
|
|
int lastButtonState;
|
|
|
|
void setup() {
|
|
// put your setup code here, to run once:
|
|
pinMode(outputA, INPUT);
|
|
pinMode(outputB, INPUT);
|
|
pinMode(buttonPin, INPUT_PULLUP);
|
|
|
|
Serial.begin(9600);
|
|
aLastState = digitalRead(outputA);
|
|
|
|
}
|
|
|
|
void loop() {
|
|
// put your main code here, to run repeatedly:
|
|
|
|
buttonState = digitalRead(buttonPin);
|
|
|
|
aState = digitalRead(outputA);
|
|
|
|
if (aState != aLastState) {
|
|
if(digitalRead(outputB) != aState) {
|
|
counter++;
|
|
} else {
|
|
counter--;
|
|
}
|
|
Serial.print("Position: ");
|
|
Serial.println(counter);
|
|
}
|
|
|
|
if (!buttonState && buttonState != lastButtonState) {
|
|
counter /= 2;
|
|
Serial.print("Position: ");
|
|
Serial.println(counter);
|
|
}
|
|
|
|
|
|
lastButtonState = buttonState;
|
|
aLastState = aState;
|
|
|
|
}
|