Rotary encoder for tda7439

Hi.
I have a challange, i been solving a lot of problems with my project,
and now i need to intergrate a rotary encoder with pushbutton like
sparkfuns, with 4 step.
i have a working ino file, thats seems greit, but I using a sketch with
a different kind of encoder so I need to replace the codes for the encoder.

Is there someone there who can ?
best regards
Niklas.

I have made a circuit board with the encoder attached to pin 2 and 3, with common to ground,
Also have pushbutton to pin 4 and ground.

/*
(Copy and paste)

Rotary encoder decoding using two interrupt lines.
Most Arduino boards have two external interrupts,
numbers 0 (on digital pin 2) and 1 (on digital pin 3).

Program sketch is for SparkFun Rotary Encoder sku: COM-09117
Connect the middle pin of the three to ground.
The outside two pins of the three are connected to
digital pins 2 and 3
*/


volatile int number = 0;                // Testnumber, print it when it changes value,
                                        // used in loop and both interrupt routines
int oldnumber = number;

volatile boolean halfleft = false;      // Used in both interrupt routines
volatile boolean halfright = false;


void setup(){
  Serial.begin(9600);
  pinMode(2, INPUT);
  digitalWrite(2, HIGH);                // Turn on internal pullup resistor
  pinMode(3, INPUT);
  digitalWrite(3, HIGH);                // Turn on internal pullup resistor
  attachInterrupt(0, isr_2, FALLING);   // Call isr_2 when digital pin 2 goes LOW
  attachInterrupt(1, isr_3, FALLING);   // Call isr_3 when digital pin 3 goes LOW
}

void loop(){
  if(number != oldnumber){              // Change in value ?
    Serial.println(number);             // Yes, print it (or whatever)
    oldnumber = number;
  }
}

void isr_2(){                                              // Pin2 went LOW
  delay(1);                                                // Debounce time
  if(digitalRead(2) == LOW){                               // Pin2 still LOW ?
    if(digitalRead(3) == HIGH && halfright == false){      // -->
      halfright = true;                                    // One half click clockwise
    }  
    if(digitalRead(3) == LOW && halfleft == true){         // <--
      halfleft = false;                                    // One whole click counter-
      number--;                                            // clockwise
    }
  }
}
void isr_3(){                                             // Pin3 went LOW
  delay(1);                                               // Debounce time
  if(digitalRead(3) == LOW){                              // Pin3 still LOW ?
    if(digitalRead(2) == HIGH && halfleft == false){      // <--
      halfleft = true;                                    // One half  click counter-
    }                                                     // clockwise
    if(digitalRead(2) == LOW && halfright == true){       // -->
      halfright = false;                                  // One whole click clockwise
      number++;
    }
  }
}

that works,
but need to be in the attached file I put under , I put a sample here under .

//Encoder related
volatile byte enc=0;  // flags for the interrupt routine

//Used for reducing the resolution of the encoder
volatile byte encDownCount=0;
volatile byte encUpCount=0;
#define encResDivider 100

and 

pinMode(2, INPUT);       // Encoder pin
    digitalWrite(2, HIGH);   // Enable pull-up resistor

    pinMode(3, INPUT);     // Encoder pin
    digitalWrite(3, HIGH); // Enable pull-up resistor
    
    pinMode(powerButton, INPUT); //Set buttons as inputs
    pinMode(menuButton, INPUT);
    
    digitalWrite(powerButton, HIGH); //Enable internal pullups
    digitalWrite(menuButton, HIGH);
    
    pinMode(fan, OUTPUT);
    digitalWrite(fan, 0);
    
    pinMode(powerRelay, OUTPUT);
    digitalWrite(powerRelay, 0);
    
    pinMode(offPowerLED, OUTPUT);
    digitalWrite(offPowerLED, HIGH);
    
    pinMode(onPowerLED, OUTPUT);
    digitalWrite(onPowerLED, HIGH);

NikArduino_Gainclone_1_3.ino (19.5 KB)