Oops, wait(1) instruction should be in while(1) block.
The code in my previous post was edited.