Button Pressing with Counter


 trying lcd print different each time button pressed. once clicked remains in first while loop , despite clicking again, doesn't register. assume because haven't got button pressing function within loop when copy first half of code loop still doesn't work. how can register click has been made within loop

code: [select]
buttonstate = digitalread(buttonpin);

  if (buttonstate != lastbuttonstate) {
    if (buttonstate == high) {
      buttonpushcounter++;
    }
    delay(50);
  }

-------------------------------------------------------------------------------

  while ((voltage < 6) && (buttonpushcounter == 1))
  {
    lcd.clear();
    lcd.setcursor(0, 0);
    lcd.print(string("menu 1"));
    delay(5000);
  }
  while (buttonpushcounter == 2)
  {
    lcd.clear();
    lcd.setcursor(0, 0);
    lcd.print(string("menu 2"));
    delay(5000);
  }

you forgot update lastbuttonstate.


Arduino Forum > Using Arduino > Programming Questions > Button Pressing with Counter


arduino

Comments

Popular posts from this blog

Flip address is out of range arduino uno r3

Arduino Uno not uploading

Indesign and MathType fonts