Hello everyone !
I'm anticipating my thoughts about a little project I'm doing right now, not sure if this will be really a problem in the future, hence I'm taking precautions.
I'll need to read 3 Water Flow sensors. And a MEGA 2560 board is being used. I'm using the following function to measure the volume flow :
double volumeFlow(byte sensorInterrupt,byte sensorPin, unsigned long desiredVolume){
float fatorCalibrador = 4.5;
volatile byte contaPulso = 0;
float taxaFluxo = 0.0;
unsigned int fluxoL = 0;
unsigned long totalL = 0;
unsigned long oldTime = 0;
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
attachInterrupt(sensorInterrupt, contadorPulso, FALLING);
if(desiredVolume> totalL){
if((millis() - oldTime) > 1000){
detachInterrupt(sensorInterrupt);
taxaFluxo = ((1000.0 / (millis() - oldTime)) * contaPulso) / fatorCalibrador;
oldTime = millis();
fluxoL = (taxaFluxo / 60);
totalL += fluxoL;
unsigned int fracao;
fracao = (taxaFluxo - int(taxaFluxo)) * 10;
contaPulso = 0;
attachInterrupt(sensorInterrupt, contadorPulso, FALLING);
}
}
return totalL;
}
As you can see, sensorInterrupt is also passed as parameter to attachInterrupt(). Reading more about this function (attachInterrupt) I saw a table which got me worried ![]()
pins 2, 3, 18, 19, 20, 21 are the ones which are "interrupt functional" in my board. I have pin 2 and 3 available. 18,19,20,21 are taken by a RTC shield.
DEFINING :
#define PIN_INTERRUPT_T 0 // int 0 = pin 2 I guess
#define PIN_INTERRUPT_S 1 // int 1 = pin 3 I guess
#define PINO_INTERRUPT_I 2 // No idea what int 2 is equivalent, my trouble is here.
#define PIN_SENSOR_T 6
#define PIN_SENSOR_S 5
#define PIN_SENSOR_I 8
Would I be able to call this function to the 3 Water Flow sensor? For example :
volumeFlow(0,6,desiredVolume) - This to Water Flow T
volumeFlow(1,5,desiredVolume) - This for Water Flow S
volumeFlow(2,8,desiredVolume) - This for the Water Flow I
Is there any idea to counter this possible problem? I'm afraid I did not understood the pin map right.
Really much thanks