Move reading the compass into a function