Using I2C Digital Input Modul in combination with onebutton lib

Hello together,

I started to work with Arduino couple weeks ago. I already created my first working sketch, which should control my blinds at home. For this I use the onebutton lib to support different commands depending of shortpress, double click or longpress. Right now my code is working as expected. I am little bit proud :)

My next step is to read out the button information with a Digital Input Modul (buttons with 24V), which is connected to my arduino via I2C.

My problem is, onebutton.cpp is only working with Arduino pins. :(

Is it a good idea to rework the onebutton.cpp in that way, that I hand over the relevant bit to the lib instead of "int pin"?

OneButton::OneButton(int pin, int activeLow)

activeLow should be also not necessary anymore, right?

Also pinMode not necessary: * // use the given pin as input* * pinMode(pin, INPUT);*

  • // Detect the input information*
  • int buttonLevel = digitalRead(_pin); // current button signal.*

Instead of digitalRead --> bitRead

Right now I am not sure, if changing the existing lib is a good solution for my application. Hope you could help me to find a working solution.

Thanks

My problem is, onebutton.cpp is only working with Arduino pins.

I fail to see why that is a problem. Which other pins did you (unrealistically) expect it to work with?

Is it a good idea to rework the onebutton.cpp in that way, that I hand over the relevant bit to the lib instead of "int pin"?

What "relevant bit"?

As I already wrote, I want to change the lib to be able to read information from my I2C Modules. This modul has 8 Inputs, this mean the arduino get 1Byte from the Input modul. Each Bit represent an Input. So for this I want to change the int pin of the onebutton lib to this bit.

So for this I want to change the int pin of the onebutton lib to this bit.

You are going to have to do far more than that. Look at the code for the library. Look at what it does with the pin number. See a digitalRead() on that pin? I'll bet you do.

You can't meaningfully digitalRead() from your I2C device.

PaulS: You can't meaningfully digitalRead() from your I2C device.

Thats right, that for I want replace digitalRead() with bitRead().

Instead int pin I want to handover the relevant Bit (which comes from I2C Module)

Solved. OneButton lib was expanded for generic support v1.3.0.