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

Multiple encoders #21

Open
Gandrasg opened this issue Dec 21, 2020 · 3 comments
Open

Multiple encoders #21

Gandrasg opened this issue Dec 21, 2020 · 3 comments

Comments

@Gandrasg
Copy link

Hi!
Can you help? I don't fully understand how to assign tasks by ID for multiple encoders.
If I use multiple encoders, how do I request information for a particular encoder? How can I associate behavior with an ID. For example: If the encoder ID is X, do you do it, and if the encoder ID is Y, do you do it?

void encoder_rotated(i2cEncoderLibV2* obj) {
  if (obj->readStatus(i2cEncoderLibV2::RINC))
    Serial.print("Increment ");
  else
    Serial.print("Decrement ");
  Serial.print(obj->id);
  Serial.print(": ");
  Serial.println(obj->readCounterInt());
  "if the ID = 0" writeRGBCode(0x0000FF);
  "if the ID = 1" writeRGBCode(0x00FF00);
}

Thanks in advance.

@Gandrasg
Copy link
Author

If I understand correctly, is obj -> "function" what points to and identifies the encoder ID in a given function? How can I reference the ID of this function in a for loop? (Encoder.id == 1).
I'm not a programmer, I have minimal knowledge of c ++, I'm just trying to understand the code.
Sorry for the silly questions.

@Fattoresaimon
Copy link
Owner

Hello,
the "i2cEncoderLibV2* obj" is just a pointer to a class. And you can access to the member to the class with the operator "->".
It's like if the class is a " box " with inside some function, variable etc... the obj is a pointer to that box and you can see inside with the operator "->".
That box are defined here:
i2cEncoderLibV2 RGBEncoder[ENCODER_N] = { i2cEncoderLibV2(0x40), i2cEncoderLibV2(0x20), i2cEncoderLibV2(0x60), i2cEncoderLibV2(0x10), i2cEncoderLibV2(0x50), i2cEncoderLibV2(0x30), i2cEncoderLibV2(0x70), i2cEncoderLibV2(0x04), i2cEncoderLibV2(0x44), };
Where ENCODER_N it's 9, so in that case i have defined 9 time the i2cEncoderLibV2 calss.

@Gandrasg
Copy link
Author

Gandrasg commented Jan 3, 2021

Thanks!
Happy New Year!
Meanwhile...I’ve noticed on the encoders that as the number of IDs increases, I reach the maximum for more and more rotations.
Four encoders line up, the fourth causes much more rotation and triggers the same change as the first. Do you have any idea what could be causing this? There is only one SJ8 soldered in the queue and I turned off IPUP in the code.

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