Go Down

Topic: error: expected constructor, destructor, or type conversion (Read 11345 times) previous topic - next topic

rikkifirmansyah

anyone help please i have a errors in this program

Code: [Select]
#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
Code: [Select]
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


Tom Carpenter

#1
Jul 03, 2012, 06:31 pm Last Edit: Jul 03, 2012, 06:33 pm by TCWORLD Reason: 1
Code: [Select]

//***************************************************************************
// 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:
Code: [Select]
#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...
~Tom~


E-Xen

Please, who can help me with this problem.

Code: [Select]

//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.

christop

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

Go Up