You need to create a variable to display that the button will toggle.
Do you have some code started that you can post up?
Shawn
Something like:
Code:value var word incvalue var word cursorposition var byte **LCD setup code here ** LCDOUT $FE, $0F 'turn blinking cursor on cursorposition = 0 'reset cursor position dostuff: LCDOUT #value DIG 3 LCDOUT #value DIG 2 LCDOUT #value DIG 1 LCDOUT #value DIG 0 IF upbutton = 1 THEN IF cursorposition = 0 THEN value = value + 1 ENDIF IF cursorposition = 1 THEN value = value + 10 ENDIF IF cursorposition = 1 THEN value = value + 100 ENDIF IF cursorposition = 1 THEN value = value + 1000 ENDIF IF downbutton = 1 THEN IF cursorposition = 0 THEN value = value - 1 ENDIF IF cursorposition = 1 THEN value = value - 10 ENDIF IF cursorposition = 1 THEN value = value - 100 ENDIF IF cursorposition = 1 THEN value = value - 1000 ENDIF IF leftbutton = 1 THEN IF cursorposition > 0 THEN LCDOUT $FE, $10 'move cursor left cursorposition = cursorposition - 1 ENDIF ENDIF IF rightbutton = 1 THEN IF cursorposition < 3 THEN LCDOUT $FE, $14 'move cursor right cursorposition = cursorposition + 1 ENDIF ENDIF IF confirmbutton = 1 THEN '** go back to, or continue the main program here ENDIF goto dostuff
oops, straight after the dostuff: label,
to set up the display for the next frame.Code:LCDOUT $FE,2 'LCD cursor return home FOR count = 0 TO cursorposition LCDOUT $FE, $14 'move cursor right NEXT count
None of this is tested, but you should get the idea.
Might want to compare cursor position with 0,1,2 and 3 when checking the buttons instead of only 0 and 1 no?
Can you even use cursor position 0? Or does it start at 1?
I think you have them backwards, the units would be at position 3, tens at position 2 and so on.
But yeah, that's a perfect starting point to start building on.
Robert
Whoops, ... copy & paste & forgot to adjust
and do the same with te up button.Code:IF downbutton = 1 THEN IF cursorposition = 0 THEN value = value - 1 ENDIF IF cursorposition = 1 THEN value = value - 10 ENDIF IF cursorposition = 2 THEN value = value - 100 ENDIF IF cursorposition = 3 THEN value = value - 1000 ENDIF
Also need a pause for button debounce, so
straight after each button checkCode:pause 500
cursorposition = 0 is the thousands position.
The thousands digit is the first to be printed to LCD,
so no movement needs to occur from cursor home command.
And the other thing you mentioned...
I need to build a generic test circuit before posting code![]()
Bookmarks