Go Down

Topic: ABOUT PROGRAM (Read 854 times) previous topic - next topic

karaneee

I HAVE A PROBLEM ABOUT ARDUINO CODE.I MADE HOME SECURITY SYSTEM WİTH ARDUINO BUT I COMPILE THE PROGRAM "a function-definition is not allowed here before '{' token".IF ANYONE HELP ME I LL BE PLEASED.THE PROGRAM IS IN ATTACHMENT

PaulS

Where does your setup() function end?

Put EVERY { on a line by itself.
Put EVERY } on a line by itself.

It will be blindingly obvious what your problem is.
The art of getting good answers lies in asking good questions.

spycatcher2k

If thats your full sketch - theres your problem. - It's incomplete, functions missing, mismatched braces.
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

karaneee

Yes that is my full sketch spycatcher2k. ı agree some functions missing.but which functions missing??ı couldnt find them.and setup() function end } ı put that at te end of pin mode line pauls

UKHeliBob

Quote
setup() function end } ı put that at te end of pin mode line
Code: [Select]

pinMode(11,OUTPUT); // buzzer in digital pin 11 }

Do you mean the } that is part of the comment ?
Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

AWOL

Your for loop doesn't look good to me.

Why didn't you post your code?

spycatcher2k

Have you copied and pasted this from a site? if so, could you post the address.
Mrs Drew
-=-
http://www.uk-pcb.co.uk - UK PCB Fab Company
I will design & code for you, but I will also charge you (PM me)
If you don't like my answers, realize : I'm not being cheeky, I'm Just trying to prompt you to use your own brain/google etc.

karaneee

Your for loop doesn't look good to me.

Why didn't you post your code?
MY CODE IS TOP OF THE PAGE  UNDER MY FIRST QUESTION

groundFungus

#8
Feb 04, 2017, 03:36 pm Last Edit: Feb 04, 2017, 03:43 pm by groundfungus
Attaching the code is not the same as posting the code.  Posting the code in code tags (like the forum stickies ask, if you had read them) allows anyone to see it without having to download the code into a text editor.  Before you post the code please use autoformat (ctrl-t or Tools Auto Format) to indent the code to make it more readable.  Autoformat will also often point out errors in mismatched brackets.

AWOL

MY CODE IS TOP OF THE PAGE  UNDER MY FIRST QUESTION
Please stop SHOUTING

karaneee


karaneee

int IRpin = A0; // IR photodiode on analog pin A0

int IRemitter = 2; // IR emitter LED on digital pin 2 int ambientIR; // variable to store the IR coming from the ambient int obstacleIR; // variable to store the IR coming from the object int value[10]; // variable to store the IR values int distance; // variable that will tell if there is an obstacle or not

void setup(){

Serial.begin(9600); // initializing Serial monitor pinMode(IRemitter,OUTPUT); // IR emitter LED on digital pin 2 digitalWrite(IRemitter,LOW);// setup IR LED as off

pinMode(11,OUTPUT); // buzzer in digital pin 11 }

void loop(){

distance = readIR(5); // calling the function that will read the distance and passing the "accuracy" to it Serial.println(distance); // writing the read value on Serial monitor // buzzer(); // uncomment to activate the buzzer function }

int readIR(int times){

for(int x=0;x

//-- Function to sound a buzzer for audible measurements --//

void buzzer(){

if (distance>1){

if(distance>100){ // continuous sound if the obstacle is too close

digitalWrite(11,HIGH); }

else{ // bips faster when an obstacle approaches

digitalWrite(11,HIGH);

delay(150-distance); // adjust this value for your convenience

digitalWrite(11,LOW);

delay(150-distance); // adjust this value for your convenience } }

else{ // off if there is no obstacle

digitalWrite(11,LOW); }

}

AWOL

Code: [Select]
for(int x=0;xsee reply #5

karaneee

can you help me.I couldnt understand what you mean.if u can change the code and attach here i can try it.that is my first forum chatting.So i dont know the rules of the forum.

AWOL

The site includes a reference page where you can see how a for loop should be constructed.
The IDE is packed with worked programming examples.

Go Up