Menu with pushbutton rotary encoder and serial LCD for BS2
Turnbull2112
Posts: 65
I am trying to develop a user menu on a project with a push button and a rotary encoder. My device has an 8 x 2 serial LCD. I would like to get the button to enter a "configuration menu" from normal operation and be able to scroll through several setpoint screens and allow the encoder to adjust values stored in EEPROM. I just started testing the encoder this evening so I am very new to this. Here is an outline of what I would like to see.
DO
"check sensors"
"calculate and display values"
IF push button = 1 THEN GOSUB menu
else
next
LOOP
menu:
first screen
"ALARM SETPOINT = 50 %"
-At this point I would like to write the new value with the encoder and by pressing the button it would save it and continue to the next menu selection then ultimately exit back into the main routine.
Presently I am using two pots with an RCTIME value to adjust two variables. I need MUCH more flexibility than this. RCTIME is pretty squirrley and very limiting.
I know my questions are very broad and I'm looking for some simple examples that I could stitch together. I've been playing with Easy Encoder V1.0 BS2 so far but any extra advice would be greatly appreciated.
Regards,
Rob
DO
"check sensors"
"calculate and display values"
IF push button = 1 THEN GOSUB menu
else
next
LOOP
menu:
first screen
"ALARM SETPOINT = 50 %"
-At this point I would like to write the new value with the encoder and by pressing the button it would save it and continue to the next menu selection then ultimately exit back into the main routine.
Presently I am using two pots with an RCTIME value to adjust two variables. I need MUCH more flexibility than this. RCTIME is pretty squirrley and very limiting.
I know my questions are very broad and I'm looking for some simple examples that I could stitch together. I've been playing with Easy Encoder V1.0 BS2 so far but any extra advice would be greatly appreciated.
Regards,
Rob
Comments
The challenge with the Stamp used with an encoder is having the code fast enough to capture pulses at the highest speed expected.
I've attached a short program that works really well with small encoders.
Cheers,
Here is a snippet from my program that I would like to use the READ and WRITE to EEPROM via data selected from the digital encoder and push button. Do I add "read value unit pb is pressed then WRITE new value to EE addr"? Is it this simple? Again sorry for being so vague. Are there any examples of this? I have been looking around and I haven't found any.
DO
FOR reps = 21 TO 40
HIGH RPOT
PAUSE 500
RCTIME RPOT,1,FLOWSP 'Presently using RCTIME and a POT to adjust this variable but this sucks....
FLOWSP=FLOWSP/3/2+400MIN 900 MAX 1400 'Scaling
GOSUB Rea_d 'Read sensors and update data
SEROUT 15,33,[254,88] 'Clear LCD
SEROUT 15,33,["SP ",DEC FLOWSP DIG 3,DEC FLOWSP DIG 2, DEC FLOWSP DIG 1, DEC FLOWSP DIG 0," PV ",DEC FLOWA DIG 3,DEC FLOWA DIG 2, DEC FLOWA DIG 1, DEC FLOWA DIG 0] 'display updated setpoint and process variable data.
PAUSE 500
IF PB = 1 THEN
GOTO main
ELSE
ENDIF
NEXT
LOOP UNTIL PB = 1 OR reps > 40
RETURN
One caution is that an EEPROM location is gradually worn out over many WRITE operations. If you only WRITE a few hundred times a day, its no big deal. A few hundred times a second and the EEPROM location will take a beating.
READing an EEPROM location is harmless.
Cheers,
Thanks,
You'll see that INC includes p8,9,10,11. To use p9 and p10, you'll have to use a mask of %0110.
In the code I posted, I believe it uses INB & %0011 to use p6,p7
I found it - from way back in 1995 for the BS-1 (not BS-2).
You can download it here: http://www.parallax.com/Portals/0/Downloads/docs/cols/nv/vol1/col/nv8.pdf
This includes some code and an LCD screen example of a radio type menu. The tricky part with the BS2 is having a really tight loop so you don't loose track of quadrature inputs. An interrupt routine is usually used.
I'm working on a propeller-based project that uses a rotary encoder and simply used the obex object for the encoder - it was really way too easy. If you have timing problems and can't overcome them, consider using a prop with the BS2 library. Even though the BS2 is old, people are still doing very amazing things with them, so I wont be surprised when you succeed, though.
Rob