GithubHelp home page GithubHelp logo

Comments (5)

xreef avatar xreef commented on June 16, 2024

Hi alve89,
use void* pointer.
Bye Renzo

from pcf8574_library.

alve89 avatar alve89 commented on June 16, 2024

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.

from pcf8574_library.

xreef avatar xreef commented on June 16, 2024

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

from pcf8574_library.

alve89 avatar alve89 commented on June 16, 2024

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()).

from pcf8574_library.

alve89 avatar alve89 commented on June 16, 2024

I just changed the library by the following things:

  1. PCF8574.h: Adding default value for _address
  2. PCF8574.h: Adding void setAddress(uint8_t address); and void setI2CPins(uint8_t sda, uint8_t scl);
  3. PCF8574.cpp: Adding the definitions of the declarations above

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!

from pcf8574_library.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.