How about post your whole project here and also your external circuit. Are you using simple buttons to input or using matrix?
Need a bit more comment on your software so people can understand better.
Besides that you never set num1 you may think to tighten the code, you may read and write more than 1 pin at a time provided that they are located on the same physical port. Delaying for every case could be extracted and called omly once....