analog read only once a time I was working on a school project in where i need to analog read form A0 and test if my value is bigger than some boundary (500 for example) to return 0 or 1 
well with a simple code in an infinity loop 
this will keep returning 0000000 and 1111111 for infinity 
but need 1 only once when my analog value passes from 900 to 300 for example and I dont need once when It stays at 300. 
and the same problem for 0 : I need 0 only once when it passes from 300 to 900 and not 0 from staying at 900
thanks for help in advance
Store the current read value AND the previous value and check if a border has been crossed.

E.g. 

if Previous value &lt; 500 AND current value &gt;= 500
   Going from 0 to 1 -&gt; return/send 1
else if Previous value &gt;= 500 AND current value &lt; 500
   Going from 1 to 0 -&gt; return/send 0


However, to make it more complicated, you might have debouncing effects, e.g. what if the value moves for some time around 500 to go to 200... It will still result in possibly many 0 and 1 boundary changes.

You can fix this easily by using two different value: by checking going lower &lt; 490 and going higher > 510 (or any other appropriate value. Or use a debounce mechanism where it should be below or above the 500 value for a minimum (but short) amount of time.