Can some one please help me with brackets, i know there's an error somewhere but i can't get it to compile so i cant see where
the sketch
#include <SimpleTimer.h>
#include <TFT.h> // Arduino TFT library
#include <SPI.h>
// pin definition for the Uno
#define cs 10
#define dc 9
#define rst 8
// create an instance of the library
TFT TFTscreen = TFT(cs, dc, rst);
// Declare ins for H Bridge
const int motor1Pin = 5; // H-bridge leg 1 (pin 2, 1A)
const int motor2Pin = 6; // H-bridge leg 2 (pin 7, 2A)
const int enablePin = 7; // H-bridge enable pin
byte sensorInterrupt = 0; // 0 = pin 2; 1 = pin 3
byte sensorPin = 2;
// The hall-effect flow sensor outputs approximately 4.5 pulses per second per
// litre/minute of flow.
float calibrationFactor = 4.5;
volatile byte pulseCount;
float flowRate;
float lastFlowRate;
float currentFlowRate;
unsigned int flowMilliLitres;
unsigned long oldTime;
int pumpBlocked;
int rppin = 3; // the pin that the RimsPump is attached to
int PumpRunning ;
int pumpRequired= 14;
void setup()
{
// set pump required to input
pinMode (pumpRequired, INPUT);
// set all the other pins you're using as outputs:
pinMode(motor1Pin, OUTPUT);
pinMode(motor2Pin, OUTPUT);
pinMode(enablePin, OUTPUT);
// set enablePin LOW so that motor is off:
digitalWrite(enablePin, LOW);
timer.setInterval (500 , enablePin, HIGH);// Turn ball valve every 1/2 second
timer.setinterval (250, enablePin, LOW) ; // Turn ball valve off every 1/4 second
TFTscreen.begin();
TFTscreen.background(0, 0, 0);
TFTscreen.stroke(255, 255, 255);
TFTscreen.setTextSize(2);
// declare pin 3 to be an output:
pinMode(rppin, OUTPUT);
// Initialize a serial connection for reporting values to the host
Serial.begin(9600);
pinMode(sensorPin, INPUT);
digitalWrite(sensorPin, HIGH);
pulseCount = 0;
flowRate = 0.0;
flowMilliLitres = 0;
oldTime = 0;
currentFlowRate = flowRate;
pumpBlocked = 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()
{
{
Serial.println("flow Rate");
Serial.println(flowRate);
Serial.println("Current Flowrate);
Serial.println(currentFlowRate);
Serial.println("Last Flowrate");
Serial.println(lastFlowRate);
Serial.println();
}
{
if pumprequired (HIGH)
//Pulse pin to slowly run up pump
if (flowRate > 3){ // Ltr's / Min
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
}
//Pulse pin to slow pump speed
else if (flowRate < 3){
digitalWrite(motor1Pin, HIGH); // set leg 1 of the H-bridge high
digitalWrite(motor2Pin, LOW); // set leg 2 of the H-bridge low
}
}
void pumpTimeOut(){ // set the time out for blocked pumps
}
{
if (currentFlowRate <= lastFlowRate - 2 ){
PumpRunning = 0 , // Stop pump
pumpBlocked +1 ,// Add 1 to pump blocked
// Close ball valve
digitalWrite(motor1Pin, LOW); // set leg 1 of the H-bridge low
digitalWrite(motor2Pin, HIGH); // set leg 2 of the H-bridge high
timerId = timer.setTimeout(10000, pumpTimeout) ;
PumpRunning = 1;}
}
// set text colour to suit pump speed
{
if (flowRate < 1 ){ TFTscreen.stroke (255, 153, 51);} // Light orange text
else if (flowRate >= 1 && flowRate < 2){ TFTscreen.stroke (255, 128, 0); } // Orange text
else if (flowRate >= 2 && flowRate < 2.5 ){ TFTscreen.stroke (178, 255, 102);} // Light green text
else if (flowRate > 2.5 && flowRate == 3 ){ TFTscreen.stroke (0, 255, 0); } // Green text
else if (flowRate > 3 ){ TFTscreen.stroke (255, 0, 0); } // Red text
}
{
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. We also apply the calibrationFactor to scale the output
// based on the number of pulses per second per units of measure (litres/minute in
// this case) coming from the sensor.
flowRate = ((1000.0 / (millis() - oldTime)) * pulseCount) / calibrationFactor;
// Note the time this processing pass was executed. Note that because we've
// disabled interrupts the millis() function won't actually be incrementing right
// at this point, but it will still return the value it was set to just before
// interrupts went away.
oldTime = millis();
// Divide the flow rate in litres/minute by 60 to determine how many litres have
// passed through the sensor in this 1 second interval, then multiply by 1000 to
// convert to millilitres.
flowMilliLitres = (flowRate / 60) * 1000;
unsigned int frac;
frac = (flowRate - int(flowRate)) * 10;
}
{
TFTscreen.stroke(255, 255, 255);
TFTscreen.text("FLOW RATE:", 0, 0);
if (int(flowRate) < 10)
TFTscreen.text("", 0, 30);
TFTscreen.print((int)flowRate); // Print the integer part of the variable
TFTscreen.text(".", 0, 30); // Print the decimal point
TFTscreen.print(frac, DEC) ; // Print the fractional part of the variable
TFTscreen.text(" L/Min", 55, 30);
TFTscreen.text("PUMP BLOCKED", 0,70);
TFTscreen.text("",0,90);
TFTscreen.print(pumpblocked);
TFTscreen.text("TIMES",30,90);
}
{
if (pumpblocked == 0) {TFTscreen.background(0,255,0) ; } // Green background
else if (pumpblocked >=1 && pumpblocked <=2){ TFTscreen.background(255, 128, 0); } // Orange background
else if (pumpblocked >=3 ){ TFTscreen.background(255,0,0); } // Red background
}
{
// 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++;
}
}
Its probably something obvious but i just cant see it.
TIA
Pesh