I'm trying to make a program in Arduino Uno which can calculate the time interval (in mills) between two HIGH states of the same input .
int V1;
long int time1;
long int time2;
long int interval1;
long int lastvalue;
void setup (){
pinMode(2, INPUT);
Serial.begin(9600);
}
void loop() {
V1 = digitalRead(2); // reading state of input 2
if (V1 ==HIGH) {
Serial.print("Event occure: ");
time1 = millis();
Serial.print(time1);
delay(500);
interval1= time1 - lastvalue;
Serial.print("difference between previous time1 and current time1 (in mills): ");
Serial.print(interval1);
}
}
Can you give me a hint about how to calculate the difference between current value of time1 and last value (current time1-1) of time1?
Thank you!
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…