Infrared object detect sensor now works as intended. Sorted problem
with global variables.