Need code for shifting numbers.

I have 10 pushbuttons connected to my Arduino numbered from 0 to 9 and I need a 3-digit variable that's changing as one presses the pushbuttons;

ex. Press 4 Variable: 004
Press 6 Variable: 046
Press 7 Variable: 467
Press 3 Variable: 673 etc.

Please help.

What you are looking for is arrays.
First you declare your arrays (call them array[2] and lastarray[2].

In your loop, you first make lastarray equal to array (for i= 0 to 2)

Then you look for button changes. If a button is changed, the number will be the new array[2], array[1] will be lastarray[2] and array[0] will be lastarray[1]

There are probably more elegant ways to do this, but if you are not running too much other calculations, it should work.

Joachim

You don't need an array at all. Define an int, value. Set it to 0.

When a button is pushed:

value *= 10;
value += btnNumber;
value %= 1000;

You don't need an array at all. Define an int, value. Set it to 0.

When a button is pushed:

value *= 10;

value += btnNumber;
value %= 1000;

Smart way to do it.

Personally, I'd get lazy and do this:

if (digitalRead(button1) == HIGH) {
first = second
second = third
third = 1
}

and repeat the code for all of the buttons.

Don't forget to debounce though.

But you'd also need a function that deletes the first number after every three presses

"% 1000" ?

"% 1000" ?

Whoops. Didn't notice that the first time :P. I'll modify my original post. ;D