Shop OBEX P1 Docs P2 Docs Learn Events
Nuts & Volts question for Johnny Mac — Parallax Forums

Nuts & Volts question for Johnny Mac

w4fejw4fej Posts: 264
edited 2012-10-29 08:52 in Propeller 1
First off, I am new to the Prop coming from the Basic Stamp. I learn by looking through different program listings and figure out how the program works by seeing how others do things.

Nuts & Volts Column 6, May 2010: Spinning Up Fun With Encoders.

I have firgured out how most of the program example works and have been trying to figure out how to adapt it to my needs. The only thing I can't get my head around is the "HiLimit and LoLimit" you mention in the article. (-100, +100). Is that number the number of "detents" your encoder had?? The encoder I am using is the Parallax 27805 which has 16 detents per revolution. Would the Hi/Lo be -16, +16 for my encoder??

Could you shed some light on this Hi/Lo limit value referenced in the article?

Thanks, Mike B.

(P.S. I Love the N/V articles. I've learned a ton from them).

Comments

  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-28 20:00
    w4fej wrote: »
    The only thing I can't get my head around is the "HiLimit and LoLimit" you mention in the article. (-100, +100). Is that number the number of "detents" your encoder had?? The encoder I am using is the Parallax 27805 which has 16 detents per revolution. Would the Hi/Lo be -16, +16 for my encoder??

    I'm also a fan of JonnyMac's articles.

    I'm pretty sure his use of limits is just for your own needs.

    What is your encoder controlling? If it's controlling oven temperature then you might have the low limit be 100 and the high limit 500. It doesn't make sense to set your oven to -100 so you wouldn't use the end point examples in Jon's article.

    My encoder sets my guitar amp volume, so I have the end points set to 0 and 11.

    BTW, my Mecanum wheeled robot monitors four quadrature encoders using a program based on JonnyMac's encoder code.
  • JonnyMacJonnyMac Posts: 9,108
    edited 2012-10-28 21:05
    That is the limit you want when you instantiate the object -- and you can set it when you call the init() method. To give you an example, a friend of mine used that object to create a watering controller and each time he moved from one field to another, he would reset the limits; on the hours field he set the limits from 0 to 23, the minutes and seconds fields were 0 to 59. As Duane points out, the limits are based on your use of the encoder.

    BTW, I appreciate the kind words by both of you. I do work hard to make my column educational (without being overwhelming) and entertaining.
  • w4fejw4fej Posts: 264
    edited 2012-10-29 05:02
    Thanks Johhny and Duane:

    Ok, the encoder will be used to scroll through several "menus" on a remote control device. I want to be able to scroll forwards and backwards. If I hit the highest menu then I want it to roll over back to the first menu etc.. The encoder I am using doesn't have a button however I have a "select" button right next to the encoder so in effect It has one. Let's say I have 7 different menus I want to scroll through, would the limits then be +7 to -7? Is the negative number to indicate the opposite direction of rotation? Or would my limits be 0 or 1 and 7??

    Thanks again and keep spining..
    Mike B.

    Edit: I think a light bulb just went off on this question. Doooh... If I have seven menus then the limits would be 1 to 7 thus not allowing for a value of say 8 or 9 etc. Sometimes you just can't see the stinking forest through all those darn trees!
  • Duane DegnDuane Degn Posts: 10,588
    edited 2012-10-29 08:52
    JonnyMac's code lets you also set the starting value of the encoder so just set it to something really high like one billion and have the limits be zero and two billion (or some other large number less than 2,147,483,647 (which is the largest value of a long for the Propeller)).

    Then you could determine menu choice by using the modulus operator:
    menuChoice := encoderValue // 7
    

    The range of "menuChoice" would be from 0 to 6. This will allow the desired "roll over" effect you want.

    Instead of using one billion exactly, you could choose a starting value where the above equation gives you the memu choice you what to start with. For example if you want "menuChoice" to equal zero before the encoder is turned, you would set the start value to 999,999,994 or 1,000,000,001.
Sign In or Register to comment.