Here is my code so far. Im pretty new to the language, any help would be great
Matt
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12,11,10,9,8,7);
byte sensorInterrupt = 0; // 0 = pin 2; 1 = pin 3
byte sensorPin = 2;
// The hall-effect flow sensor outputs aproximatly one pulse per .00038L
volatile byte pulseCount;
float flowRate;
unsigned int flowGallons;
float totalGallonsA;
unsigned int totalGallonsB;
int pulseCounttot;
unsigned long oldTime;
void setup()
{
Serial.begin(9600);
lcd.begin(16, 2);
lcd.setCursor(0, 0);
lcd.print("BRADSHAW ");
lcd.setCursor(0, 1);
lcd.print("INDUSTRIES ");
delay(3000);
lcd.clear();
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
flowGallons = 0;
totalGallonsA = 0;
totalGallonsB = 0;
oldTime = 0;
pulseCounttot = 0;
// The Hall-effect sensor is connected to pin 2 which uses interrupt 0.
// Configured to trigger on a FALLING state change (transition from HIGH
// state to LOW state)
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
/**
* Main program loop
*/
void loop()
{
if((millis() - oldTime) >= 1000) // Only process counters once per second
{
// Disable the interrupt while calculating flow rate and sending the value to
// the host
detachInterrupt(sensorInterrupt);
// Because this loop may not complete in exactly 1 second intervals we calculate
// the number of milliseconds that have passed since the last execution and use
// that to scale the output.
unsigned long time = millis() - oldTime;
float time_in_sec = time / 1000;
float impuls = pulseCount * time_in_sec; //scale pulse number
float flowG = impuls * .00010; // amount of gals
float GPH = flowG * 120 ; // convert to gph
totalGallonsA =+ flowG ;
oldTime = millis();
{
}
lcd.setCursor(0,0);
lcd.print(GPH);
lcd.setCursor(6,0);
lcd.print("GPH"); // Print the integer part of the variable
lcd.setCursor(0,1);
lcd.print(totalGallonsA,4);
// Reset the pulse counter so we can start incrementing again
pulseCount = 0;
// Enable the interrupt again now that we've finished sending output
attachInterrupt(sensorInterrupt, pulseCounter, FALLING);
}
}
/**
* Invoked by interrupt0 once per rotation of the hall-effect sensor. Interrupt
* handlers should be kept as small as possible so they return quickly.
*/
void pulseCounter()
{
// Increment the pulse counter
pulseCount++;
}