Shop OBEX P1 Docs P2 Docs Learn Events
Any Spin code ideas for acceleration or velocity with rotary encoder? — Parallax Forums

Any Spin code ideas for acceleration or velocity with rotary encoder?

When using a rotary encoder for incrementing or decrementing 1 number per click to get to a large value it sometimes seems tedious.
On a digital clock for example when setting the minutes if you hold down either arrow key it will count up or down a minute at a time but continue to hold it changes 10 minutes at a time.
So I was wondering if anyone has implemented this sort of feature using a rotary encoder? If not- any suggestions how one might do this in Spin?

Thanks- Don

Comments

  • JonnyMacJonnyMac Posts: 9,102
    edited 2020-02-16 20:41
    Spin may not be fast enough to handle a rotary encoder -- but let's say that it is. What you might do (and I have done with buttons) is mark the time since a new change. If changes continue passed some designated period, you change the delta for the encoder. With buttons it's a bit different. I did a controller for a road sign that used up and down buttons to change parameters. If you press and hold a button the value will initially change every 250ms. If you hold the button for more than 1s then the timing between button reads changes to 100ms so that you can get to the target faster. Releasing the button goes back to the 250ms change delay for a held button.

    It's all about time.
    -- mark a new change
    -- still changing?
    -- if period met, change delta

    Many encoders have buttons built in. If that is not being used for something else, you could use it to set the encoder delta (though it's tough to press and turn reliably).
  • Don MDon M Posts: 1,652
    I thought about holding the button down and turning but as you say that may seem difficult.
  • If you think about, encoders already have a acceleration function -- you control the speed that you turn it. Doing an auto-multiplier (time based) might cause confusion, so I would stick with an external control.
  • Don MDon M Posts: 1,652
    Of course one could just have the encoder increment the ones, tens or hundreds selected by the push button. Then maybe a long push to set.
  • jmgjmg Posts: 15,173
    Don M wrote: »
    Of course one could just have the encoder increment the ones, tens or hundreds selected by the push button. Then maybe a long push to set.

    Depends how many digits you need to set.
    Button-in can select digit (left/right) then on release that digit INCs/DECs. A simple timeout can release set mode.

    Mouse movement uses a non-linear approach, faster = adds more, so you could try that, but if you need more than 3 digits, the select-digit may be easier

    If there is no button, just an encoder, maybe a combination of rate + timeout can apply.
    Slow clicks is 'normal' but a fast-spin either way, goes to digit-select mode (fast flash digit Left/right active), moderate pause in clicks hops to INC/DEC that digit (slow flash), until a long pause exits set-mode. (no flash)
    Fast spin would need to be discarded from INC/DEC, which could get tricky.
    The fast-spin number might be usable to seed the digit, so a good operator could land on, or close to wanted digit.
  • Don MDon M Posts: 1,652
    Yes 3 digits max. I like the hold button in and select digit idea.
  • Don M wrote: »
    Of course one could just have the encoder increment the ones, tens or hundreds selected by the push button. Then maybe a long push to set.

    If you display supports a means to indicate which digit you're changing, that's a good idea. On my road sign controller we uses a VFD that could set the brightness of individual characters to 1 of 8 levels, so it was nice for highlighting selected items.
Sign In or Register to comment.