a bit far of what you need to do... but you may find some tricks in it...

Combination Gate Access
http://www.picbasic.co.uk/forum/show...=gate+operator

Enjoy!