More explicit integer types

The code broke on Arduinos that use 32-bit integers (e.g. Arduino Due) rather than 16-bit integers (Uno). Being more explicit about ints fixes this problem.