Open OrionCul opened 4 years ago
There are two main approaches you could take:
digitalWrite
etc. to SX1509 pins. When you do this, you can use pretty much all parts of the library using pins from your IO expander. This is how the library deals with multiplexed pins and pins of shift registers.The first option is a quick solution if you know some C++, and the end result will have less overhead, but at a cost of having to copy/adapt some parts of the library to make them work with your custom IO functions.
The second option just requires you to implement a couple of virtual functions (digitalWrite
, digitalRead
, pinMode
, etc.), and from then on, you can just use the library as usual.
For option one, if I were to implement the button matrix, how would I get it to work with the control surface's library to send out MIDI signals? Or would I have to do that myself?
For option two, would I have to implement all of the virtual functions in that class? Also, where would I implement them so that the whole library uses my defined functions instead?
You can use Control_Surface.sendCC(address, value)
and the other similar functions.
You have to provide an implementation for all pure virtual functions, but you can just leave them empty if you don't need them.
You don't have to define them in a specific place. Just create a class for the expander that inherits from ExtendedIOElement
and override its methods. Then create an instance of your class, and use yourInstance.pin(n)
to pass its pins to other parts of the library.
I have a button matrix set up and when a button is pressed, I want to light up a corresponding LED. I've seen numerous ways of doing this in the library, but the issue I'm having is that I'm using an SX1509 I/O expander so I can't use the NoteToLed library or anything. I was wondering if it's possible to define in the arduino file what happens when a button is pressed. For example, something like this possibly: