Arduino button problems

Hello, I am trying to use two buttons to control a variable, When one is pressed the number goes up but when the other is pressed it goes down. But, this doesn't seem to be working, it goes up fine but when i want to come back down it increases by one and then goes down. I don't know why it is increasing by one but then going down. Any help will be helpful. the code is here:

int button = 8;
int button_two = 7;;
int val = 0;
int val_two = 0;
int numb = 0;
void setup() {
  pinMode(button, INPUT);
  pinMode(button_two, INPUT);
void loop() {
  val = digitalRead(button);
  val_two = digitalRead(button_two);
    if (val == HIGH) {
  } else if (val_two == HIGH) {
  } else {


sort by: active | newest | oldest

Why you show the number before doing the math?

Isaac Emery (author)  AYassineLebouiha2 months ago

i'm sorry I don't get what you mean.


numb=numb+1; "" (switch those lines, in both cases)
Here you are showing the number before doing the math, if numb=0 and you press increase button it will show 0 on screen then actually the numb=1, after that when you press decrease it will show 1 then actually the numb=0

Isaac Emery (author)  AYassineLebouiha2 months ago


No problem, hope it will work

Isaac Emery (author)  AYassineLebouiha2 months ago

I think i do get what you mean. You mean, don't show the variable, numb, before adding one. That may fix it. Thanks.