NEW: Learning electronics? Ask your questions on the new Electronics Questions & Answers site hosted by CircuitLab.
Project Help and Ideas » Scrolling menu selection
January 29, 2011 by SpaceGhost ![]() |
Here's something I have been playing around with. I put together a fairly simple vertically "scrolling" menu. You scroll the "arrow" (>) to the output that you want to activate. Pushing one button turns on the selected output, pushing another button turns it off. Two buttons are used to either navigate up the menu or back down, and the menu "wraps."
The program works good. LEDs on the outputs give visual indication of the individual output states (on of off). I experimented with putting "ON" indicators on the LCD screen that corresponded with individual outputs and their on states (putting the ON indicators on the 17th - 20th position(s) of the LCD line). Using a lot of "if" statements and more variables I had luck getting "ON" messages to move and wrap with the first two outputs ("output one" and "output two")... But getting "output three" to work that way with the other two outputs "ON" proved to be impossible! I kinda figured when I started that it probably wouldn't work or the file would be HUGE... but gave it several tries. The code I have works as it is - but I'd love to improve on it! Does anyone have any hints or suggestions? I'm sure there's a concept to this that I need to learn & study... Dave |
||
---|---|---|---|
January 30, 2011 by Ralphxyz ![]() |
Hey Space Ghost, this is very interesting I am going to need a multiple button press routine to set Year/Date/Time in a new project. Thanks for doing some of the preliminary work for me. I have limited programming knowledge, but one point I do see is all of your "if" statements. I believe you really want to use the switch/case syntax. Google "C switch case". All of the ifs will work but I believe using switch/case makes your code more logical (easier) to read and I believe the compiler will generate more efficient (smaller) code. Ralph |
||
January 31, 2011 by SpaceGhost ![]() |
Hey thanks Ralph, I will look that up. In the meantime though I figured out how to put the "ON"s on the LCD display to correspond with the output states of the MCU. Here is the code as I have it now -
This works pretty good, I'm happy with it. It would be pretty easy to modify also, add another output, etc. I might play around and see if I can do a one button input to turn the selected output on or off (push once for on, push again for off), and thus free up another port for another extra output... I may have some redundant code in this program. I may try disecting it some later... I'm always of course, open to any suggestions or comments... Does this code seem kinda large for what I want it to do? It's really just a fancy selector switch... I'm getting it with the "if" statements, I'm getting it now how to "and" things... And Rick, that counter program you helped me with was of great help here too, again! But I know there is so much more that I need to learn! But sometimes I gotta just walk away from it for a while, too. Often that's what I gotta do to figure something out. Anyway, hope someone else might find what I posted useful or inspire them to come up with something better. Dave |
||
February 01, 2011 by Ralphxyz ![]() |
You can "latch" a button by setting a variable on button press and then polling the state of the variable on another press. Your code would process depending on the state of the variable not on the button state. This could/should be done using interrupts so that opens up a whole new realm of programing for you. Ralph |
Please log in to post a reply.
Did you know that you can impress a loved one with a digitally-controlled Valentine's Day Card with randomly twinkling LEDs? Learn more...
|