This forum is read only and new users cannot register, please ask all new questions either using GitHub discussions, or in Arduino forum tagging @davetcc.
I'm fairly new to this library, browsing through your examples.
I'm using an Adafruit Thumbstick (https://www.adafruit.com/product/512) which supports two axes. I've wired that part to A8 and A9 on an Arduino Due.
My nonworking sketch so far: (btw, there some more parts assigned to that due).
I assume that I have to add another encoder somwhow, instead of another ArduinoAnalogDevice abstraction... hmmm
See the section on using multiple encoders titled ‘Advanced usage of rotary encoders’.
Let me know if you still need a bit more detail and I’ll write it up later today in the documentation.
Hmm, still stuck with adding a 2nd joystick encoder... i guess that's possibly a problem with my overall knowledge of c++
Normally I would add 2 object references pointing at encoder 0 and 1 (encoder 0..3 should be possible afaik)
As it seems, I have to use interrupts when using 2 encoders. This might be problematic with analog joystick pins, so could you please
add one or two example lines for joystick encoders, how to initialize such objects, that would be great!
davetcc Joined: Jan 19, 2019 Messages: 686 Offline
If we look at the below function copied out of JoystickSwitchInput.h
auto joystickEncoder = new JoystickSwitchInput(analogDevice, analogPin, callback);
switches.setEncoder(joystickEncoder);
taskManager.scheduleOnce(250, joystickEncoder);
Then we can see that each encoder does not need an interrupt; instead, they need to be scheduled by task manager.
Can you try something along the lines of:
auto joystickEncoder = new JoystickSwitchInput(analogDevice, analogPin, callback);
switches.setEncoder(0, joystickEncoder);
taskManager.scheduleOnce(250, joystickEncoder);
auto joystickEncoder2 = new JoystickSwitchInput(analogDevice, analogPin2, callback2);
switches.setEncoder(1, joystickEncoder2);
taskManager.scheduleOnce(250, joystickEncoder2);
// your other initialisation
davetcc wrote:If we look at the below function copied out of JoystickSwitchInput.h
auto joystickEncoder = new JoystickSwitchInput(analogDevice, analogPin, callback);
switches.setEncoder(joystickEncoder);
taskManager.scheduleOnce(250, joystickEncoder);
Then we can see that each encoder does not need an interrupt; instead, they need to be scheduled by task manager.
Can you try something along the lines of:
auto joystickEncoder = new JoystickSwitchInput(analogDevice, analogPin, callback);
switches.setEncoder(0, joystickEncoder);
taskManager.scheduleOnce(250, joystickEncoder);
auto joystickEncoder2 = new JoystickSwitchInput(analogDevice, analogPin2, callback2);
switches.setEncoder(1, joystickEncoder2);
taskManager.scheduleOnce(250, joystickEncoder2);
// your other initialisation
Thank you Dave, that was really helpful!
// Joystick X/Y
switches.initialise(arduinoPins, true);
auto joystickEncoder0 = new JoystickSwitchInput(&analogDevice, JOYSTICK_X, onEncoderJoyXChange);
switches.setEncoder(0, joystickEncoder0);
taskManager.scheduleOnce(250, joystickEncoder0);
auto joystickEncoder1 = new JoystickSwitchInput(&analogDevice, JOYSTICK_Y, onEncoderJoyYChange);
switches.setEncoder(1, joystickEncoder1);
taskManager.scheduleOnce(250, joystickEncoder1);
switches.changeEncoderPrecision(0, 256, 0);
switches.changeEncoderPrecision(1, 256, 0);
Still struggling with c++, but this is just a syntax and definition issue, no showstopper.
I really have to go through all of your routines to gain more knowledge.
Pretty elegant code and possibilities, thank you for sharing your library with us
This site uses cookies to analyse traffic, serve ads by Google AdSense (non-personalized in EEA/UK),
and to record consent. We also embed Twitter, Youtube and Disqus content on some pages, these companies
have their own privacy policies.