Your sketch should do that although you can omit the delay(), it's not necessary.
I guess you made the wiring wrong but you didn't provide a wiring diagram for us to check.
Your sketch should do that although you can omit the delay(), it's not necessary.
I guess you made the wiring wrong but you didn't provide a wiring diagram for us to check.