what i was trying to tell you about the button press is that if you use something like:
if(val==HIGH){
digitalWrite(led[i],HIGH);
}
then you that will be true the whole time you have your finger on the button. That is different than just making it true when you PRESS the button.
Let me give you an example to try to explain the difference.
Lets say you have a variable called V. You want this variable to store how make times you have pressed the button, so you can write a code and each time the button is pressed you can cay that V++ (which mean V = V + 1).
What would happen with your code is that each time you would press the button the (val == HIGH) would be true many times (because the arduino runs your loop MANY times in a second) so your val would increase a lot, not just one.
So what you need to do is to find out the moment when the button BECOMES pressed.
Check that State Change Detection page, they explain it quite well...
![]()
I think you should have an array also for the val, so you can store the value of each led.
It may help you to use something like
digitalWrite(led[i],val[i]