I wanted to come up with a straightforward menu system configuration that allows you to scroll through different options and adjust a "setting" in each option on to an LCD display. I also wanted the user to both "enter" the data into a function and "clear" the entered data back to zero. After doing some research and training, I came up with a menu program that utilizes the functions of six buttons.
THE PROGRAMThe program makes use of the LiquidCrystal_I2C which needs to be downloaded and installed before using this program. The library allows you to utilize the I2C backpack attached to your LCD display. It also contains a "debouncing" function which allows the button pushes to be stable, thus recording an accurate push into the program. It prevents stray signals from affecting the recording of the push press.
Six buttons are separately wired to six digital inputs of the Arduino. Each of those buttons has a wire going into one corner of the button from the positive rail of the breadboard. A 2K resistor is attached to the opposite corner of each of the buttons pulled to the negative rail (pull-down resistors). The other side contains an LED light for each button. Two LEDs are colored blue and represent the "Up" and "Down" directional buttons. The next two LEDs are colored green and represent the "Left" and "Right" directional buttons. The next LED is colored yellow and represents an "Enter" function. The last LED is colored red and represents a "Clear" function. Each LED has a 220-ohm current-limiting resistor going to the negative rail of the breadboard. The LEDs themselves are actually not necessary for this program to function, these are mainly just cosmetic functions.
The menu arrays themselves are simply placeholders. You can modify and make the option names and measurement types anything you prefer.
The first two setting options are programmed to allow negative numbers. The last three setting options are programmed to accept only positive numbers. Those can be changed as denoted in the code. They also have integer limits between -999 to 999 but these limits can also be changed.
HOW IT WORKSWhen the program begins, use the "Left" and "Right" buttons to scroll through the menu. The menu is programmed with 5 option settings as more can be added or subtracted. In each menu option is a setting to adjust. The units of measurement are degrees F, degrees C, pounds, inches, and MPH. These can also be modified.
(For continuity's sake, I set the program to only allow both positive and negative numbers be entered for both the degrees options and only those two options. The other three options can only accept positive numbers. This can be changed.)
The "Up" and "Down" buttons allow you to change the number of the setting. Pushing either the up or down buttons more than five times increases or decreases the setting number by 5, so as to speed up the process of entering a large number value. The increment resets back to 1 when a different button other than the one being pressed consecutively is pushed. The settings are saved in the memory as long as the micro-controller is powered on. Pushing the "Enter" button enters the data into function by simply flashing a message that the data was entered. Pushing the "Clear" clears the current setting back to 0.
While this menu configuration does not have a specific use, you can modify and expand on the code to accommodate your needs or ideas.
Have fun with this code, feel free to use it anywhere, modify it to your hearts' desire. ENJOY!!
Comments