// You can assign any number of functions to different pins. How cool is that? 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 if(encoderPos == ARDUINO_SIZE_MIN_encoderPos) { } else { 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) { bFlag = 1; //signal that we're expecting pinA to signal the transition to detent from free rotation } sei(); //restart interrupts #ifdef DEBUG if(DEBUG > 4) { 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("] "); } #endif } 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 if(encoderPos == ARDUINO_SIZE_MAX_encoderPos) { } else { 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 } #ifdef DEBUG if(DEBUG > 4) { 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("] "); } #endif sei(); //restart interrupts }