Your pictures are just about useless. Post links to the devices, where the manufacturer knows how to post useful information, like schematics, and which pins are being used.
That code uses pins 2 and 3 because they support external interrupts. The Mega has other pins that support external interrupts, too.