How can I store a sensor value?

I want to store a sensor value:

val = digitalRead(sensor);

First val = 0 when val = 1 I want to store it, indifferent the next values.

For this I want to store:

if(val == 1){
//do this
}

Do you mean that you want to take some action when val changes to 1 ?

previousVal = val;
val = digitalRead(sensor);
if (val != previousVal && val == 1)
{
  //do stuff
}

BSanyi: I want to store a sensor value:

val = digitalRead(sensor);

First val = 0 when val = 1 I want to store it, indifferent the next values.

WHERE do you want to store it?

By doing "val = digitalRead(sensor);" you already store it.

You store the result in the RAM variable named "val".

That' not enough?

You want to store it somewhere else? EEPROM? Internet website? SD card? Perhaps you better describe more detailed!

I want to save and store sensor value when is 1.

BSanyi: I want to save and store sensor value when is 1.

You save it every time you do this...

val = digitalRead(sensor);

... so we don't understand what you mean.

The sensor value is stored no matter what the value is, be it 1 or anything, so to say you want to store it when it's 1 doesn't make sense.

You need to explain some more please.

What is the point of “storing” it for only a single value? You’ll always be storing the same number…

Regards,
Ray L.