pinMask = ~(1 << PE2);
is that correct ? i'm not quite sure how the pinMask works.
these 2 lines look obsolete
if(begun && (pin >= 0)){
DDRE |= ~(1 << PE2);
}
Oh hold on, you are supposed to set the pinmode to INPUT first, yes that is correct.
For the rest it looks OK, the question is as always 'Does it work ?'
I am a little confused with the purpose of the variables p & pin, pin is set as p once (begun && pin >= 0) , but you've copied it correctly i think.