function-definition is not allowed here before '{' token

Hey out there!
I really got problems with Arduino. Now that I’ve managed to finally find the right port and make a LED blink using a Winows Computer and not my Mac I have trouble making a void flash command. It worked on my Mac and I’m just doing the same thing, but I don’t know why it’s not working. After compiling I just get the error-message “a function definition is not allowed here before ‘{’ token”. I’ve already moved several parts of the code, but only get other error messages. Maybe you can have a look at the code and help me? It’s a screenshot in the attachments. Please use easy english, as I’m german.

There's no closing "}" for the loop() function, only for the for loop in it

There is a closing ‘}’ for the loop, its just way down so you can’t see it on the screenshot.

Post all of your code, not a screen shot. And please use code tags.

And please post the full error message.

Sorry.
Here’s the full code:

int ledPin = 12;
void setup()
{
pinMode(ledPin, OUTPUT);
}

void loop ()
{

void flash (int duration)

{ digitalWrite (ledPin, HIGH);
delay (duration);
digitalWrite (ledPin, LOW);
delay (duration);
digitalWrite (ledPin, HIGH);
delay (duration);
digitalWrite (ledPin, LOW);
delay (duration);
digitalWrite (ledPin, HIGH);
delay (duration);
digitalWrite (ledPin, LOW);
delay (duration);
}

for (int iCounter = 0; iCounter <= 100; iCounter++)
{
flash(200);
flash(500);
flash(200);
digitalWrite (ledPin, HIGH);
delay (5000);
}

}

What are code tags?
The full error message:

CodeFlash.ino: In function ‘void loop()’:
CodeFlash:12: error: a function-definition is not allowed here before ‘}’ token is given
CodeFlash:28: error: ‘flash’ was not declared in this scope

Remove the flash function and place it after the void loop(){...} function.

void loop()
{
.
.
.
}

void flash (int duration)
{
.
.
}

Have you read the notice at the top of the board on how to use the forum?

dannable: Remove the flash function and place it after the void loop(){...} function.

True, you can't have nested functions in C/C++.

igendel,

The code listing didn't match the screen shot so who knows what's happening!

dannable:
igendel,

The code listing didn’t match the screen shot so who knows what’s happening!

Yes, well, one bug at a time :grinning:

#include “Servo.h”

Servo servo;

#define IN1 8
#define IN2 9
#define IN3 10
#define IN4 11

int koraci = 0;
boolean smjer = true;
unsigned long vrijemeZadnje = 0; // biljeziti cemo vrijeme
unsigned long vrijemeTrenutno = 0; // koje je potrebno da se
unsigned long vrijeme = 0; // se izvrsi zadani kut
int koraciPreostalo = 4095; //ovaj koracni ukupno ima 4095 koraka
int poz = 0;

const int trig = 6; // Trig na PIN11
const int echo = 5; // Echo na PIN12

int led1 = 3;
int led2 = 4;

void setup() {

servo.attach(2); // signalni PWM pin Croduina je 9
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(trig, OUTPUT);
pinMode(echo, INPUT);
Serial.begin(115200); // zapocinjem serijsku komunikaciju
pinMode(IN1, OUTPUT);
pinMode(IN2, OUTPUT);
pinMode(IN3, OUTPUT);
pinMode(IN4, OUTPUT);
Serial.println(“Mjerenje udaljenost s HC-SR04 senzorom”);
Serial.println("");
}

void loop() {
long vrijeme, udaljenost;

digitalWrite(trig, HIGH); // Slanje triga
delayMicroseconds(10); // Odaslani trig traje 10 μs = 0.1 ms
digitalWrite(trig, LOW);

vrijeme = pulseIn(echo, HIGH); // Primanje reflektiranog triga
udaljenost = (vrijeme/2) / 28; // Racunanje udaljenosti, u centimetrima
// konacna udaljenost senzora od predmeta
// u cm je varijabla “udaljenost”

Serial.print(udaljenost);
Serial.println(" cm");

delay(50); // preporucena pauza izmedu ocitanja ne bi trebala biti manja od 50ms

if(udaljenost <= 25){
digitalWrite(led1, HIGH); // pali se pocetkom dizanja donja led rasvijeta
while(koraciPreostalo > 0) // dokle je preostalo koraka do punog okreta
{
vrijemeTrenutno = micros(); //zapisi trenutno vrijeme u micro sek
if(vrijemeTrenutno - vrijemeZadnje >= 1000)
{

vrijeme = vrijeme + micros() - vrijemeZadnje;
vrijemeZadnje = micros();
koraciPreostalo–;
}
}
delay(50);

for(poz = 0; poz < 180; poz += 1) // motor se okrece od 0 do 180 stupnjeva
{ // u koracima od 1 stupnja
servo.write(poz); // kazemo servo da provjeri varijablu poz za poziciju
// cekamo 15ms da motor dode na zadanu poziciju
}
delay(2000); //nakon 5 sekundi
digitalWrite(led2, HIGH); // pali se gornja led rasvijeta
}
else {
digitalWrite(led2, LOW); // gasi se gornja led rasvijeta
smjer = !smjer; // obrni smjer
koraciPreostalo = -4095;
while(koraciPreostalo < 0) // dokle je preostalo koraka do punog okreta
{
vrijemeTrenutno = micros(); //zapisi trenutno vrijeme u micro sek
if(vrijemeTrenutno - vrijemeZadnje >= 1000)
{

vrijeme = vrijeme + micros() - vrijemeZadnje;
vrijemeZadnje = micros();
koraciPreostalo++;
}
}

for(poz = 180; poz>=0; poz-=1){
servo.write(poz);
}

delay(50);
delay(2000); //nakon 2 sekundi
digitalWrite(led1, LOW); // gasi se donja led rasvijeta
}

void stepper(int brojKoraka){
for (int x=0; x < brojKoraka; x++){
switch(koraci){
case 0:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
case 1:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, HIGH);
break;
case 2:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 3:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, HIGH);
digitalWrite(IN4, LOW);
break;
case 4:
digitalWrite(IN1, LOW);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 5:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, HIGH);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 6:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
case 7:
digitalWrite(IN1, HIGH);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, HIGH);
break;
default:
digitalWrite(IN1, LOW);
digitalWrite(IN2, LOW);
digitalWrite(IN3, LOW);
digitalWrite(IN4, LOW);
break;
}

postaviSmjer();
}
}

void postaviSmjer()
{
if(smjer==1){ koraci++; }
if(smjer==0){ koraci–; }
if(koraci>7){ koraci=0; }
if(koraci<0){ koraci=7; }
}

Error is “a function-definition is not allowed here before ‘{’ token.” for function" void stepper(int brojKoraka){ ". I tried many, many times but I didn’t fix it. Can you put this code in your arduino IDE and fix it? Thank you very much!!!

nikolakristic:
Error is “a function-definition is not allowed here before ‘{’ token.” for function" void stepper(int brojKoraka){ ". I tried many, many times but I didn’t fix it. Can you put this code in your arduino IDE and fix it? Thank you very much!!!

#include "Servo.h"

Servo servo;

#define IN1  8
#define IN2  9
#define IN3  10
#define IN4  11

int koraci = 0;
boolean smjer = true;
unsigned long vrijemeZadnje = 0;    // biljeziti cemo vrijeme
unsigned long vrijemeTrenutno = 0;  // koje je potrebno da se
unsigned long vrijeme = 0;          // se izvrsi zadani kut
int koraciPreostalo = 4095; //ovaj koracni ukupno ima 4095 koraka
int poz = 0;

const int trig = 6;        // Trig na PIN11
const int echo = 5;        // Echo na PIN12

int led1 = 3;
int led2 = 4;

void setup() {

  servo.attach(2);       // signalni PWM pin Croduina je 9
  pinMode(led1, OUTPUT);
  pinMode(led2, OUTPUT);
  pinMode(trig, OUTPUT);
  pinMode(echo, INPUT);
  Serial.begin(115200);  // zapocinjem serijsku komunikaciju
  pinMode(IN1, OUTPUT);
  pinMode(IN2, OUTPUT);
  pinMode(IN3, OUTPUT);
  pinMode(IN4, OUTPUT);
  Serial.println("Mjerenje udaljenost s HC-SR04 senzorom");
  Serial.println("");
}

void loop() {
  long vrijeme, udaljenost;

  digitalWrite(trig, HIGH);   // Slanje triga
  delayMicroseconds(10);      // Odaslani trig traje 10 μs = 0.1 ms
  digitalWrite(trig, LOW);

  vrijeme = pulseIn(echo, HIGH);       // Primanje reflektiranog triga
  udaljenost = (vrijeme / 2) / 28;     // Racunanje udaljenosti, u centimetrima
  // konacna udaljenost senzora od predmeta
  // u cm je varijabla "udaljenost"

  Serial.print(udaljenost);
  Serial.println(" cm");

  delay(50);                            // preporucena pauza izmedu ocitanja ne bi trebala biti manja od 50ms

  if (udaljenost <= 25) {
    digitalWrite(led1, HIGH);           // pali se pocetkom dizanja donja led rasvijeta
    while (koraciPreostalo > 0) // dokle je preostalo koraka do punog okreta
    {
      vrijemeTrenutno = micros(); //zapisi trenutno vrijeme u micro sek
      if (vrijemeTrenutno - vrijemeZadnje >= 1000)
      {

        vrijeme = vrijeme + micros() - vrijemeZadnje;
        vrijemeZadnje = micros();
        koraciPreostalo--;
      }
    }
    delay(50);

    for (poz = 0; poz < 180; poz += 1)  // motor se okrece od 0 do 180 stupnjeva
    { // u koracima od 1 stupnja
      servo.write(poz);                   // kazemo servo da provjeri varijablu poz za poziciju
      // cekamo 15ms da motor dode na zadanu poziciju
    }
    delay(2000);  //nakon 5 sekundi
    digitalWrite(led2, HIGH);             // pali se gornja led rasvijeta
  }
  else {
    digitalWrite(led2, LOW);  // gasi se gornja led rasvijeta
    smjer = !smjer; // obrni smjer
    koraciPreostalo = -4095;
    while (koraciPreostalo < 0) // dokle je preostalo koraka do punog okreta
    {
      vrijemeTrenutno = micros(); //zapisi trenutno vrijeme u micro sek
      if (vrijemeTrenutno - vrijemeZadnje >= 1000)
      {

        vrijeme = vrijeme + micros() - vrijemeZadnje;
        vrijemeZadnje = micros();
        koraciPreostalo++;
      }
    }

    for (poz = 180; poz >= 0; poz -= 1) {
      servo.write(poz);
    }

    delay(50);
    delay(2000);  //nakon 2 sekundi
    digitalWrite(led1, LOW);              // gasi se donja led rasvijeta
  }
}

void stepper(int brojKoraka) {
  for (int x = 0; x < brojKoraka; x++) {
    switch (koraci) {
      case 0:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, HIGH);
        break;
      case 1:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, HIGH);
        break;
      case 2:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, LOW);
        break;
      case 3:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN3, HIGH);
        digitalWrite(IN4, LOW);
        break;
      case 4:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
      case 5:
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2, HIGH);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
      case 6:
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
      case 7:
        digitalWrite(IN1, HIGH);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, HIGH);
        break;
      default:
        digitalWrite(IN1, LOW);
        digitalWrite(IN2, LOW);
        digitalWrite(IN3, LOW);
        digitalWrite(IN4, LOW);
        break;
    }

    postaviSmjer();
  }
}

void postaviSmjer()
{
  if (smjer == 1) {
    koraci++;
  }
  if (smjer == 0) {
    koraci--;
  }
  if (koraci > 7) {
    koraci = 0;
  }
  if (koraci < 0) {
    koraci = 7;
  }
}

Hi there, now we have a problem. Function-definition is not allowed here before ‘{’ token is not resolved. We have the code to see.

#include <SoftwareSerial.h>
SoftwareSerial SIM900 (0,1);
char inchar;

boolean lockLow = true;
boolean takeLowTime;
boolean Check_PIR;
int CalibrationTime = 30;
int led = 13;
int sensor = 3;
int sensor_Value;
int buzzer = 9;
int sms_count = 0;

void setup()
{
Serial.begin(9600);
pinMode(led, OUTPUT);
digitalWrite(led, LOW);
pinMode(buzzer, OUTPUT);
digitalWrite(buzzer, LOW);
pinMode(sensor, INPUT);
digitalWrite(sensor, LOW);
pinMode(9, OUTPUT);
digitalWrite(9, LOW);
delay(100);
digitalWrite(9, HIGH);
delay(2500);

Serial.print(“Calibrating Sensor”);
for(int i = 0; i<CalibrationTime; i++)
{
Serial.print(".");
delay(1000);
}
Serial.print(“done”);
Serial.println(“SENSOR ACTIVE”);
delay(50);

SIM900.begin(9600);
SIM900.println(“AT+CMGF=1”);
delay(200);
}

void loop()
{

if(digitalRead(sensor) == HIGH)
{
digitalWrite(led, HIGH);
digitalWrite(buzzer, LOW);

if(lockLow)
{
lockLow = false;
Serial.println("-----");
Serial.println (“detectd at”);
delay(50);
}
}
if(digitalRead(sensor) == LOW)
{
digitalWrite(led, LOW);
digitalWrite(buzzer, HIGH);

if(takeLowTime)
{
takeLowTime = false;
lockLow=true;
Serial.print("ended at ");
delay(50);
}
}

Serial.println(sensor_Value);
Serial.println(sms_count);
delay(1000);

void Check_SMSReceive()
{
SIM900.println(“AT+CNMI= 2,2,0,0,0”);
delay(200);
Serial.println(“Waiting for SMS…”);
delay(200);
{
if(SIM900.available() >0)
{
inchar=SIM900.read();
if (inchar==’*’)
{
delay(10);
inchar=SIM900.read();
if (inchar==‘o’)
{
delay(10);
inchar=SIM900.read();
if (inchar==‘n’)
{
digitalWrite(led, HIGH);
delay(900);
digitalWrite(led, LOW);
}
Serial.println( “Message received to Activate Alarm” );
SIM900.println(“AT+CMGD=1,4”);
}
}
}
}
}

void Check_PIR()
{
sensor_value=digitalRead(sensor);
if((sensor_value==HIGH) && (sms_count < 1))
{
digitalWrite(buzzer,HIGH);
delay(2000);
digitalWrite(buzzer,LOW);

SendTextMessage();
}}
void SendTextMessage()
{
SIM900.println(“AT+CMGF=1”);
delay(200);
SIM900.println(“AT+CMGS=“0962143035”\r”);
delay(200);
SIM900.println(“Movement detected”);
Serial.println( “Movement detected” );
delay(200);
SIM900.println((char)26);
delay(200);
sms_count++;
}

}

Please see my please.

   Serial.println(sensor_Value);
   Serial.println(sms_count);
   delay(1000);


 void Check_SMSReceive()

Where does loop() end?

Please remember to use code tags blah blah blah

Hi, Welcome to the forum.

Please read the first post in any forum entitled how to use this forum. http://forum.arduino.cc/index.php/topic,148850.0.html then look down to item #7 about how to post your code. It will be formatted in a scrolling window that makes it easier to read.

Can you please post a copy of your circuit, in CAD or a picture of a hand drawn circuit in jpg, png?

Thanks.. Tom.. :)

i have a similar problem, i tried to change everything i think that could be wrong but still not works!.
BIOS2.INO:

//Include Section

//Keyboard Files

#include <PS2Keyboard.h>

//TV Output Files

#include <TVout.h>
#include <font4x6.h>
#include <font6x8.h>
#include <font8x8.h>
#include <font8x8ext.h>
#include <fontALL.h>
#include "logo.h"

//Program Files

#include "hcmd2.h"

/* 0 = DEC 48
 * 1 = DEC 49
 * 2 = DEC 50
 * 3 = DEC 51
 * 4 = DEC 52
 * 5 = DEC 53
 * 6 = DEC 54
 * 7 = DEC 55
 * 8 = DEC 56
 * 9 = DEC 57
 */



PS2Keyboard Key;
TVout TV;
char KeyRead;
char KeyBuffer;
bool loopContinue;

void setup() {
  //pinMode(4,INPUT);
  //pinMode(5,INPUT);
  TV.begin(NTSC,128,64);
  TV.select_font(font4x6);
  delay(100);
  TV.bitmap(TV0.hres()/2,TV0.vres()/2,logo);
  delay(1000);
  TV.clear_screen();
  TV.println("COPYRIGHT H4CK SOFTWARE 2017-2019");
  delay(100);
  TV.println("FourBIOS V1.02");
  delay(100);
  TV.print("Starting Up: ");
  delay(500);
  TV.print(".");
  delay(500);
  TV.print(".");
  delay(500);
  TV.println(".");
  Key.begin(2,3);
}

void loop() {
  RESET0:
  TV.print("HCMD:/>");
  RESET1:
  loopContinue = true;
  while (loopContinue == true){
    if (Key.available()) {
     KeyRead = Key.read();
     if (KeyRead == PS2_ENTER) { 
          cmdProcess(KeyBuffer);
          loopContinue = false;
        }else{
          KeyBuffer = KeyRead;
          TV.print(KeyRead); 
          TV.println(" < Execute?");
      }
    }
  }
}

Error:

exit status 1
a function-definition is not allowed here before '{' token

i attach the original files if that can help.

don´t mind me, problem solved!

BIOS2.ino (1.4 KB)

hcmd2.h (3.77 KB)

logo.cpp (5.32 KB)

logo.h (109 Bytes)

Life Lesson! I forgot to close the void cmdProcess() function that is declared in hcmd2.h So Don't mind me.