Wait for input...

This code doesn't want to quite work

Have you tried persuasion?
Chocolates and flowers?
Pension plan?

I don't quite understand - the first character you read with a keyboard.read and convert it to decimal digit, but after that, you just wait on a data pin.

This:

r1 = val, DEC;

doesn't do what you want it to. It just assigns the value of DEC to r1.