Skip to main content
. 2025 Feb 26;25(5):1420. doi: 10.3390/s25051420
1   const byte interruptPin_1 = 2;
2   const byte interruptPin_2 = 3;
3   
4   volatile unsigned long minElapsed = 100L;
5   volatile unsigned long elapsedTime;
6   volatile unsigned long previousTime = millis();
7   
8   unsigned long t0 = 0L;
9   unsigned long t1 = 0L;
10   
11   int TA;
12   int TR;
13   
14   
15   bool teste = false;
16   
17   void setup() {
18    Serial.begin(115200);
19
20    pinMode(interruptPin_1, INPUT_PULLUP);
21    pinMode(interruptPin_2, INPUT_PULLUP);
22    attachInterrupt(digitalPinToInterrupt(interruptPin_1),tapete,CHANGE);
23    attachInterrupt(digitalPinToInterrupt(interruptPin_2),saco,CHANGE);
24   
25   }
26   
27   void loop(){
28    if (teste){
29     Serial.print(TA);
30     Serial.print(“;”);
31     Serial.println(TR);
32     teste = false;
33    }
34   }
35   
36   void tapete(){
37    elapsedTime = millis() − previousTime;
38    if (elapsedTime > minElapsed){   //true interrupt
39     previousTime = millis();
40     delay(5);
41     if (digitalRead(interruptPin_1)){
42     if (t0){
43        Serial.println(“Contato Tapete—Fim”);
44        TA = t1 − t0;
45        TR = previousTime − t1;
46        teste = true;
47        t0 = 0L;
48        t1 = 0L;
49     }
50     else {
51        Serial.println(“Contato Tapete—Inicio”);
52        t0 = 0L;
53        t1 = 0L;
54     }
55     }
56     else {
57     if (!t0){
58        Serial.println(“Saida Tapete—T0”);
59         t0 = previousTime;
60      }
61      }
62     }
63   }
64
65   void saco(){
66     elapsedTime = millis() − previousTime;
67     if (elapsedTime > minElapsed){  //true interrupt
68      previousTime = millis();
69      delay(5);
70      if (digitalRead(interruptPin_2)){
71      if (t0){
72        Serial.println(“Contato Saco—T1”);
73        t1 = previousTime;
74      }
75     }
76    }
77 }