constant for delay

They way you defined 'val', it is only in scope inside of the function setup(). Do what Alpha told you to change that.