How to count a switch push

hi there
i have two buttons on pin 2 and 3, i would like when i push one button it will add 0.1 to the serial and push the other it will take 0.1 off.

i got this using interrupts but adds a lot in one button push instead of one count per push

int encoderPin1 = 2;
int encoderPin2 = 3;

volatile float encoderValue = 0;

void setup() {
  Serial.begin (9600);

  pinMode(encoderPin1, INPUT); 
  pinMode(encoderPin2, INPUT);

  digitalWrite(encoderPin1, HIGH); //turn pullup resistor on
  digitalWrite(encoderPin2, HIGH); //turn pullup resistor on

  attachInterrupt(0, updatebuttonUP  , FALLING); 
  attachInterrupt(1, updatebuttonDOWN, FALLING);

}

void loop(){ 
 
  Serial.println(encoderValue);
  delay(1000); 
}

void updatebuttonUP() {
  encoderValue ++;
}

void updatebuttonDOWN() {
  encoderValue --;
}

is this a good way of going about this? or what am i doing wrong?
thanks Joe

Read up on switch "bouncing" and how to "debounce" a switch. That could be a problem.

Edit: When you increment a floating point number, what's the new value? In other words, what does

encoderValue++;

do?

i got this using interrupts but adds a lot in one button push instead of one count per push

You are pushing an encoder?

I think the problem is the button is bouncing...
Look here -> link

Joes:
is this a good way of going about this?

If it does what you want, it's good.

...R

Edit: When you increment a floating point number, what's the new value? In other words, what does

encoderValue++;

do?

well i was playing with this i was trying to get it to add 0.1 on to the current value (obviously it does not do that).
i did try this but it did not like it:
encoderValue + 0.1;

You are pushing an encoder?

no just two push buttons
but the code did originate from using encoder

am i going about this the right way or is there some other way what could be better and easier?

i did try this but it did not like it:
encoderValue + 0.1;

What did not like that? And why should it? It accomplishes nothing.

The correct ways to increment by 0.1 are

encoderValue = encoderValue + 0.1;

or

encoderValue += 0.1;
encoderValue += 0.1;

that was what i was trying to do lol

all working now but like you lot send it is now bouncing am i better looking at the Debounce on my ide? or is there something better?
also i would like to cycle though it fast if i push and hold how could i do that?

thanks again Joe

  pinMode(encoderPin1, INPUT_PULLUP);
  pinMode(encoderPin2, INPUT_PULLUP);

  //digitalWrite(encoderPin1, HIGH); //turn pullup resistor on     ?? this may be specific to some hardware?? 
  //digitalWrite(encoderPin2, HIGH); //turn pullup resistor on

  attachInterrupt(0, updatebuttonUP  , FALLING);
  attachInterrupt(1, updatebuttonDOWN, FALLING);

Hope you plan to do debounce in ISR itself AKA delay re-trigger.

also i would like to cycle though it fast if i push and hold how could i do that?

In ISR

while( digtalRead(buttonx)
{
// advance buttonx values
buttox += 0.1;

}

but yiu will have to add some delays , say add only every 1 second, and than can get tricky in ISR.

using the internal pull up is this ok?

meaning in the examples Debounce

what am i doing wrong?

You have not given enough detail to be sure but it is unlikely that you need to use interrupts for this.

Joes:
using the internal pull up is this ok?

Yes if one of your button terminal is connected to pin and the other button terminal to ground.

meaning in the examples Debounce

I'll get back to you on that one , I am having some issues running / monitoring plain machine delay for loop
in ISR.
Simple for( long c = 0 ; c != 0XFFFFFFF;c++) delays only 1us on Due, but cascading another for loop gives unexpected and wrong delay. ( about 4 seconds)

Joes: