change of value of a variable in a specific time

i am increasing the count of a variable, i need to make the variable value zero if there is no change in last 1sec of time, can anyone tell me how to go about it ??

There’s no such thing as an “if” loop.

Post your code.

Something like that maybe

unsigned long lastChange;

void ChangeValue()
{
  value = something;
  lastChange = millis();
}

void loop()
{
  if ( millis() - lastChange >= 1000 )
    value = 0;
}

AWOL:
There’s no such thing as an “if” loop.

Post your code.

int Sh1_data = 2;
int Sh1_latch = 3;
int Sh1_clock = 4;
int c = 0;
int c1 = 0;

int seq1[7] = {
0,7,14,28,56,112,224};
int seq2[7] = {
224,112,56,28,14,7,0};

void setup()
{
Serial.begin(9600);
pinMode(Sh1_data,OUTPUT);
pinMode(Sh1_latch,OUTPUT);
pinMode(Sh1_clock,OUTPUT);

}

void loop()
{

float GX = analogRead(A0);
float GZ = analogRead(A1);
Serial.print("Gyro X value = “);
Serial.print(GX);
delay(5);
Serial.print(” : ");
delay(5);
Serial.print("Gyro Z value = ");
Serial.println(GZ);
Serial.print(c);
delay(50);
if (GX < 150)
{
c++;
if (c==3)
{
for (int n=0; n<7; n++)
{
digitalWrite(Sh1_latch, LOW);
shiftOut(Sh1_data, Sh1_clock, MSBFIRST, seq2[n]);
digitalWrite(Sh1_latch, HIGH);
delay(75);
}
c=0;
}
}
if (GX > 300)
{
c1++;
if (c1==3)
{
for (int n1=0; n1<7; n1++)
{
digitalWrite(Sh1_latch, LOW);
shiftOut(Sh1_data, Sh1_clock, LSBFIRST, seq2[n1]);
digitalWrite(Sh1_latch, HIGH);
delay(75);
}
c1=0;
}
}
}

in the above code , i need to make the value of ‘c’ zero when there is no change for 1sec. ?? can you help me ???

Yes, I'd go with the approach in reply #2.

(I live in hope that when I write "post your code", the implied "...between code tags" is recognised)

guix: Something like that maybe

unsigned long lastChange;

void ChangeValue() {  value = something;  lastChange = millis(); }

void loop() {  if ( millis() - lastChange >= 1000 )    value = 0; }

Tanq very much, perfectly apt for my situation :)