bonjour à tous,
j'ai un problème d'interruption dans un code pour lire 5 débitmètres à effet hall sur un arduino uno et un lcd key pad.
le problème c'est que je peux lire les voie 1 et 2 qui sont sur les pin 2 et 3
mais pas les voies 3 4 5 sur les pins 11 12 13
les autres pins sont pris par le lcd.
j'ai cru voir que les pins 2 et 3 sont interrupts et pas les autres
y a t il un moyen de faire fonctionner différemment ou dois-je acheter une mega 2560 ?
#include <LiquidCrystal.h>
LiquidCrystal lcd(8, 9, 4, 5, 6, 7);
//pins
const int voie1Pin = 2; //pin location of flow rate meter on voie1 line
const int voie2Pin = 3; //pin location of flow rate meter on voie2 line
const int voie3Pin = 11; //pin location of flow rate meter on voie3 line
const int voie4Pin = 12; //pin location of flow rate meter on voie4 line
const int voie5Pin = 13; //pin location of flow rate meter on voie5 line
// variables
volatile int voie1Pulsecount; //measuring the rising edges of the signal for the voie1 line
volatile int voie2Pulsecount; //measuring the rising edges of the signal for the voie2 line
volatile int voie3Pulsecount; //measuring the rising edges of the signal for the voie3 line
volatile int voie4Pulsecount; //measuring the rising edges of the signal for the voie4 line
volatile int voie5Pulsecount; //measuring the rising edges of the signal for the voie5 line
unsigned int copyvoie1Pulsecount;
unsigned int copyvoie2Pulsecount;
unsigned int copyvoie3Pulsecount;
unsigned int copyvoie4Pulsecount;
unsigned int copyvoie5Pulsecount;
double voie1Read;
double voie2Read;
double voie3Read;
double voie4Read;
double voie5Read;
float TOTAL = 0;
/*************************************************************************/
void setup() {
Serial.begin(9600);
lcd.begin(16, 2);
lcd.clear();
lcd.setCursor(0,0);
lcd.print("Water Flow Meter");
lcd.setCursor(0,1);
lcd.print("****************");
delay(2000);
pinMode(voie1Pin, INPUT); //initializes digital pin 2 as an input
pinMode(voie2Pin, INPUT); //initializes digital pin 3 as an input
pinMode(voie3Pin, INPUT); //initializes digital pin 11 as an input
pinMode(voie4Pin, INPUT); //initializes digital pin 12 as an input
pinMode(voie5Pin, INPUT); //initializes digital pin 13 as an input
attachInterrupt(digitalPinToInterrupt(2), voie1RPM, RISING); //attaching voie1 pulse counter interrupt to pin 2
attachInterrupt(digitalPinToInterrupt(3), voie2RPM, RISING); //attaching voie2 pulse counter interrupt to pin 3
attachInterrupt(digitalPinToInterrupt(11), voie3RPM, RISING); //attaching voie3 pulse counter interrupt to pin 11
attachInterrupt(digitalPinToInterrupt(12), voie4RPM, RISING); //attaching voie4 pulse counter interrupt to pin 12
attachInterrupt(digitalPinToInterrupt(13), voie5RPM, RISING); //attaching voie5 pulse counter interrupt to pin 13
}
/************************************************************************/
void loop()
{
static unsigned long lastsecond;
if (micros() - lastsecond >= 1000000)
{
lastsecond += 1000000;
getCount();
voie1Read = (copyvoie1Pulsecount / 7.5); //(voie1 pulse frequency / 7.5Q), = flow rate in L/min
voie2Read = (copyvoie2Pulsecount / 7.5); //(voie2 pulse frequency / 7.5Q), = flow rate in L/min
voie3Read = (copyvoie3Pulsecount / 7.5); //(voie3 pulse frequency / 7.5Q), = flow rate in L/min
voie4Read = (copyvoie4Pulsecount / 7.5); //(voie4 pulse frequency / 7.5Q), = flow rate in L/min
voie5Read = (copyvoie5Pulsecount / 7.5); //(voie5 pulse frequency / 7.5Q), = flow rate in L/min
TOTAL = TOTAL + voie1Read + voie2Read + voie3Read + voie4Read + voie5Read;
Serial.print("TOTAL:");
Serial.println(TOTAL);
Serial.print ("voie1 : ");
Serial.print (voie1Read, 2); //Prints the number calculated above
Serial.println (" L/min");
Serial.print ("voie2 : ");
Serial.print (voie2Read, 2); //Prints the number calculated above
Serial.println (" L/min");
Serial.print ("voie3 : ");
Serial.print (voie3Read, 2); //Prints the number calculated above
Serial.println (" L/min");
lcd.clear();
lcd.setCursor(0,0);
lcd.print(voie1Read, 1);
lcd.setCursor(4,0);
lcd.print(voie2Read, 1);
lcd.setCursor(8,0);
lcd.print(voie3Read, 1);
lcd.setCursor(12,0);
lcd.print(voie4Read, 1);
lcd.setCursor(0,1);
lcd.print(voie5Read, 1);
lcd.setCursor(6,1);
lcd.print("Total ");
lcd.print(TOTAL/60,0);
}}
// functions -----------------------------------------------------
void voie1RPM (){ //This is the function that the interupt calls
voie1Pulsecount++;} //This function measures the rising and falling edge of the hall effect sensors signal
void voie2RPM (){ //This is the function that the interupt calls
voie2Pulsecount++;} //This function measures the rising and falling edge of the hall effect sensors signal
void voie3RPM (){ //This is the function that the interupt calls
voie3Pulsecount++;} //This function measures the rising and falling edge of the hall effect sensors signal
void voie4RPM (){ //This is the function that the interupt calls
voie4Pulsecount++;} //This function measures the rising and falling edge of the hall effect sensors signal
void voie5RPM (){ //This is the function that the interupt calls
voie5Pulsecount++;} //This function measures the rising and falling edge of the hall effect sensors signal
void getCount(){
noInterrupts();
copyvoie1Pulsecount = voie1Pulsecount;
voie1Pulsecount = 0;
copyvoie2Pulsecount = voie2Pulsecount;
voie2Pulsecount = 0;
copyvoie3Pulsecount = voie3Pulsecount;
voie3Pulsecount = 0;
copyvoie4Pulsecount = voie4Pulsecount;
voie4Pulsecount = 0;
copyvoie5Pulsecount = voie5Pulsecount;
voie5Pulsecount = 0;
interrupts();}