Skip to content

Commit fd549a0

Browse files
authored
Merge pull request #1 from hjmhardsoft/master
fix error interrupt on Arduino Leonardo Board
2 parents a578fed + 3470d1f commit fd549a0

File tree

4 files changed

+8
-8
lines changed

4 files changed

+8
-8
lines changed

examples/YF-S201/Read_Flow_Rate/Read_Flow_Rate.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// pin -> interrupt pin
1919
FlowSensor Sensor(YFS201, D2);
20-
int timebefore = 0;
20+
unsigned long timebefore = 0; // Same type as millis()
2121

2222
// Uncomment if use ESP8266 and ESP32
2323
// void IRAM_ATTR count()
@@ -44,4 +44,4 @@ void loop() {
4444
Serial.println(Sensor.getFlowRate_m());
4545
timebefore = millis();
4646
}
47-
}
47+
}

examples/YF-S201/Read_Flow_Rate_and_Volume/Read_Flow_Rate_and_Volume.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// pin -> interrupt pin
1919
FlowSensor Sensor(YFS201, D2);
20-
int timebefore = 0;
20+
unsigned long timebefore = 0; // Same type as millis()
2121

2222
// Uncomment if use ESP8266 and ESP32
2323
// void IRAM_ATTR count()
@@ -46,4 +46,4 @@ void loop() {
4646
Serial.println(Sensor.getVolume());
4747
timebefore = millis();
4848
}
49-
}
49+
}

examples/YF-S201/Read_Volume/Read_Volume.ino

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
// pin -> interrupt pin
1919
FlowSensor Sensor(YFS201, D2);
20-
int timebefore = 0;
20+
unsigned long timebefore = 0; // same type as millis()
2121

2222
// Uncomment if use ESP8266 and ESP32
2323
// void IRAM_ATTR count()
@@ -44,4 +44,4 @@ void loop() {
4444
Serial.println(Sensor.getVolume());
4545
timebefore = millis();
4646
}
47-
}
47+
}

src/FlowSensor.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ void FlowSensor::begin(void (*userFunc)(void))
7575
{
7676
pinMode(this->_pin, INPUT);
7777
digitalWrite(this->_pin, INPUT_PULLUP); // Optional Internal Pull-Up
78-
attachInterrupt(this->_pin, userFunc, RISING);
78+
attachInterrupt(digitalPinToInterrupt(this->_pin), userFunc, RISING); // For better compatibility with any board, for example Arduino Leonardo Boards
7979
}
8080

8181
/**
@@ -129,4 +129,4 @@ float FlowSensor::getFlowRate_s()
129129
float FlowSensor::getVolume()
130130
{
131131
return this->_volume;
132-
}
132+
}

0 commit comments

Comments
 (0)