I think I am into something here:
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
LiquidCrystal_I2C lcd(0x27,16,2);
byte sensorA = 0;
byte sensorB = 1;
byte sensorPinA = 2;
byte sensorPinB = 3;
float calibrationFactor = 50;
volatile byte pulseCount;
float flowRate;
unsigned int turFuel;
unsigned int returFuel;
unsigned long oldTime;
void setup()
{
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 1);
lcd.print(" ");
Serial.begin(38400);
pinMode(sensorA, INPUT);
pinMode(sensorB, INPUT);
pulseCount = 0;
flowRate = 0.0;
turFuel = 0;
returFuel = 0;
oldTime = 0;
attachInterrupt(sensorA, pulseCounter, FALLING);
attachInterrupt(sensorB, pulseCounter, FALLING);
}
//hovedprogrammet i loop.
void loop()
{
if((millis() - oldTime > 1000))
{
detachInterrupt(sensorA);
detachInterrupt(sensorB);
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
oldTime =millis();
flowRate = (sensorA - sensorB) / 8500;
unsigned int frac;
Serial.print(int(flowRate));
Serial.print(".");
frac = (flowRate - int(flowRate)) * 10;
Serial.print(frac, DEC) ;
Serial.print(" ");
Serial.print(flowRate);
lcd.setCursor(0, 0);
lcd.print(" ");
lcd.setCursor(0, 0);
lcd.print("Flow: ");
if(int(flowRate) < 10)
{
lcd.print(" ");
}
lcd.print((int)flowRate);
lcd.print('.');
lcd.print(frac, DEC) ;
lcd.print(" L");
lcd.print("/min");
pulseCount = 0;
attachInterrupt(sensorA, pulseCounter, FALLING);
attachInterrupt(sensorB, pulseCounter, FALLING);
}
void pulseCounter()
{
pulseCount++;
}
Or what do you think? I get a problem in one of the last lines in this code. Can anyone help with that problem?
Regards, Fredrik.