Implement asynchronous pin waiting

thus getting rid of the unnecessary delay in the switch example