title: Trouble with buttons (Arduino)
body: <p>StackOverflow! I am a teenager fairly new to Arduino coding, and am investigating a problem. I am running Linux Ubuntu 10.10 if that makes a difference. I have a setup going with a homemade board consisting of five buttons, one for each left, right, up, and down, and one center button, and a Hitachi 2x16 character LCD screen, using the Arduino Uno board.. My programs purpose is to play my splash screen, issue a countdown from three on-screen, display a helpful message, and then go into the program, which simply opens up a list of items, showing one at a time, and allows you to scroll through them using the up and down buttons, and exit the program by clicking the center button. So, here's the problem: the rest of the program works just fine, but when it comes to the menu, it correctly displays the first item, but the buttons do not serve their purpose. I checked using the serial monitor, and the state of the button doesn't change when pressed. But here's the kicker. I used a volt meter to check if the buttons were correctly using power, and they are. They just don't seem to be working digitally. I have checked my wiring, and it is all correct. I think the problem may be in the code, so I leave it to your more experienced hands: </p>
  
  <pre><code>// include the library code:
  #include &lt;LiquidCrystal.h&gt;
  
  int itemNum = 0;
  
  // Declare variables for on and off states, for efficiency!
  int on = LOW;
  int off = HIGH;
  
  // Declare the buttons' digital pins and states respectively
  const int upbtnpin = 8;
  const int dwnbtnpin = 9;
  const int cntrbtnpin = 10;
  
  int upbtnstate = off;
  int dwnbtnstate = off;
  int cntrbtnstate = off;
  
  // initialize the library with the numbers of the interface pins
  LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
  
  void setup() {
  
    // Activate Serial Monitor
    Serial.begin(9600);
  
    // Declare buttons to be INPUT
    pinMode(upbtnpin, INPUT);
    pinMode(dwnbtnpin, INPUT);  
    pinMode(cntrbtnpin, INPUT);
  
    // Activate Pullups
    digitalWrite(upbtnpin, HIGH);
    digitalWrite(dwnbtnpin, HIGH);
    digitalWrite(cntrbtnpin, HIGH);
  
    // Begin LCD
    lcd.begin(16, 2);
  
  
    // Splash Screen
    lcd.setCursor(0, 0);
    lcd.print(" _@ Paradigm @_");
    lcd.setCursor(0,1);
    lcd.print("&lt;-&gt; Robotics &lt;-&gt;");
    delay(3000);
    lcd.clear();
  
    // Display Message and countdown
    cntrbtnstate = digitalRead(cntrbtnpin);
    lcd.setCursor(0, 0);
    lcd.print("Menu Program 1.0");
    lcd.setCursor(0, 1);
  
    int i = 3;
    while (i &gt; 0) {
  
    if (i == 3) {
      lcd.setCursor(0, 1);
      lcd.print("Wait 3 second(s)");
      delay(1000);
      i--;
    }
  
    else if (i == 2) {
      lcd.setCursor(0, 1);
      lcd.print("Wait 2 second(s)");
      delay(1000);
      i--;
    }
  
    else if (i == 1) {
      lcd.setCursor(0, 1);
      lcd.print("Wait 1 second(s)");
      delay(1000);
      i--;
    }
  
   }
     lcd.clear();
     delay(500);
     lcd.setCursor(0, 0);
     lcd.print("Press enter any");
     lcd.setCursor(0, 1);
     lcd.print(" time to exit. ");
     delay(1200);
     lcd.clear();
  
  
  }
  
  
  
  // ...And finally, to the actual program!
  
  void loop() {
    upbtnstate = digitalRead(upbtnpin);
    dwnbtnstate = digitalRead(dwnbtnpin);
    cntrbtnstate = digitalRead(cntrbtnpin);
  
    while (cntrbtnstate != on) {
  
      if (upbtnstate == on) {
        delay(250);
        itemNum++;
      }
  
      else if (dwnbtnstate == on) {
        delay(250);
        itemNum--;
      }
  
      // OPTIONAL for debugging
      delay(150);
      Serial.print(" ! "); 
      delay(150);
      Serial.print(int(upbtnstate));
      Serial.print(" ");
      delay(150);
      Serial.print(int(dwnbtnstate));
      Serial.print(" ");
      delay(150);
      Serial.print(int(cntrbtnstate));
  
      String item = "";
      int itemNum = 0;
  
      switch(itemNum) {
  
        case 0:
          lcd.setCursor(0, 1);
          lcd.print("END OF LIST");
          break;
        case 1:
          lcd.setCursor(0, 1);
          lcd.print("Water Bottle");
          break;
        case 2:
          lcd.setCursor(0, 1);
          lcd.print("Biker Jacket");
          break;
        case 3:
          lcd.setCursor(0, 1);
          lcd.print(".44 Magnum");
          break;
        case 4:
          lcd.setCursor(0, 1);
          lcd.print(".44 Rounds (x14)");
          break;
        case 5:
          lcd.setCursor(0, 1);
          lcd.print("Machete");
          break;
        case 6:
          lcd.setCursor(0, 1);
          lcd.print("END OF LIST");
          break;
        default:
          lcd.setCursor(0, 0);
          lcd.print("  An error has  ");
          lcd.setCursor(0, 1);
          lcd.print("    occoured    ");
      }
  
      if (itemNum &gt; 6) {
        itemNum == 6;
      }
  
      else if (itemNum &lt; 0) {
        itemNum == 0;
      }
  
     lcd.setCursor(0, 1);
     lcd.print(item);
    }
    lcd.clear();
    lcd.setCursor(0, 1);
    lcd.print("    Goodbye!    ");
  
  }
  </code></pre>