ClickEncoder Library Button to I2C?

I’m using the ClickEncoder Libary - but just for the nicely done button!

Here is an example how to adress a button:

#include <ClickEncoder.h>
#include <TimerOne.h>
#define opt_button 7
ClickEncoder *opt_btn;

void setup(){
opt_btn = new ClickEncoder(97, 96, opt_button, 2, HIGH); // avoids linking in heap library
Timer1.initialize(1000);
Timer1.attachInterrupt(timerIsr);

}


void timerIsr() {
  //Encoder Library neccesarry function
  opt_btn->service();
  mode_btn->service();
  }


void loop()
{

  checkOptBtn();

}



void checkOptBtn(){
  ClickEncoder::Button c = opt_btn->getButton();
  switch (c) {
    case ClickEncoder::Held:
      opt_hold = true;
      break;
    case ClickEncoder::DoubleClicked:
      break;
    case ClickEncoder::Clicked:
      break;
    case ClickEncoder::Released:
      opt_hold = false;
      break;
  }
}

So this gives me a nice button feature with click,double clicked, held, released and also pressed can be found.

Now my problem is, that i run out of pins on ATMEGA328. So i need a I2C Expander anyway (MCP23017). I would like to remove the Buttons from the ATMEGA, since i need the pins of it for other things like software serial and stuff.

So i want to ask kindly if someone would look at the attached library and could tell me if it would be possible to modify the library.

  1. I would need to have the orginal function, but with an I2C Input from the MCP23017
  2. If anyhow possible, i need just the stuff that deals with the buttons. The Encoder is unused in my application

Any help is welcome! :slight_smile:

ClickEncoder.cpp (7.86 KB)

ClickEncoder.h (4.24 KB)