Professional Documents
Culture Documents
Pushbutton Menu
Pushbutton Menu
Pushbutton Menu
// LIBRARIES
#include <Wire.h> // deals with I2C connections
#include <LiquidCrystal_I2C.h> // activates the LCD I2C library
// MENU ARRAYS
String menuOption[] = {{"Setting 1"}, {"Setting 2"}, {"Setting 3"}, {"Setting 4"},
{"Setting 5"}}; // Text on the top line
String measurementType[] = {{"[DEG. FAHR]"}, {"[DEG. CEL]"}, {"[POUNDS]"},
{"[INCHES]"}, {"[MPH]"}}; // Text on the bottom line
// OBJECT DECLARATION
LiquidCrystal_I2C lcd(0x27, 16, 2); // Activates the LCD "object"
// SETUP
void setup() {
delay(1000);
// MAIN LOOP
void loop() {
// The current state for each button is set not equal to the pressed state and
when it changes, the pressed state becomes equal to the current state.
if (buttonStateRight == LOW)
{
directionPush++; // Both the up and down
press counts will be reset to zero when the right button is pushed.
upPressCount = 0;
downPressCount = 0;
}
if (directionPush > 4) // If the user tries to
scroll above the last menu option,
{ // the program will loop
back to the first menu option.
directionPush = 0;
}
lcd.clear();
}
// UP BUTTON PRESS
if (currentButtonStateUp != buttonStateUp) // Up button scrolls the
setting upward.
{
buttonStateUp = currentButtonStateUp;
{
upPressCount++;
downPressCount = 0; // The downPressCount is
reset to zero.
setting1Counter++;
if (upPressCount > 5)
{
setting2Counter = setting2Counter + 4;
}
if (upPressCount > 5)
{
setting3Counter = setting3Counter + 4;
}
if (upPressCount > 5)
{
setting4Counter = setting4Counter + 4;
}
if (upPressCount > 5)
{
setting5Counter = setting5Counter + 4;
}
if (downPressCount > 5)
{
setting2Counter = setting2Counter - 4;
}
if (downPressCount > 5)
{
setting3Counter = setting3Counter - 4;
}
if (downPressCount > 5)
{
setting4Counter = setting4Counter - 4;
}
if (downPressCount > 5)
{
setting5Counter = setting5Counter - 4;
}
lcd.clear();
}
{ // It flahses a brief
message stating that the data has been cleared.
lcd.clear(); // The press counts for
both the up and down variables are also reset to zero.
lcd.setCursor(0,0);
lcd.print("DEGREES FAHREN.");
lcd.setCursor(0,1);
lcd.print("IS CLEARED");
setting1Counter = 0;
downPressCount = 0;
upPressCount = 0;
delay(2000);
}