Go Down

Topic: A function-definition is not allowed here before ‘{’ token? (SOLVED) (Read 418 times) previous topic - next topic

Daisy_Agullo

I have been troubled with this error when i combined my programs into one. But when i run it alone, it does run well.
The error are specifically pointed on these codes:


 //this method is for seconds
int seconds(){
    s = initialHours*3600;
    s = s+(initialMins*60);
    s = s+initialSecs;
    s = s+(millis()/1000);
    return s;
}
//this method is for hours
int hours(){
    hrs = seconds();
    hrs = hrs/3600;
    hrs = hrs%24;
    return hrs;
}
//this method is for minutes
int mins(){
    minutes = seconds();
    minutes = minutes/60;
    minutes = minutes%60;
    return minutes;
}


UKHeliBob

The problem is probably caused by a missing or misplaced curly bracket.

Please post the complete program using code tags when you do.
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Daisy_Agullo

Here is the complete code:

#include <SPI.h>     
#include <RF24.h> 
#include <nRF24L01.h>
#include <LiquidCrystal.h>

LiquidCrystal lcd(8, 6, 5, 4, 3, 2);

RF24 radio(9,10);     

const uint64_t pipe = 0xE8E8F0F0E1LL;

int msg[1];

  //for clock program
int s=0;
int sec=0;
int hrs=0;
int minutes=0;

int initialHours = 8;
int initialMins = 0;
int initialSecs = 00;

int a = 0;

void setup(){
  lcd.begin(20, 4); 
  lcd.setCursor(0,0);
  lcd.print("Now serving");
  lcd.setCursor(12,0);
  lcd.print("counter");
 

  //for seconds
int seconds(){
    s = initialHours*3600;
    s = s+(initialMins*60);
    s = s+initialSecs;
    s = s+(millis()/1000);
    return s;
}
//for hours
int hours(){
    hrs = seconds();
    hrs = hrs/3600;
    hrs = hrs%24;
    return hrs;
}
//for minutes
int mins(){
    minutes = seconds();
    minutes = minutes/60;
    minutes = minutes%60;
    return minutes;
}
 
int secs(){
    sec = seconds();
    sec = sec%60;
    return sec;
}

   
  radio.begin();                   
  radio.openReadingPipe(1, pipe); 
  radio.startListening();         
   
 }
void loop() {
  digitalClockDisplay();
  radioA(); 

}

void radioA() {   

  if(radio.available()){         
    bool done = false;   
       
 while (!done) {
     done == radio.read(msg, 1);
     radio.read(msg, 1);

    lcd.setCursor(3, 1);
    lcd.print(a);
  }
}
  if (msg[0] == 111 && msg[0] == 222) {
    a++;
    lcd.setCursor(3, 1);
    lcd.print(a);

    lcd.setCursor(15,1);
    lcd.print('1');
    delay(200);
     delay(200);
    }

  if (msg[0] == 111 && msg[0] == 333){ 
    a++;
    lcd.setCursor(3, 1);
    lcd.print(a);
   
    lcd.setCursor(15,1);
    lcd.print('2');
    delay(200);
   }
 if (msg[0] == 333){
    a=0;
    lcd.setCursor(15,1);
    lcd.print(" ");
  }

}
   

void printDigits(byte digits){
    if(digits < 10)
        lcd.print('0');
    lcd.print(digits);
}
char sep(){
    s = millis()/1000;
   if(s%2==0)
    {
        lcd.print(":");
    }
    else {
       lcd.print(" ");
   } 
}

void digitalClockDisplay(){
    lcd.setCursor(6,3);

    printDigits(hours());
    sep();

    printDigits(mins());
    sep();

    printDigits(secs());
}     


AWOL

You've got function definitions in the middle of setup.
Move them out.

Please remember to use code tags when posting code.

Silente

Never use millis() for long timers, itbis not accurate enought. You need a RTC
Dove va un numero va una variabile, una funzione e/o  un test.
Per ottenere devi spiegare

Strumenti/Formattazione automatica fino alla morte!
Cristianesimo:bibbia='C':K&R

PaulRB

Code: [Select]

done == radio.read(msg, 1);

Incorrect use of ==

Never use millis() for long timers, itbis not accurate enought. You need a RTC
You can use millis() for long timers if it is accurate enough for your project. If not, then use an RTC or NTP or GPS or...

Go Up