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


void timerIsr() {
  //Encoder Library neccesarry function

void loop()



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

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)