Launch Box built :) requesting help with limiting rotary encoder value
xanadu
Posts: 3,347
<-wireless keyboard for laptop on robot, not launch box.
<-old pic, all wired up now. all in one unit though, only the battery sits in the bottom of case
I only want the rotary encoder to have 2 positions for now. So it can only equal two different numbers. Then I can use it as a rotary selector for two options and it can switch between them relatively fast.
I am on page 63 of the PE book for reference. I can make example code that works and limits the VAR to two numbers using a push button.
It seems as though I cannot limit the variable with #> or #< inside of my program using the encoder. So I'm guessing that it needs to be done in the object?
The object is Quad Decoder - http://obex.parallax.com/objects/666/
Here is my current code:
Thank you.
<-old pic, all wired up now. all in one unit though, only the battery sits in the bottom of case
I only want the rotary encoder to have 2 positions for now. So it can only equal two different numbers. Then I can use it as a rotary selector for two options and it can switch between them relatively fast.
I am on page 63 of the PE book for reference. I can make example code that works and limits the VAR to two numbers using a push button.
It seems as though I cannot limit the variable with #> or #< inside of my program using the encoder. So I'm guessing that it needs to be done in the object?
The object is Quad Decoder - http://obex.parallax.com/objects/666/
Here is my current code:
{{ Launch Box Project }} CON _clkmode = xtal1 + pll16x '333 gigawatt crystal _xinfreq = 5_000_000 'recalibrate decalibrator ENCODER_PIN = 12 'first encoder pin (12+13) XBT = 17 'XBee DIN XBR = 16 'XBee DOUT OBJ quad : "QuadDecoder" lcd : "SparkFun_serial_lcd" xbee : "XBee_Object_2" VAR byte encval 'encoder variable PUB main 'init VARs encval := 1 'rot enc initial value 'init used pins dira[23] := 1 'rot enc red LED dira[22] := 1 'rot enc green LED dira[21] := 1 'rot enc blue LED dira[18] := 0 'rot enc push button dira[5] := 0 'arm switch dira[6] := 0 'red push button dira[1] := 1 'ARM sw status led outa[1] := 0 'yellow dira[2] := 1 'PWR sw status led (no switch logic) outa[2] := 1 'green dira[3] := 1 'BTN status led outa[3] := 0 'red 'let's get this LCD party started lcd.init(7,9600,2,20) lcd.displayOn lcd.cursor(0) lcd.backlight(true) lcd.clrln(0) lcd.clrln(1) 'XBee after party begins now xbee.start(XBR, XBT, %0000, 9_600) waitcnt(clkfreq * 1 + cnt) xbee.at_init xbee.str(string("Launch Box Online")) 'begin enc program to take over the planet quad.start(ENCODER_PIN, @encval) go PUB go repeat outa[1] := ina[5] 'send arm sw to yellow LED outa[3] := ina[6] 'send red but to red LED waitcnt(clkfreq/10 + cnt) lcd.dec(encval) {{ ┌──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┐ │ TERMS OF USE: MIT License │ ├──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┤ │Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation │ │files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, │ │modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software│ │is furnished to do so, subject to the following conditions: │ │ │ │The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.│ │ │ │THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE │ │WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR │ │COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, │ │ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. │ └──────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────┘ }}
Thank you.
Comments
Andy
Thanks.
You can also isolate other bits with & 2 the result changes every second step between 0 and 2. With & 4 you get 0 or 4 every fourth step, and so on.
The variable encval still counts up and down in the full range and will always be overwritten by the QuadDecoder object, so if you need the toggling value in a variable you need to copy it into a new variable:
myencval := encval & 1
Andy
I just updated my code for the box. It's sending a character to an XBee in loop back and waiting for the response, depending on the position of the encoder knob it either beeps or blinks, or both. So now I can range test it in my RC airplane, sort of a heart beat signal if you will.
This box project is way too much fun lol.