Due to high demand expect some shipping delays at this time, orders may not ship for 1-2 business days.
0

QT Rotary Encoder set min and max values?
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

QT Rotary Encoder set min and max values?

by Mjblackfire on Thu Oct 21, 2021 7:19 am

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!

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

Re: QT Rotary Encoder set min and max values?

by adafruit_support_bill on Thu Oct 21, 2021 8:05 am

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.

adafruit_support_bill
 
Posts: 82472
Joined: Sat Feb 07, 2009 10:11 am

Re: QT Rotary Encoder set min and max values?

by Mjblackfire on Thu Oct 21, 2021 10:32 am

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?

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

Re: QT Rotary Encoder set min and max values?

by adafruit_support_bill on Thu Oct 21, 2021 10:55 am

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.

adafruit_support_bill
 
Posts: 82472
Joined: Sat Feb 07, 2009 10:11 am

Re: QT Rotary Encoder set min and max values?

by Mjblackfire on Thu Oct 21, 2021 11:06 am

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.

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

Re: QT Rotary Encoder set min and max values?

by adafruit_support_bill on Thu Oct 21, 2021 11:33 am

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.

adafruit_support_bill
 
Posts: 82472
Joined: Sat Feb 07, 2009 10:11 am

Re: QT Rotary Encoder set min and max values?

by Mjblackfire on Thu Oct 21, 2021 11:50 am

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.

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

Re: QT Rotary Encoder set min and max values?

by adafruit_support_bill on Thu Oct 21, 2021 11:58 am

Something like:

Code: Select all | TOGGLE FULL SIZE
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;
}

adafruit_support_bill
 
Posts: 82472
Joined: Sat Feb 07, 2009 10:11 am

Re: QT Rotary Encoder set min and max values?

by Mjblackfire on Thu Oct 21, 2021 12:09 pm

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

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

Please be positive and constructive with your questions and comments.