Help with brackets please

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

(deleted)

Its probably something obvious but i just cant see it.

Yes , it is . It is obvious you need to spend more time organizing your code.
Go through your entire sketch and put labels on EVERY brace (ie: L-1, L-2,-L-3, R-1,R-2, R-3)
THEY SHOULD BE MATCHED PAIRS . FOR EVERY L-X, THERE SHOULD BE AN R-X
FOR EVERY L-Y, THERE SHOULD BE AN R-Y
FOR EVERY L-Z, THERE SHOULD BE AN R-Z

INDENT YOUR CODE LIKE THIS SO IT IS EASIER TO MATCH UP THE BRACES

   if pumprequired (HIGH)    //<===            NO LEFT BRACES !!!!!!!!!!!
           //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
                }

We are here to help people with programming and hardware issues, not to clean up their messes.
Or to put it another way , we are here to help people learn and to understand something that has them baffled. In your case , you already understand that you made a mistake somewhere with the braces. We are not sure if you understand that the reason this happened is your poor formatting, lack of indentation , inadequate labels, lack of labeling and last but not least lack of NOTE TAKING. Where is your notepad where your keep track of the braces ? What is the moral of this story ? Perhaps we should say that the moral of the story is , "Be organized, take notes, take your time and don't rush and last but not least, don't ask others to find your missing braces"

Would we ask YOU to go through OUR code line by line to find the missing braces ?

You can try Tools\Autoformat but that will only give you clues.

#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()
{  // ........................................L-1
  { // .......................................L-2

  Serial.println("flow Rate");
  Serial.println(flowRate);
  Serial.println("Current Flowrate);
  Serial.println(currentFlowRate);
  Serial.println("Last Flowrate");
  Serial.println(lastFlowRate);
  Serial.println();
  } // ........................................................................................R-2
 
  {// .......................................................................................L-3
  if pumprequired (HIGH)    //<===            NO LEFT BRACES !!!!!!!!!!!
           //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

etc. etc. etc.......

SEE MIKE'S SUGGESTION FURTHER ON...

I suspect the very last bracket should be moved so it is before void pulseCounter

You have used so many brackets and so much whitespace I'm surprised there is any left for the rest of us.

...R

Is my last post considered "lashing out at the next Newbie ?"

raschemmel:
Is my last post considered "lashing out at the next Newbie ?"

Yes I thought it was a bit harsh.

@Pesho77
If you put the cursor to the right of an opening bracket you will see an outline round the matching closing bracket. This will help you match them up.

Yes I thought it was a bit harsh.

I guess it must have been pretty bad if Grumpy_Mike is calling it "harsh"...

raschemmel:

Yes I thought it was a bit harsh.

I guess it must have been pretty bad if Grumpy_Mike is calling it "harsh"...

hehehe

coming from an occasional lashee of Grumpy_Mike, I was ROFL.

Though, I really do appreciate the approach it gets your attention, like a "sniff of tequila in the morning"

Keep the help coming, we are all learning...

There are lots of spurious braces '{' and '}' in that code, but there are also quite a few if/else statements which are missing them. If you don't put a compound statement after an if/else then it only applies to the immediately following statement, which can introduce some very subtle and nasty bugs. I recommend you get in the habit of always using a { } compound statement around conditional code, even when you only have a single statement in it. Also put each { and } on separate lines with matching pairs indented by the same amount and the code between them indented one extra level. If the code is more or less syntactically correct then you can use Tools / Autoformat to correct the indentation, otherwise you will need to do it manually. Once you have the indentation corrected it is very simple to scan through the code and see where the actual control structure differs from what you intended.

Also, any time you have two blank lines together, delete one of them.