|
|
@@ -4,9 +4,52 @@ void ROTTARY_SW_sw_INT() {
|
|
|
Serial.println("ROTTARY_SW_sw_INT TRIG");
|
|
|
}
|
|
|
|
|
|
+/*
|
|
|
void ROTTARY_SW_dt_INT() {
|
|
|
Serial.println("ROTTARY_SW_dt_INT TRIG");
|
|
|
}
|
|
|
void ROTTARY_SW_clk_INT() {
|
|
|
Serial.println("ROTTARY_SW_clk_INT TRIG");
|
|
|
}
|
|
|
+*/
|
|
|
+
|
|
|
+void ROTTARY_SW_dt_INT() {
|
|
|
+ cli(); //stop interrupts happening before we read pin values
|
|
|
+ reading1 = digitalRead(ROTTARY_SW_clk) ;
|
|
|
+ reading2 = digitalRead(ROTTARY_SW_dt);
|
|
|
+ //reading = PIND & 0xC; //read all eight pin values then strip away all but pinA and pinB's values
|
|
|
+ if (reading1 == 1 and reading1 == 1 and aFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
|
|
|
+ encoderPos --; //increment the encoder's position count
|
|
|
+ bFlag = 0; //reset flags for the next turn
|
|
|
+ aFlag = 0; //reset flags for the next turn
|
|
|
+
|
|
|
+ } else if (reading1 == 0 and reading2 == 1) {
|
|
|
+ aFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation
|
|
|
+ }
|
|
|
+ sei(); //restart interrupts
|
|
|
+ Serial.print("dt_: #["); Serial.print(encoderPos); Serial.print("] R1["); Serial.print(reading1); Serial.print("] R2["); Serial.print(reading2); Serial.print("] aFlag["); Serial.print(aFlag); Serial.print("] bFlag["); Serial.print(bFlag);
|
|
|
+ Serial.println("] ");
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+void ROTTARY_SW_clk_INT(){
|
|
|
+ cli(); //stop interrupts happening before we read pin values
|
|
|
+ reading1 = digitalRead(ROTTARY_SW_clk) ;
|
|
|
+ reading2 = digitalRead(ROTTARY_SW_dt);
|
|
|
+ //reading = PIND & 0xC; //read all eight pin values then strip away all but pinA and pinB's values
|
|
|
+ if (reading1 == 1 and reading2 == 1 && bFlag) { //check that we have both pins at detent (HIGH) and that we are expecting detent on this pin's rising edge
|
|
|
+ encoderPos ++; //increment the encoder's position count
|
|
|
+ bFlag = 0; //reset flags for the next turn
|
|
|
+ aFlag = 0; //reset flags for the next turn
|
|
|
+
|
|
|
+ // Serial.print("clkA: #["); Serial.print(encoderPos); Serial.print("] R1["); Serial.print(reading1); Serial.print("] R2["); Serial.print(reading2); Serial.print("] AFlag["); Serial.print(aFlag); Serial.print("] bFlag["); Serial.print(bFlag); Serial.println("] ");
|
|
|
+
|
|
|
+ } else if (reading1 == 1 ) {
|
|
|
+ aFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation
|
|
|
+ }
|
|
|
+
|
|
|
+ Serial.print("clkA: #["); Serial.print(encoderPos); Serial.print("] R1["); Serial.print(reading1); Serial.print("] R2["); Serial.print(reading2); Serial.print("] AFlag["); Serial.print(aFlag); Serial.print("] bFlag["); Serial.print(bFlag);
|
|
|
+ Serial.println("] ");
|
|
|
+ sei(); //restart interrupts
|
|
|
+}
|
|
|
+
|