Hi all,
Pretty new to coding so please go easy on me!
I have Arduino and I2C QT rotary encoders and am using the example code provided. I would like to limit rotation output triggers from 0-100-0 rather than incrementing into the thousands. I have noticed the void setEncoderPosition function but haven't a clue how to use it or even if that is the correct way to tackle this.
If someone could shed some light on this I would be grateful.
Thanks!
QT Rotary Encoder set min and max values?
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: QT Rotary Encoder set min and max values?
Quadrature encoders are incremental encoders. They do not report an absolute position. They can only tell you the direction and number of steps moved from some arbitrary initial position.
You can set that initial position using setEncoderPosition. There are no physical limits to the number of steps you can rotate in either direction. Any limits on values reported would need to be implemented in your software.
You can set that initial position using setEncoderPosition. There are no physical limits to the number of steps you can rotate in either direction. Any limits on values reported would need to be implemented in your software.
- Mjblackfire
- Posts: 5
- Joined: Thu Oct 21, 2021 7:13 am
Re: QT Rotary Encoder set min and max values?
Thanks for the reply. That's exactly what I'm trying to achieve. I've used constrains to limit before but surely there is a way to instruct the QT seesaw controller to stop incrementing / decrementing at certain figures, so any further turns of the encoder result in no change in the encoder_position reported by the Arduino software?
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: QT Rotary Encoder set min and max values?
Yes you could modify the firmware on the seesaw chip to do that. But it would be simpler to just clamp the min & max values in your code.surely there is a way to instruct the QT seesaw controller to stop incrementing / decrementing at certain figures
- Mjblackfire
- Posts: 5
- Joined: Thu Oct 21, 2021 7:13 am
Re: QT Rotary Encoder set min and max values?
Okay we're on a similar wavelength here. I can clamp what number the serial.print stops at, say 20, but any further increments on the encoder are still being logged in the firmware. So e.g. if the encoder is turned 25 steps I then have to decrement the encoder back down again 5 clicks before the serial.print logs any decrease. That's what I'm trying to overcome but my basic coding is hitting a wall.
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: QT Rotary Encoder set min and max values?
If the reported current position exceeds your limits, you can call setEncoderPosition to reset the current position to the limit. Then when the direction reverses, it will start decrementing from that limit position.
- Mjblackfire
- Posts: 5
- Joined: Thu Oct 21, 2021 7:13 am
Re: QT Rotary Encoder set min and max values?
Could you kindly explain how to do that please as I can't figure it out and can't see any documentation on its use for newbies like me. And does it need any void setup or defining to function.
- adafruit_support_bill
- Posts: 88154
- Joined: Sat Feb 07, 2009 10:11 am
Re: QT Rotary Encoder set min and max values?
Something like:
Code: Select all
int32_t new_position = ss.getEncoderPosition();
if (new_position > MAX_POSITION)
{
ss.setEncoderPosition(MAX_POSITION);
new_position = MAX_POSITION;
}
if (new_position < MIN_POSITION)
{
ss.setEncoderPosition(MIN_POSITION);
new_position = MIN_POSITION;
}
- Mjblackfire
- Posts: 5
- Joined: Thu Oct 21, 2021 7:13 am
Re: QT Rotary Encoder set min and max values?
Thanks very much, I'll give that a go.
Please be positive and constructive with your questions and comments.