abstracting sensor reads into a function