Please I'm needing help.
I'm trying to set up a menu with LCD as output and matrix keypad as input. It just isn't working right,
I'm not so sure how this is supposed to be done. I'm using subroutines for each keypress.
I need the LCD to keep on displaying the different key functions and immediately jump to the sub-routine when a key is pressed. However, if after it starts the subroutine no further action is taken or it has done what it should, it should wait for say 3 seconds and go back to the main loop.
I have attached the code I've gotten up.
This is just the basic stuff, I'll still add more layers.
Here is part of the code for quick viewing. The full gcb file is attached.
Main:
DoforeverSelectcaseKeypadDatacase10'Value 10 is Key ALockcase11'Value 11 is Key BUnlockcase13'Value 13 is Key DResetEndselectloopsubLockclsprint"Set Password:"locate1,0LCDCursorFlashOnwait3sLCDCursorFlashOffGotoMainendsubsubUnlockclsPrint"Enter Password:"wait3sGotoMainendsubsubResetclsPrint"Enter Master pin"wait3sGotoMainendsub
will do forever do forever? there's do while and do until but do forever would just be
do
loop
Main:
DoforeverSelectcaseKeypadDatacase10'Value 10 is Key APrint"Lock"case11'Value 11 is Key BPrint"Unlock"case13'Value 13 is Key DPrint"Reset"""Endselectloop
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Thank you so much for responding.
It seems I overlooked some errors before posting the code above (just the calling in of the subroutines). I have corrected it.
I just use use the 'Do forever' in place of do because I think it's meant to catch errors. I think I saw that somewhere, not sure.
Okay, Do while and Do until?
How would I structure it??
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
The Do command will cause the code between the Do and the Loop to run repeatedly while condition is true or until condition is true, depending on whether While or Until has been specified.
Note that the While or Until and the condition can only be specified once, or not at all. If they are not specified, then the code will repeat endlessly.
Optionally, you can specify a condition to EXIT the Do-Loop immediately.
Example 1:
'This code will flash a light until the button is pressed
#chip12F629, 4
#defineBUTTONGPIO.3
#defineLIGHTGPIO.5DirBUTTONInDirLIGHTOutDoUntilBUTTON=1PulseOutLIGHT, 1sWait1sLoopExample2:
This code will also flash a light until the button is pressed. This example uses EXIT DO within a continuous loop.
Your first code was very close to working . Calling the subs with select is exactly how you could build the menu.
You do not want " Goto Main" in your subs. When the program hits "End Sub" it automatically goes back to where it came from.
Your options menu should be put into a sub also. I don't know how big your lcd is? 1x16, 2x16,2x20. it would be nice to get the whole menu options on the display with one write, use abbreviations. "A-LK B-unlk D-rst" there it is in 16 chars. Or you could make scrolling but that is harder.
SubMenuOptionsclsPrint"A-LK B-unlk D-rst"EndSub
Once the options are in a sub then write the MenuOptions Sub 2 different places in your main program.
first place is in the intro right after the
print"Welcome"wait2sMenuOptions
the other place is at the end of every sub (lock,unlock,reset) before the "end sub" statement. this will clean your screen and put up the MenuOptions.
Thank you so much@mmotte.
I appreciate the details. Let me try this and get back.
I also would love to implement the scrolling menu immediately I get this working.
I intend using a 4 by 16 LCD but for now, I'm using a 2 by 16 LCD.
Last edit: Judah Ben 2020-09-28
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
I'm not sure if it is any help, but both the clocks I have posted in the finished projects section have a menu for setting the time, date and parameters. The menu is displayed on a standard 16 x 2 LCD and all options are selected and adjusted with three buttons (Up, Down, OK). The menu has a timeout where if no buttons are pressed the menu exits out. It may inspire you in how to implement something similar?
This code is a modified form of one originally written by someone else. I thought I'd borrowed it from one of the clock examples in the demo folder, but I can't spot which one it was.
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Indeed.Wow interesting that case is more efficient / faster than multiple if then.
Thanks for the heads up. Little things like this are not explained in the gcb help.
I thought case would be less efficient cos it looked too polished.
cheers
ps lcd displays are so boring
I hope this has not confused Judah Ben.
I don't suppose code speed matters with lcds as they are slow as snails anyway :)
Last edit: stan cartwright 2020-09-27
If you would like to refer to this comment somewhere else in this project, copy and paste the following link:
Please I'm needing help.
I'm trying to set up a menu with LCD as output and matrix keypad as input. It just isn't working right,
I'm not so sure how this is supposed to be done. I'm using subroutines for each keypress.
I need the LCD to keep on displaying the different key functions and immediately jump to the sub-routine when a key is pressed. However, if after it starts the subroutine no further action is taken or it has done what it should, it should wait for say 3 seconds and go back to the main loop.
I have attached the code I've gotten up.
This is just the basic stuff, I'll still add more layers.
Here is part of the code for quick viewing. The full gcb file is attached.
Last edit: Judah Ben 2020-09-27
will do forever do forever? there's do while and do until but do forever would just be
do
loop
Thank you so much for responding.
It seems I overlooked some errors before posting the code above (just the calling in of the subroutines). I have corrected it.
I just use use the 'Do forever' in place of do because I think it's meant to catch errors. I think I saw that somewhere, not sure.
Okay, Do while and Do until?
How would I structure it??
This may help: http://gcbasic.sourceforge.net/help/_do.html
Explanation:
The Do command will cause the code between the Do and the Loop to run repeatedly while condition is true or until condition is true, depending on whether While or Until has been specified.
Note that the While or Until and the condition can only be specified once, or not at all. If they are not specified, then the code will repeat endlessly.
Optionally, you can specify a condition to EXIT the Do-Loop immediately.
Example 1:
This code will also flash a light until the button is pressed. This example uses EXIT DO within a continuous loop.
Thank you very much, I'll put something together and get back ASAP.
Your first code was very close to working . Calling the subs with select is exactly how you could build the menu.
You do not want " Goto Main" in your subs. When the program hits "End Sub" it automatically goes back to where it came from.
Your options menu should be put into a sub also. I don't know how big your lcd is? 1x16, 2x16,2x20. it would be nice to get the whole menu options on the display with one write, use abbreviations. "A-LK B-unlk D-rst" there it is in 16 chars. Or you could make scrolling but that is harder.
Once the options are in a sub then write the MenuOptions Sub 2 different places in your main program.
first place is in the intro right after the
the other place is at the end of every sub (lock,unlock,reset) before the "end sub" statement. this will clean your screen and put up the MenuOptions.
GL
Mike
Thank you so much@mmotte.
I appreciate the details. Let me try this and get back.
I also would love to implement the scrolling menu immediately I get this working.
I intend using a 4 by 16 LCD but for now, I'm using a 2 by 16 LCD.
Last edit: Judah Ben 2020-09-28
I'm not sure if it is any help, but both the clocks I have posted in the finished projects section have a menu for setting the time, date and parameters. The menu is displayed on a standard 16 x 2 LCD and all options are selected and adjusted with three buttons (Up, Down, OK). The menu has a timeout where if no buttons are pressed the menu exits out. It may inspire you in how to implement something similar?
This code is a modified form of one originally written by someone else. I thought I'd borrowed it from one of the clock examples in the demo folder, but I can't spot which one it was.
Okay, thank you. I will look them up and go through.
I would try
goto is elegant sometimes but not used much now. There are alternative methods.
Stan... Case - Select. Faster and a lot more smarter.
loop
Indeed.Wow interesting that case is more efficient / faster than multiple if then.
Thanks for the heads up. Little things like this are not explained in the gcb help.
I thought case would be less efficient cos it looked too polished.
cheers
ps lcd displays are so boring
I hope this has not confused Judah Ben.
I don't suppose code speed matters with lcds as they are slow as snails anyway :)
Last edit: stan cartwright 2020-09-27
Not at all. My case of use isn't speed-sensitive too. Thank you.
Alright, thank you @evanvennn