Thanks for your help.
Sorry about this still learning about this coding, do i put that code you have sent me in the loop or setup sorry? Does i need to put prevanalogValue in the integers somewhere as when I try and verify it, it says "was not declared in scope
Many thanks
Adam