Debouncing should be done in a while() slope and not by only reading the input once. I remember that I once used delay(125) for good results.
More remarks:
- Why don't u use
pinMode(2, INPUT_PULLUP)you need only the button between pin and ground (assumed you used an external resistor to 5V), so you use the internal one - A construct like
(val == LOW) && (old_val == HIGH)works, but could be done (val != old_val) in a smarter way, couldn't it? When you will be able to write more complex programs, you will like more "readable" code - Try to use
digitalWrite(13, (stateOfLED == 1))instead of thatif ... elseconstruct
For more ideas study the lower part of constants - Arduino Reference