Closed alve89 closed 3 years ago
Hi alve89, use void* pointer. Bye Renzo
Thanks for your very quick reply!
I just tried a bit with this but still I don't see how to store the PCF8574
object as a property in a myClass
object and "change" its address afterwards...? So my problem is the line PCF8574 myPCF;
in my first post.
If you don't want to instantiate the object you have to use a pointer. ` class myClass { public: PCF8574* getMyPCF(); void setMyPCF();
private: PCF8574* myPCF; }; `
But I think it's better if you declare first like in this example.
Bye Renzo
I understand that. The problem with only having the pointer is, that I would need to instantiate the object somewhere else (e.g. in global scope) but I don't want the user to instantiate it by himself, I want to provide an interface (get / set methods), so I thought of instantiating the object in the myClass
object and use it with the getMyPCF()
method.
The example you provided does exactly what I don't want: Declaring / defining the objects in global scope and use them in setup()
(and loop()
).
I just changed the library by the following things:
_address
void setAddress(uint8_t address);
and void setI2CPins(uint8_t sda, uint8_t scl);
If you find this helpful, feel free to use it. Beside this issue I think these changes can be helpful. If you see another way to solve this issue, I'm looking forward to your response!
PCF8574_library_emptyConstructor.zip
@xreef I just noticed an error in my code, I forgot the &Wire
line - I added it and it's working properly now!
Hey!
I'd like to use this library for an project where I need to have the PCF8574 object as a attribute / property of a class, so something like
Unfortunately something like this would throw an error because there's no "empty" constructor for the PCF8574 library available. I want to be able to set the address of the
myPCF
object afterwards. Is there a way to do that without changing the librarys code? Otherwise I could start a pull request adding something likesetAddress(uint8_t addr)
...