Fixed race condition issue with analogRead