QT Rotary Encoder set min and max values?

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
Mjblackfire
 
Posts: 5
Joined: Thu Oct 21, 2021 7:13 am

QT Rotary Encoder set min and max values?

Post by Mjblackfire »

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!

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: QT Rotary Encoder set min and max values?

Post by adafruit_support_bill »

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.

User avatar
Mjblackfire
 
Posts: 5
Joined: Thu Oct 21, 2021 7:13 am

Re: QT Rotary Encoder set min and max values?

Post by Mjblackfire »

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?

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: QT Rotary Encoder set min and max values?

Post by adafruit_support_bill »

surely there is a way to instruct the QT seesaw controller to stop incrementing / decrementing at certain figures
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.

User avatar
Mjblackfire
 
Posts: 5
Joined: Thu Oct 21, 2021 7:13 am

Re: QT Rotary Encoder set min and max values?

Post by Mjblackfire »

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.

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: QT Rotary Encoder set min and max values?

Post by adafruit_support_bill »

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.

User avatar
Mjblackfire
 
Posts: 5
Joined: Thu Oct 21, 2021 7:13 am

Re: QT Rotary Encoder set min and max values?

Post by Mjblackfire »

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.

User avatar
adafruit_support_bill
 
Posts: 88154
Joined: Sat Feb 07, 2009 10:11 am

Re: QT Rotary Encoder set min and max values?

Post by adafruit_support_bill »

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;
}

User avatar
Mjblackfire
 
Posts: 5
Joined: Thu Oct 21, 2021 7:13 am

Re: QT Rotary Encoder set min and max values?

Post by Mjblackfire »

Thanks very much, I'll give that a go.

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”