Expected initializer or function-definition is not allowed? Wont work either way

Hello all! This is my first time posting to the forum and I would like to say thanks for all the help you guys have given me through this forum! The following is a simple code I am writing to control my RIMS system. It use to have manual ball valves and PIDS running the heating elements but I thought I would try my luck at automating it. When I try to compile this code, however, it it gives me the message [expected initializer before ‘lcd’] and when I add an initializer, a semicolon, it gives me [ a function-definition is not allowed here before ‘{’ token]. This happens everywhere I have a function and the next line following. This question has me stuck! Any help would be greatly appreciated! Please help me get it to compile…

[code]
/*The following program is a program to control my RIMS(Remote Infusion Circulating Mash System) that has 5 DC pumps operated by relays.*/
/* It has three different processes (MASH,HLT,WORTCHILL) that will turn on different valves in a series to direct the Wort for the different processes*/
/* The MASH and HLT functions each turn on respective heating elements to control the temperature for each cycle*/
/* The display shows the current process and temperature as well the remaining time after it is entered for each process. */

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <max6675.h>


const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'.', '0', '#', 'D'}
};

byte rowPINS[ROWS] = {9, 8, 7, 6};
byte colPINS[COLS] = {5, 4, 3, 2};
Keypad kpd = Keypad(makeKeymap(keys), rowPINS, colPINS, ROWS, COLS);
LiquidCrystal_I2C lcd(0x27, 20, 4); // set the LCD address to 0x20 for a 16 chars and 2 line display

//setup vars

int cho = 0;
int PROCESS = 0;
int pump = 20;
int valve1 = 21;
int valve2 = 22;
int valve3 = 23;
int valve4 = 24;
int valve5 = 25;
int thermo_gnd_pins = 45;
int thermo_vcc_pins = 47;
int thermoDO1_pin  = 14;
int thermoCS1_pin  = 15;
int thermoCLK1_pin = 16;
int thermoDO2_pin  = 17; //check
int thermoCS2_pin  = 18; //check
int thermoCLK2_pin = 19;
int ALARM = 20;
int Levelswitch = 22;
int MASHHE = 23;
int HLTHE = 24;

long int set1;
long int set2;
long int set3;
long int set4;
long int j;
int t1, t2, t3, t4, t5, t6;
int r1, r2, r3;
String hours;
String minutes;
String seconds;

boolean brew = true; // condition for alarm

char key;
String r[8];

MAX6675 thermocouple1(thermoCLK1_pin, thermoCS1_pin, thermoDO1_pin);// first thermocouple
MAX6675 thermocouple2(thermoCLK2_pin, thermoCS2_pin, thermoDO2_pin);// 2nd thermocouple

void setup()
{
  lcd.init(); // initialize the lcd
  pinMode(pump, OUTPUT);
  pinMode(valve1, OUTPUT);
  pinMode(valve2, OUTPUT);
  pinMode(valve3, OUTPUT);
  pinMode(valve4, OUTPUT);
  pinMode(valve5, OUTPUT);
  pinMode(Levelswitch, INPUT);
  pinMode(MASHHE, OUTPUT);
  pinMode(HLTHE, OUTPUT);
  pinMode(thermo_vcc_pins, OUTPUT);
  pinMode(thermo_gnd_pins, OUTPUT);
  pinMode(ALARM, INPUT);
  pinMode(A4, OUTPUT);
  digitalWrite(thermo_vcc_pins, HIGH);
  digitalWrite(thermo_gnd_pins, LOW);


  float setBREWTime()  // the problem lies between here and lcd.init() statement everywhere I have a function

  lcd.init();
  lcd.backlight(); lcd.print("Set BREW Time");
  lcd.setCursor(0, 3);

  lcd.clear();
  lcd.print("HH:MM:SS");
  lcd.setCursor(0, 2);
  int i = 0;

  while (1) {
    key = kpd.getKey();

    char j;

    if (key != NO_KEY) {

      lcd.setCursor(j, 1);

      lcd.print(key);

      r[i] = key - 48;
      i++;
      j++;

      if (j == 2 || j == 5)
      {
        lcd.print(":"); j++;
      }
      delay(500);
    }

    if (key == '#')
    {
      key = 0;
      break;
    }
  }          //end while-loop
  lcd.clear();
}            //end setup


float Brewtime()


setBREWTime()

for (int i = 0; i < 6; i++) // this for loop is used to get the value of the feeding time and print it serially
{
  Serial.print(r[i]);
  Serial.println();
}

hours = String (r[0]) + String (r[1]) ; //combining two separate int values of r[0] and r[1] into one string and save it to "hours"
minutes = String (r[2]) + String (r[3]) ;  //combining two separate int values of r[2] and r[3] into one string and save it to "minutes"
seconds = String (r[4]) + String (r[5]) ;  //combining two separate int values of r[4] and r[5] into one string and save it to "seconds"


set1 = (hours.toInt() * 3600); //converting hours into seconds
set2 = (minutes.toInt() * 60);  //converting minutes into seconds
set3 = seconds.toInt();
set4 = (hours.toInt() * 3600) + (minutes.toInt() * 60) + seconds.toInt(); //adding set1, set2 and set3 together in set4
Serial.print("set4");
Serial.print(set4);
Serial.println();

lcd.setCursor(0, 3);
lcd.print("PROCESS START");
delay(2000);
lcd.clear();

for (long int j = set4; j >= 0; j--) // this for-loop is used to decrease the total time in seconds
{
  Serial.println(j);

  lcd.setCursor(0, 1); lcd.print("PROCESS:MASH");
  lcd.setCursor(14, 0); lcd.print("TEMP:");

  long int HH = j / 3600; // converting the remaining time into remaining hours
  lcd.setCursor(0, 3);
  Serial.println(HH);
  if (HH < 10) {
    lcd.print('0');
  }
  lcd.print(HH);
  lcd.print(":");

  long int MM = (j - (HH * 3600)) / 60 ; //converting the remaining time into remaining minutes
  lcd.setCursor(3, 3);
  Serial.println(MM);
  if (MM < 10) {
    lcd.print('0');
  }
  lcd.print(MM);
  lcd.print(":");

  long int SS = j - ((HH * 3600) + (MM * 60)); //converting the remaining time into remaining seconds
  lcd.setCursor(6, 3);
  Serial.println(SS);
  if (SS < 10) {
    lcd.print('0');
  }
  lcd.print(SS);
  delay(1000);

  if (digitalRead(A3) == 1) {
    break;
  }

  if (j == 0)

  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("CHANGE PROCESS");
    lcd.setCursor(3, 1);
    lcd.print("-Ring-Ring-");

    for (int k = 0; k <= 50; k++) //this for loop is used for the buzzer to beep 50 times as the timer reaches zero
    {
      digitalWrite(ALARM, HIGH);
      delay(300);
      digitalWrite(ALARM, LOW);
      delay(300);
      if ((key == '#') {
      break;
    }
  } //end alarm for-loop
}   //end j==0

}     //end second for-loop

void loop()



float MASH()
{
  char key = kpd.getKey();
  lcd.clear();
  lcd.setCursor(4, 2); lcd.print("PROCESS: MASH");
  lcd.setCursor(13, 0); lcd.print("MASH TEMP = ");
  lcd.setCursor(14, 0); lcd.print(thermocouple1.readFahrenheit());
  Serial.print("Temp: ");
  Serial.println(thermocouple1.readFahrenheit());

  Brewtime();

  digitalWrite(pump, HIGH);
  digitalWrite(valve1, LOW);
  digitalWrite(valve2, HIGH);
  digitalWrite(valve3, LOW);
  digitalWrite(valve4, HIGH);
  digitalWrite(valve5, LOW);

  if (pump = 1) {
  }
  // if temprature goes above 150F, turn the relay ON
  if (thermocouple1.readFahrenheit() > 152 < 148) {
    digitalWrite(MASHHE, LOW);// set pin 10 LOW
  } else {
    digitalWrite(MASHHE, HIGH);// set pin 10 HIGH
  }


} // end MASH FUNCTION


float HLT()

lcd.clear();
lcd.setCursor(4, 2); lcd.print("PROCESS: HLT");
lcd.setCursor(13, 0); lcd.print("HLT TEMP = ");
lcd.setCursor(13, 1); lcd.print(thermocouple2.readFahrenheit());
Serial.print("Temp: ");
Serial.println(thermocouple2.readFahrenheit());
{
  Brewtime();

  digitalWrite(pump,   LOW);
  digitalWrite(valve1, LOW);
  digitalWrite(valve2, LOW);
  digitalWrite(valve3, LOW);
  digitalWrite(valve4, LOW);
  digitalWrite(valve5, LOW);

  if (Levelswitch = 1) // if temprature goes above 202F, turn the relay ON
  {
    if (thermocouple2.readFahrenheit() > 205 < 202)
    {
      digitalWrite(HLTHE, LOW);// set pin 10 LOW
    } else {
      digitalWrite(HLTHE, HIGH);// set pin 10 HIGH
    }
  }
}
}// END HLT FUNCTION

float WORTCHILL();
{
  lcd.clear();
  lcd.setCursor(0, 2); lcd.print("PROCESS:WORT CHILLER");

  digitalWrite(pump, HIGH);
  digitalWrite(valve1, LOW);
  digitalWrite(valve2, HIGH);
  digitalWrite(valve3, LOW);
  digitalWrite(valve4, HIGH);
  digitalWrite(valve5, LOW);

  if (pump = 1) {

    //
    digitalWrite(HLTHE, LOW);// set pin 10 LOW
  }
}// END WORTCHILL FUNCTION

while (cho == 0)


{
  key = kpd.getKey();
  switch (key)
  {
    case NO_KEY:
      break;
    case 'A':
      MASH();
      lcd.clear();
      cho = 1;
      break;
    case 'B':
      HLT();
      cho = 2;
      break;
    case 'C':
      WORTCHILL();
      lcd.clear();
      cho = 3;
      break;
  } // end case
}// end while cho=0
}// end setup


void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
  asm volatile (" jmp 0");
}

[/code]

 float setBREWTime()

You are trying to declare the function setBREWTime inside the setup function, and you missed the ; as well.

You do the same further on, but I'm reading this on my phone and I lost track of where the function ends so I'm not sure about that.

This compiles maybe a new starting point for you…

/*The following program is a program to control my RIMS(Remote Infusion Circulating Mash System) that has 5 DC pumps operated by relays.*/
/* It has three different processes (MASH,HLT,WORTCHILL) that will turn on different valves in a series to direct the Wort for the different processes*/
/* The MASH and HLT functions each turn on respective heating elements to control the temperature for each cycle*/
/* The display shows the current process and temperature as well the remaining time after it is entered for each process. */

#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad.h>
#include <max6675.h>


const byte ROWS = 4;
const byte COLS = 4;
char keys[ROWS][COLS] = {
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'.', '0', '#', 'D'}
};

byte rowPINS[ROWS] = {9, 8, 7, 6};
byte colPINS[COLS] = {5, 4, 3, 2};

Keypad kpd = Keypad(makeKeymap(keys), rowPINS, colPINS, ROWS, COLS);

LiquidCrystal_I2C lcd(0x3F, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);  //  check your I2C address

#define  LCD_ROWS  4
#define  LCD_COLS  20

//setup vars

int cho = 0;
int PROCESS = 0;
int pump = 20;
int valve1 = 21;
int valve2 = 22;
int valve3 = 23;
int valve4 = 24;
int valve5 = 25;

int thermo_gnd_pins = 45;
int thermo_vcc_pins = 47;
int thermo1DO_pin  = 14;
int thermo1CS_pin  = 15;
int thermo1CLK_pin = 16;
int thermo2DO_pin  = 17; //check
int thermo2CS_pin  = 18; //check
int thermo2CLK_pin = 19;

int ALARM = 20;
int Levelswitch = 22;
int MASHHE = 23;
int HLTHE = 24;

long int set1;
long int set2;
long int set3;
long int set4;
long int j;
int t1, t2, t3, t4, t5, t6;
int r1, r2, r3;
String hours;
String minutes;
String seconds;

boolean brew = true; // condition for alarm

char key;
String r[8];


MAX6675 thermocouple1(thermo1CLK_pin, thermo1CS_pin, thermo1DO_pin);// first thermocouple
MAX6675 thermocouple2(thermo2CLK_pin, thermo2CS_pin, thermo2DO_pin);// 2nd thermocouple
                        ///fiddled the call on thermos....maybe unnecessary
void setup()
{

  pinMode(pump, OUTPUT);
  pinMode(valve1, OUTPUT);
  pinMode(valve2, OUTPUT);
  pinMode(valve3, OUTPUT);
  pinMode(valve4, OUTPUT);
  pinMode(valve5, OUTPUT);
  pinMode(Levelswitch, INPUT);
  pinMode(MASHHE, OUTPUT);
  pinMode(HLTHE, OUTPUT);
  pinMode(thermo_vcc_pins, OUTPUT);
  pinMode(thermo_gnd_pins, OUTPUT);
  pinMode(ALARM, INPUT);
  pinMode(A4, OUTPUT);
  digitalWrite(thermo_vcc_pins, HIGH);
  digitalWrite(thermo_gnd_pins, LOW);


setBREWTime() ;  ///  re assigned the functions at this call

 lcd.begin(LCD_COLS, LCD_ROWS);
 
  lcd.print("Set BREW Time");
  lcd.setCursor(0, 3);
                                      ///          maybe a bit of delay here to get the message
  lcd.clear();
  lcd.print("HH:MM:SS");
  lcd.setCursor(0, 2);
  int i = 0;

  while (1)
  {
    key = kpd.getKey();

    char j;

    if (key != NO_KEY)
    {

      lcd.setCursor(j, 1);

      lcd.print(key);

      r[i] = key - 48;
      i++;
      j++;

      if (j == 2 || j == 5)
      {
        lcd.print(":"); 
        j++;
      }
      delay(500);
    }

    if (key == '#')
    {
      key = 0;
      break;
    }
  }          //end while-loop
  lcd.clear();
}            //end setup


float Brewtime()
{   
  // ??????????whatever needs to go here
}

 float setBREWTime()
{
for (int i = 0; i < 6; i++) // this for loop is used to get the value of the feeding time and print it serially
{
  Serial.print(r[i]);
  Serial.println();
}

hours = String (r[0]) + String (r[1]) ; //combining two separate int values of r[0] and r[1] into one string and save it to "hours"
minutes = String (r[2]) + String (r[3]) ;  //combining two separate int values of r[2] and r[3] into one string and save it to "minutes"
seconds = String (r[4]) + String (r[5]) ;  //combining two separate int values of r[4] and r[5] into one string and save it to "seconds"


set1 = (hours.toInt() * 3600); //converting hours into seconds
set2 = (minutes.toInt() * 60);  //converting minutes into seconds
set3 = seconds.toInt();
set4 = (hours.toInt() * 3600) + (minutes.toInt() * 60) + seconds.toInt(); //adding set1, set2 and set3 together in set4
Serial.print("set4");
Serial.print(set4);
Serial.println();

lcd.setCursor(0, 3);
lcd.print("PROCESS START");
delay(2000);
lcd.clear();

for (long int j = set4; j >= 0; j--) // this for-loop is used to decrease the total time in seconds
{
  Serial.println(j);

  lcd.setCursor(0, 1); 
  lcd.print("PROCESS:MASH");
  lcd.setCursor(14, 0); 
  lcd.print("TEMP:");

  long int HH = j / 3600; // converting the remaining time into remaining hours
  lcd.setCursor(0, 3);
  Serial.println(HH);
  if (HH < 10) 
  {
    lcd.print('0');
  }
  lcd.print(HH);
  lcd.print(":");

  long int MM = (j - (HH * 3600)) / 60 ; //converting the remaining time into remaining minutes
  lcd.setCursor(3, 3);
  Serial.println(MM);
  if (MM < 10)
  {
    lcd.print('0');
  }
  lcd.print(MM);
  lcd.print(":");

  long int SS = j - ((HH * 3600) + (MM * 60)); //converting the remaining time into remaining seconds
  lcd.setCursor(6, 3);
  Serial.println(SS);
  if (SS < 10) 
  {
    lcd.print('0');
  }
  lcd.print(SS);
  delay(1000);

  if (digitalRead(A3) == 1)
  {
    break;
  }

  if (j == 0)

  {
    lcd.clear();
    lcd.setCursor(0, 0);
    lcd.print("CHANGE PROCESS");
    lcd.setCursor(3, 1);
    lcd.print("-Ring-Ring-");

    for (int k = 0; k <= 50; k++) //this for loop is used for the buzzer to beep 50 times as the timer reaches zero
    {
      digitalWrite(ALARM, HIGH);
      delay(300);
      digitalWrite(ALARM, LOW);
      delay(300);
      if (key == '#')
      {
      break;
    }
  } //end alarm for-loop
}   //end j==0

}     //end second for-loop
}                                                    ///****
void loop()
{
  readKeys();          // whatever function needs
}

float MASH()                           
{
  char key = kpd.getKey();
  lcd.clear();
  lcd.setCursor(4, 2); lcd.print("PROCESS: MASH");
  lcd.setCursor(13, 0); lcd.print("MASH TEMP = ");
  lcd.setCursor(14, 0); lcd.print(thermocouple1.readFahrenheit());
  Serial.print("Temp: ");
  Serial.println(thermocouple1.readFahrenheit());

  Brewtime();

  digitalWrite(pump, HIGH);
  digitalWrite(valve1, LOW);
  digitalWrite(valve2, HIGH);
  digitalWrite(valve3, LOW);
  digitalWrite(valve4, HIGH);
  digitalWrite(valve5, LOW);

  if (pump = 1) 
  {
    
  // if temprature goes above 150F, turn the relay ON
  if (thermocouple1.readFahrenheit() > 152 < 148)
  {
    digitalWrite(MASHHE, LOW);// set pin 10 LOW
  } else 
  {
    digitalWrite(MASHHE, HIGH);// set pin 10 HIGH
  }

  }                                                                         //  *************
} // end MASH FUNCTION

float HLT()
{
lcd.clear();
lcd.setCursor(4, 2); 
lcd.print("PROCESS: HLT");
lcd.setCursor(13, 0); 
lcd.print("HLT TEMP = ");
lcd.setCursor(13, 1); 
lcd.print(thermocouple2.readFahrenheit());
Serial.print("Temp: ");
Serial.println(thermocouple2.readFahrenheit());
{
  Brewtime();

  digitalWrite(pump,   LOW);
  digitalWrite(valve1, LOW);
  digitalWrite(valve2, LOW);
  digitalWrite(valve3, LOW);
  digitalWrite(valve4, LOW);
  digitalWrite(valve5, LOW);

  if (Levelswitch = 1) // if temprature goes above 202F, turn the relay ON
  {
    if (thermocouple2.readFahrenheit() > 205 < 202)
    {
      digitalWrite(HLTHE, LOW);// set pin 10 LOW
    } 
    else 
    {
      digitalWrite(HLTHE, HIGH);// set pin 10 HIGH
    }
  }
}
}// END HLT FUNCTION

float WORTCHILL()
{
  lcd.clear();
  lcd.setCursor(0, 2); lcd.print("PROCESS:WORT CHILLER");

  digitalWrite(pump, HIGH);
  digitalWrite(valve1, LOW);
  digitalWrite(valve2, HIGH);
  digitalWrite(valve3, LOW);
  digitalWrite(valve4, HIGH);
  digitalWrite(valve5, LOW);

  if (pump = 1)
  {
    digitalWrite(HLTHE, LOW);// set pin 10 LOW
  }
}                    // END WORTCHILL FUNCTION


void readKeys()
{
while (cho == 0)
{
  key = kpd.getKey();
  switch (key)
  {
    case NO_KEY:
      break;
    case 'A':
      MASH();
      lcd.clear();
      cho = 1;
      break;
    case 'B':
      HLT();
      cho = 2;
      break;
    case 'C':
      WORTCHILL();
      lcd.clear();
      cho = 3;
      break;
  } // end case
}// end while cho=0
}


void software_Reset() // Restarts program from beginning but does not reset the peripherals and registers
{
  asm volatile (" jmp 0");
}

you’ll need to check through lin by line to compare the diff to your code…good luck

float HLT()


lcd.clear();
lcd.setCursor(4, 2); lcd.print("PROCESS: HLT");
lcd.setCursor(13, 0); lcd.print("HLT TEMP = ");
lcd.setCursor(13, 1); lcd.print(thermocouple2.readFahrenheit());
Serial.print("Temp: ");
Serial.println(thermocouple2.readFahrenheit());
{
  Brewtime();

Did you intend to put that LCD code INSIDE your 'HLT' function body? If so, it goes AFTER the opening bracket '{'. In any case, it can't go between the function name and the function body like you have it.

Thanks to everyone who responded so fast! I really appreciate everyone's help and will try to implement these changes and get the program running. I'll post it whenever I figure it out. Thanks guys!

Thanks again so much guys! Once you helped me get it to compile I finally was able to see how the structure worked. The code ended up working exactly as I hoped for. I ended up having to remove the BrewTime functions and putting them into the MASH and HLT functions in order to get the timer value inside the functions how I needed them. I also will end up adding a P.I.D. function for the heating elements whenever the 240v relay kicks off and I am only running them on 120v. The code ended up being much too long to post again in the forum but if anyone is interested I'll be glad to email it to you!

You can attach code to a post if is too large to post online. Click on reply instead of using quick reply and you will see the attach option.

groundFungus:
You can attach code to a post if is too large to post online. Click on reply instead of using quick reply and you will see the attach option.

Or if you are already in the middle of a Quick Reply and decide you need to attach a file, click on the "Preview" button. That shows a preview of your post and, below that, the full "Reply" dialog, including the 'attachments' parts.