Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Setting pin mode in constructor does not work #24

Open
goodlyduck opened this issue Nov 25, 2023 · 2 comments
Open

Setting pin mode in constructor does not work #24

goodlyduck opened this issue Nov 25, 2023 · 2 comments

Comments

@goodlyduck
Copy link

Hi there

On my Arduino Nano ESP32, I had to also set pinMode to OUTPUT in my setup function, it does not seem to work to set them in the SwitecX25 constructor only. Perhaps add a setup() function that can do this later in runtime? I head that interfacing with hardware might be a bad idea in a constructor.

/Martin

@guyc
Copy link
Collaborator

guyc commented Nov 27, 2023

Interesting, that's something I haven't run into before. Any idea what the underlying cause is?

It sounds like pin modes are being reset after static initialisation? does it work if you run the initialiser
within the setup loop, like this?

SwitecX25 *motor1;

void setup(void) {
  motor1 = new SwitecX25(315*3, 4, 5, 6, 7);
  ...

@goodlyduck
Copy link
Author

Thanks for your reply, I'm not sure what's causing this issue. It works if I do it like your proposal. The only difference then is that I have to use ->, i.e. motor1->zero() instead of motor1.zero().

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants