error: expected constructor, destructor, or type conversion

anyone help please i have a errors in this program

#include <SD.h>
#include <LiquidCrystal.h> 

int CS_pin = 53; 

volatile long lastSave = 0; // time value of last save. Relies on realtime clock
volatile long lcdTimeOut = 0; //timer for turning off LCD
volatile int saveInterval = 10; //time between saves (units = seconds, not millis)
volatile int lcdInterval= 60; //time to wait before shutting off LCD (units = seconds)
const int reps = 9; //number of temp readings to average per channel (count from zero)

LiquidCrystal lcd(8,3,4,5,6,7); //RS,EN,DB4,DB5,DB6,DB7


#define muxA0 15 
#define muxA1 16 
#define muxA2 17 
#define tempPin 0 
#define lcdLight 9
#define button1 2                   
int button1INT = 0; 

#define aref_voltage 1.1 

const int chs = 8; 
const int numReadings = 10; 
long tempInArray[numReadings][chs]; 
int index = 0; 
long total[chs]; 
float averages[chs]; 

//***************************************************************************************** 
void error(char *str)
{
  lcd.clear();
  lcd.home();
  lcd.print("error: ");
  lcd.print(str);
  while(1);
}

//****************************************************************************************

void setup(void)
{
  Serial.begin(9600);
  analogReference(INTERNAL1V1); 
  pinMode(muxA2, OUTPUT); 
  pinMode(muxA1, OUTPUT); 
  pinMode(muxA0, OUTPUT); 
  pinMode(button1, INPUT); 
  digitalWrite(lcdLight, HIGH); 

  lcd.begin(20,4);  //(columns,rows) 
  lcd.setCursor(0,0);
  lcd.print("Tugas Akhir");
  lcd.setCursor(0,1);
  lcd.print("Miniatur Hujan Salju");
  delay (5000);
  lcd.clear();
  
  lcd.setCursor(0,0);
  lcd.print ("Oleh: ");
  lcd.setCursor(0,1);
  lcd.print ("Mochamad Rikki Firmansyah");
  lcd.setCursor(0,2);
  lcd.print ("dan");
  lcd.setCursor(0,3);
  lcd.print ("Ichsan T Primanizar");
  delay (5000);
  lcd.clear();
  //**************************************************************************
  //initialize the SD card
  if (!SD.begin(CS_pin))
    {
      lcd.setCursor(0,0);
      lcd.println ("Card Failure ");
      delay (3000);
      lcd.clear();
      return;
    }
      lcd.println ("Card Ready");
      delay (3000);
      lcd.clear();
      
  //Membaca Konfigurasi command.txt
  File commandFile = SD.open ("COMMAND.txt");
  if (commandFile)
  {
    lcd.setCursor(0,0);
    lcd.println ("Membaca File");
    delay (3000);
    lcd.clear();
    while (commandFile.available());
  }
  else
  {
    lcd.println ("File Tdk Trsedia");
    delay (3000);
    lcd.clear();
  }
  
  
  //Write log file
  File logFile = SD.open ("LOG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.println (", , , , , , , ,");
    String header = "Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7, Ch8";
    logFile.println (header);
    logFile.close();
  }
  else
  {
    lcd.setCursor (0,0);
    lcd.print  ("data failed");
    delay (2000);
    lcd.clear();
  }
  
  
}

  //***************************************************************************
  // Have user select save-data interval and lcd timeout 
  // These two lines call sub-routines that are down at the bottom of this file
  saveInterval = saveInt(); //call saveInt sub-function and return value
  lcdInterval = lcdInt();   //call lcdInt sub-function and return value
  //*******************************************************************************
  
  // initialize analog temperature value array

  for (int channel = 0; channel < chs; channel++) { 
    for (int i = 0; i < numReadings; i++) {
      tempInArray[i][channel] = 0; 
    }
  }

i had a errors is

sketch_jul03c:169: error: expected constructor, destructor, or type conversion before '=' token
sketch_jul03c:170: error: expected constructor, destructor, or type conversion before '=' token
sketch_jul03c:175: error: expected unqualified-id before 'for'
sketch_jul03c:175: error: expected constructor, destructor, or type conversion before '<' token
sketch_jul03c:175: error: expected constructor, destructor, or type conversion before '++' token
//***************************************************************************
// Have user select save-data interval and lcd timeout 
// These two lines call sub-routines that are down at the bottom of this file
saveInterval = saveInt(); //call saveInt sub-function and return value
lcdInterval = lcdInt();   //call lcdInt sub-function and return value
//*******************************************************************************

// initialize analog temperature value array

for (int channel = 0; channel < chs; channel++) { 
  for (int i = 0; i < numReadings; i++) {
    tempInArray[i][channel] = 0; 
  }
}

You can’t just declare stuff like that outside a function. You need to put it inside a function such as void loop(){}, or void setup(){};

I think this is what you were trying to do:

#include <SD.h>
#include <LiquidCrystal.h> 

int CS_pin = 53; 

volatile long lastSave = 0; // time value of last save. Relies on realtime clock
volatile long lcdTimeOut = 0; //timer for turning off LCD
volatile int saveInterval = 10; //time between saves (units = seconds, not millis)
volatile int lcdInterval= 60; //time to wait before shutting off LCD (units = seconds)
const int reps = 9; //number of temp readings to average per channel (count from zero)

LiquidCrystal lcd(8,3,4,5,6,7); //RS,EN,DB4,DB5,DB6,DB7


#define muxA0 15 
#define muxA1 16 
#define muxA2 17 
#define tempPin 0 
#define lcdLight 9
#define button1 2                   
int button1INT = 0; 

#define aref_voltage 1.1 

const int chs = 8; 
const int numReadings = 10; 
long tempInArray[numReadings][chs]; 
int index = 0; 
long total[chs]; 
float averages[chs]; 

//***************************************************************************************** 
void error(char *str)
{
  lcd.clear();
  lcd.home();
  lcd.print("error: ");
  lcd.print(str);
  while(1);
}

//****************************************************************************************

void setup(void)
{
  Serial.begin(9600);
  analogReference(INTERNAL1V1); 
  pinMode(muxA2, OUTPUT); 
  pinMode(muxA1, OUTPUT); 
  pinMode(muxA0, OUTPUT); 
  pinMode(button1, INPUT); 
  digitalWrite(lcdLight, HIGH); 

  lcd.begin(20,4);  //(columns,rows) 
  lcd.setCursor(0,0);
  lcd.print("Tugas Akhir");
  lcd.setCursor(0,1);
  lcd.print("Miniatur Hujan Salju");
  delay (5000);
  lcd.clear();

  lcd.setCursor(0,0);
  lcd.print ("Oleh: ");
  lcd.setCursor(0,1);
  lcd.print ("Mochamad Rikki Firmansyah");
  lcd.setCursor(0,2);
  lcd.print ("dan");
  lcd.setCursor(0,3);
  lcd.print ("Ichsan T Primanizar");
  delay (5000);
  lcd.clear();
  //**************************************************************************
  //initialize the SD card
  if (!SD.begin(CS_pin))
  {
    lcd.setCursor(0,0);
    lcd.println ("Card Failure ");
    delay (3000);
    lcd.clear();
    return;
  }
  lcd.println ("Card Ready");
  delay (3000);
  lcd.clear();

  //Membaca Konfigurasi command.txt
  File commandFile = SD.open ("COMMAND.txt");
  if (commandFile)
  {
    lcd.setCursor(0,0);
    lcd.println ("Membaca File");
    delay (3000);
    lcd.clear();
    while (commandFile.available());
  }
  else
  {
    lcd.println ("File Tdk Trsedia");
    delay (3000);
    lcd.clear();
  }


  //Write log file
  File logFile = SD.open ("LOG.csv", FILE_WRITE);
  if (logFile)
  {
    logFile.println (", , , , , , , ,");
    String header = "Ch1, Ch2, Ch3, Ch4, Ch5, Ch6, Ch7, Ch8";
    logFile.println (header);
    logFile.close();
  }
  else
  {
    lcd.setCursor (0,0);
    lcd.print  ("data failed");
    delay (2000);
    lcd.clear();
  }
  
//Moved brace from here...

  //***************************************************************************
  // Have user select save-data interval and lcd timeout 
  // These two lines call sub-routines that are down at the bottom of this file
  saveInterval = saveInt(); //call saveInt sub-function and return value
  lcdInterval = lcdInt();   //call lcdInt sub-function and return value
  //*******************************************************************************
  
  // initialize analog temperature value array
  
  for (int channel = 0; channel < chs; channel++) { 
    for (int i = 0; i < numReadings; i++) {
      tempInArray[i][channel] = 0; 
    }
  }
  
} //To here...

ok thanks

Please, who can help me with this problem.

//Añadimos la librería servo.h
#include <Servo.h>

//Creamos un objeto Servo
Servo servo1;

int grados = 90; // Grados del servo
int servoPin = 9; // Pin para el Servo
boolean estadoP1; // Estado del pulsador Player 1
boolean estadoP2; // Estado del pulsador Player 1
int rep1 = 0; // Variable para primer ciclo For
int rep2 = 0; // Variable para segundo ciclo For
int numAl = 0; // Numero aleatorio
int time = 0; // Tiempo ejecucion
int time2 = 0; // Tiempo ejecucion 2
int contP1; // Contador pulsos P1
int contP2; // Contador pulsos P2
int freqJuego = 1000; // Tiempo LED apagados
int freqLed = 500; // Tiempo LED encendidos

//Pines para los LED del juego
int pinLedGeneral = 3;
int pinLedErrorP1 = 4;
int pinLedErrorP2 = 5;
int pinLedAciertoP1 = 6;
int pinLedAciertoP2 = 7;
int pinLedP1 = 8;
int pinLedP2 = 10;
int botonP1 = 11;
int botonP2 = 12;

void setup() 
{
  servo1.attach(servoPin); // Asignamos servoPin como Servo
  servo1.write(0); // Lo mandamos al grado 0
  delay(800); // Le damos tiempo a que llegue
  servo1.write(179); // Lo mandamos al grado 179
  delay(800); // Le damos tiempo a que llegue
  servo1.write(grados); // Lo llevamos al punto de partida
  //Establecemos la configuracion de lo Pines
  pinMode(pinLedGeneral, OUTPUT);
  pinMode(pinLedErrorP1, OUTPUT);
  pinMode(pinLedErrorP2, OUTPUT);
  pinMode(pinLedAciertoP1, OUTPUT);
  pinMode(pinLedAciertoP2, OUTPUT);
  pinMode(pinLedP1, OUTPUT);
  pinMode(pinLedP2, OUTPUT);
  pinMode(botonP1, INPUT);
  pinMode(botonP2, INPUT);
}

void loop() 
{
  numAl = random(0, 99); // Generamos un numero aleatorio
  time = millis(); // Almacenamos el tiempo
  contP1 = 0; // Establecemos el contaador a cero
  contP2 = 0; // Establecemos el contaador a cero
  
  // Comprobamos que la velocidad del juego no sea demasiado alta
  if (freqJuego < 50)
  {
    Ganador();
  }
  
  // Disminuimos tiempos
  freqJuego = (freqJuego - 10);
  freqLed = (freqLed - 4);
  // Encendemos un LED y comprobamos si
  // pulsa durante el LED encendido el jugador correcto
  while ((time2 - time) <= freqLed)
  {
    time2 = millis();
    if ((numAl % 2) == 0) // Led Player 1
    {
      digitalWrite(pinLedP1, HIGH);
      digitalWrite(pinLedP2, LOW);
      estadoP1 = digitalRead(botonP1);
      estadoP2 = digitalRead(botonP2);
      if ((estadoP1 == true) & (contP1 == 0))
      {
        BienP1();
      }
      if ((estadoP2 == true) & (contP2 == 0))
      {
        P2Error();
      }
    }
    // Led Player 2
    else
    {
      digitalWrite(pinLedP1, LOW);
      digitalWrite(pinLedP2, HIGH);
      estadoP1 = digitalRead(botonP1);
      estadoP2 = digitalRead(botonP2);
      if ((estadoP2 == true) & (contP2 == 0))
      {
        BienP2();
      }
      if ((estadoP1 == true) & (contP1 == 0))
      {
        P1Error();
      }
    }
  }
}

// Apagamos los LED
digitalWrite(pinLedP1, LOW);
digitalWrite(pinLedP2, LOW);

//Comprobamos que nadie pulse mientras estan apagados
time = millis();
while ((time2 - time) <= freqJuego)
{
  time2 = millis();
  estadoP1 = digitalRead(botonP1);
  estadoP2 = digitalRead(botonP2);
  if ((estadoP1 == true) & (contP1 == 0))
  {
    P1Error();
  }
  if ((estadoP2 == true) & (contP2 == 0))
  {
    P2Error();
  }
}

// Rutina para comprobar si ha gandao P1
void GanaPlayer1()
{
  if (grados == 170)
  {
    digitalWrite(pinLedAciertoP1, HIGH);
    digitalWrite(pinLedAciertoP2, LOW);
    digitalWrite(pinLedErrorP1, LOW);
    digitalWrite(pinLedErrorP2, LOW);
    Ganador();
  }
}

// Rutina para comprobar si ha gandao P2
void GanaPlayer2()
{
  if (grados == 10)
  {
    digitalWrite(pinLedAciertoP1, LOW);
    digitalWrite(pinLedAciertoP2, HIGH);
    digitalWrite(pinLedErrorP1, LOW);
    digitalWrite(pinLedErrorP2, LOW);
    Ganador();
  }
}

// Rutina cuado pulsa correctamente P1
void BienP1()
{
  contP1++;
  grados = (grados + 10);
  servo1.write(grados);
  digitalWrite(pinLedErrorP1, LOW);
  digitalWrite(pinLedAciertoP1, HIGH);
  GanaPlayer1();
}

// Rutina cuado pulsa correctamente P2
void BienP2()
{
  contP2++;
  grados = (grados - 10);
  servo1.write(grados);
  digitalWrite(pinLedErrorP2, LOW);
  digitalWrite(pinLedAciertoP2, HIGH);
  GanaPlayer2();
}

// Rutina cuado pulsa mal P1
void P1Error()
{
  contP1++;
  grados = (grados - 10);
  servo1.write(grados);
  digitalWrite(pinLedAciertoP1, LOW);
  digitalWrite(pinLedErrorP1, HIGH);
  GanaPlayer2();
}

// Rutina cuado pulsa mal P2
void P2Error()
{
  contP2++;
  grados = (grados + 10);
  servo1.write(grados);
  digitalWrite(pinLedAciertoP2, LOW);
  digitalWrite(pinLedErrorP2, HIGH);
  GanaPlayer1();
}

// Rutina cuando alguien gana el juego
void Ganador()
{
  for (rep1=0; rep1<3; rep1++)
  {
    servo1.write(0);
    for (rep2=10; rep2<250; rep2++)
    {
      analogWrite(pinLedGeneral, rep2);
      delay(3);
    }
    servo1.write(179);
    
    for (rep2=250; rep2>10; rep2--)
    {
      analogWrite(pinLedGeneral, rep2);
      delay(3);
    }
  }
  
  digitalWrite(pinLedAciertoP1, LOW);
  digitalWrite(pinLedAciertoP2, LOW);
  digitalWrite(pinLedErrorP1, LOW);
  digitalWrite(pinLedErrorP2, LOW);
  digitalWrite(pinLedGeneral, LOW);
  grados = (90);
  servo1.write(grados);
  delay(5000);
  freqJuego = 100;
  freqLed = 500;
}

This is the problem:

game.ino:108:13: error: expected constructor, destructor, or type conversion before ‘(’ token
game.ino:109:13: error: expected constructor, destructor, or type conversion before ‘(’ token
game.ino:112:1: error: ‘time’ does not name a type
game.ino:113:1: error: expected unqualified-id before ‘while’

This report would have more information with
“Show verbose output during compilation”
enabled in File > Preferences.

E-Xen: read the thread that you hijacked. Your program has the same problem and the same solution.

#include <avr/io.h>
#include <avr/sleep.h>
#include <avr/interrupt.h>
#define PCINT_IN PORTB0
#define LED_PORT PORTB1

void init_pcint()
{
PCMSK0 = (1<<PCINT2); //pin(PB0) registers that enable or disable pin-change interrupts on individual pins
PCICR =(1<<PCIE2); //PORTB enables pci2
sei(); //start up global interrupt
}

int main()
{
DDRB |= ((1 << DDB5)); //configured with internal pull-up resistor
PORTB = (1<<PCINT_IN);
init_pcint();
while (1)
{
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();

// Must enable or can’t wake!
sei();
sleep_cpu();

sleep_disable();

// like toggle a bit.
PINB |= 0x01;
}
}

void interruptFunction() {
sleep_disable();
}
void SetupInterrupts(void)
{
//Setup for Interrupt

EIMSK = (1<<PCIE1); //Enable interrupt for flag PCIF1
}
int LED = 13;

void setup() {
sleep_enable();
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
pinMode(LED, OUTPUT);
pinMode(2,INPUT);

}

void loop() {
digitalWrite(LED, HIGH);
delay(5000);
digitalWrite(LED, LOW);
sleep_cpu();
}
ISR(PCINT2_vect) //portB pin chance interrupt
{
PINB = (1<<LED); //Pin changed - toggle an led on pb1
}

Error compiling for board Arduino/Genuino Mega or Mega 2560.

can anyone help me on this error there's no problem in my program i guess the problem in on the board any help will be appreciated thanks!

there's no problem in my program

Really? Then why did the compiler have problems with it?

i guess the problem in on the board

Just how did you arrive at THAT conclusion?

Why did you pick this thread to tack onto? It IS in the Programming section, which means that YOU need to POST YOUR CODE!

#include "Stepper.h"
#include "IRremote.h"
/----- Variables, Pins -----/
#define STEPS 32 // Number of steps per revolution of Internal shaft
int Steps2Take; // 2048 = 1 Revolution
int receiver = 6; // Signal Pin of IR receiver to Arduino Digital Pin 6
/-----( Declare objects )-----/
// Setup of proper sequencing for Motor Driver Pins
// In1, In2, In3, In4 in the sequence 1-3-2-4
Stepper small_stepper(STEPS, 8, 10, 9, 11);
IRrecvirrecv(receiver); // create instance of 'irrecv'
decode_results results; // create instance of 'decode_results'
void setup()
{
irrecv.enableIRIn(); // Start the receiver
}
void loop()
{
if (irrecv.decode(&results)) // have we received an IR signal?
{
switch(results.value)
{
case 0xFF629D: // UP button pressed
small_stepper.setSpeed(500); //Max seems to be 700
Steps2Take = 2048; // Rotate CW
small_stepper.step(Steps2Take);
delay(2000);
break;
case 0xFFA857: // DOWN button pressed
small_stepper.setSpeed(500);
Steps2Take = -2048; // Rotate CCW
small_stepper.step(Steps2Take);
delay(2000);
break;
}
irrecv.resume(); // receive the next value
}
}/* --end main loop -- */

please help me to solve the error

CODE-1.txt (3.6 KB)

Ragib301:
please help me to solve the error

What problem?

Post the exact error message you are seeing.

TheMemberFormerlyKnownAsAWOL:
What problem?

Post the exact error message you are seeing.

Arduino: 1.8.7 (Windows 10), Board: “Arduino/Genuino Uno”

RG_19008:158:17: error: expected constructor, destructor, or type conversion before ‘(’ token

digitalWrite(trigpin ,LOW);//Clears the trigpin

^

RG_19008:159:22: error: expected constructor, destructor, or type conversion before ‘(’ token

delayMicroseconds(2);

^

RG_19008:161:17: error: expected constructor, destructor, or type conversion before ‘(’ token

digitalWrite(trigpin, HIGH);//Sets the trigpin on HIGH state for 10 Micro seconds

^

RG_19008:162:22: error: expected constructor, destructor, or type conversion before ‘(’ token

delayMicroseconds(10);

^

RG_19008:163:17: error: expected constructor, destructor, or type conversion before ‘(’ token

digitalWrite(trigpin, LOW);

^

RG_19008:165:5: error: ‘duration’ does not name a type

duration = pulseIn(echopin ,HIGH); //Reads the echopin, returns the sound wave travel time in Micro seconds

^

RG_19008:167:5: error: ‘distance’ does not name a type

distance = duration*0.034/2; //Calculating the distance

^

RG_19008:169:3: error: expected unqualified-id before ‘for’

for(x=0;x<=90;x++)

^

RG_19008:169:11: error: ‘x’ does not name a type

for(x=0;x<=90;x++)

^

RG_19008:169:17: error: ‘x’ does not name a type

for(x=0;x<=90;x++)

^

RG_19008:182:1: error: expected declaration before ‘}’ token

}

^

exit status 1
expected constructor, destructor, or type conversion before ‘(’ token

This report would have more information with
“Show verbose output during compilation”
option enabled in File → Preferences.

You’ve got code that isn’t in a function.

It isn’t clear to me where that code belongs.

Common compiler errors caused by mismatched brackets:

"does not name a type" or
"expected declaration before" or
"expected unqualified-id before" or
"expected initializer before"or
"expected constructor, destructor, or type conversion before '(' token"
Usually means you forgot a '{' or put in an extra '}' in the previous function. Since all of the open brackets have been closed, the compiler is looking for further global declarations (variables or functions). If it finds something that looks like executable code instead of a global declaration it emits an error. Make sure that the brackets in the preceding function are in matching pairs '{' followed by '}'.

"a function-definition is not allowed here before '{' token"
(can cause: "'functionName' was not declared in this scope")
Usually means you forgot a '}' or put in an extra '{' in the previous function. Since a set of brackets has not been closed yet the compiler is looking for more code to put in the function. You can't declare a function inside a function so if the compiler finds a function declaration it emits an error. Make sure that the brackets in the preceding function are in matching pairs '{' followed by '}'.

"expected '}' at end of input"
Usually means you forgot a '}' or put in an extra '{' in the last function in the sketch. Since a set of brackets has not been closed yet, the compiler is looking for more code to put in the function. When it hits the end of the file instead, it emits an error. Make sure that the brackets in the last function are in matching pairs '{' followed by '}'.

"expected primary-expression before '}' token"
Usually means you have an incomplete statement before a '}'. The block statement (between '{' and matching '}') can only contain complete statements. Complete statements always end with ';' (or '}' for a block statement).

I’m not sure where the problem is
[expected constructor, destructor, or type conversion before ‘(’ token]

const byte pinsetOut[3]={11,12,13}; //
const byte pinsetIn[3]={8,5,2}; //
int value[3]={1,1,1}; //
#define bibibi 10 //
#define Restpin 9 //
int Reset; //

void setup()
{
Serial.begin(9600); //
for(int i=0;i<3;i++) //
{
pinMode(pinsetOut*,OUTPUT); //*
_ pinMode(pinsetIn*,INPUT); //_
_ digitalWrite(pinsetOut,LOW); //
}
pinMode(Restpin,INPUT); //
pinMode(bibibi,OUTPUT); //
}
void loop()
{
bool founwork=true;
while(founwork==true)
for(int i=0;i<3;i++)
{
value=digitalRead(pinsetIn);
Serial.print(pinsetIn);
Serial.print(":");
Serial.print(value);
Serial.print("\t");*_

_ if (value*==0)
{
digitalWrite(pinsetOut,HIGH);
i=2;
founwork=false;
}
}
Serial.println("");
}
Buzzer(2);
while(digitalRead(Resetpin)==HIGH);
founwork=true;
for(int i=0;i<3,i++)
{
value=1;
digitalWrite(pinsetOut,LOW);
}
void Buzzer(int a) //
{
for(int i=0;i<a;i++) //
{
tone(bibibi,HIGH);
delay(100);//延遲0.1秒*

* tone(bibibi,LOW);
delay(100);//延遲0.1秒*

* }
}*_

@howareyouimfinenothank
It's because of all the italics : D Learn how to use code tags.

Seriously now, it looks like your loop() ends after the Serial.println() so most of the code after that is illegal.

howareyouimfinenothank:
I'm not sure where the problem is

The full error message I get when I try to verify your sketch says that the error is detected at line 43, character 7:

sketch_dec25a:43:7: error: expected constructor, destructor, or type conversion before '(' token

Buzzer(2);
      ^




I already told you that the error "Usually means you forgot a '{' or put in an extra '}' in the previous function. Since all of the open brackets have been closed, the compiler is looking for further global declarations (variables or functions). If it finds something that looks like executable code instead of a global declaration it emits an error. Make sure that the brackets in the preceding function are in matching pairs '{' followed by '}'."

It looks like maybe you put in an extra, unintended, '}' here:


founwork=false;
  }
 }
 Serial.println("");