error: expected unqualified-id before "if"

Hello everyone, so im pretty new on the arduino coding and im trying to make an arduino controlled elevator. however i got stucked on one part.

i got this error message after "if (buttonState2 == HIGH) {" part.
exit status 1
expected unqualified-id before 'if'

Can someone please help me to get over this? I can explain in more detail if you needed to.

Thanks in advance!

[I've added the whole code after your answers guys =)]

Son_Hali_V1.2.Konum.ino (7.99 KB)

Do an autoformat on your code and let it line up the indention and it might make it easier to find. What line does it complain about?

digitalRead(hallSensorPin1);
if (digitalRead(hallSensorPin1) == LOW) {  
    Konum=1;

Why the spurrious extra digitalRead before the if?

void up(){
   motor1.run(FORWARD);
   delay(100);
}

Where is motor1 defined?

                                               /// hall effect ve motor çalismasi \\\
                                                         // ASANSOR 1 \\

This is a PEBKAC issue. Stop with the \\ unless you know what you are doing. You don't.

buttonState1 = digitalRead(btn1);
buttonState2 = digitalRead(btn2);
buttonState3 = digitalRead(btn3);
buttonState4 = digitalRead(btn4);
buttonState5 = digitalRead(btn5);

You need to type all variables. These do not have types.

The rest of the error messages are just as explanatory.

What line does it complain about?

Damned near every one.

Delta_G:
Do an autoformat on your code and let it line up the indention and it might make it easier to find. What line does it complain about?

Yes i did autoformat and my brackets are seems good. also I checked by hand many times.

Delta_G:

digitalRead(hallSensorPin1);

if (digitalRead(hallSensorPin1) == LOW) { 
    Konum=1;




Why the spurrious extra digitalRead before the if?

I have those lines for me to understand,actually it does not doing anything.

Thx for your contribution mate!

PaulS:

void up(){

motor1.run(FORWARD);
  delay(100);
}



Where is motor1 defined?



/// hall effect ve motor çalismasi \
                                                        // ASANSOR 1 \



This is a PEBKAC issue. Stop with the \\\ unless you know what you are doing. You don't.



buttonState1 = digitalRead(btn1);
buttonState2 = digitalRead(btn2);
buttonState3 = digitalRead(btn3);
buttonState4 = digitalRead(btn4);
buttonState5 = digitalRead(btn5);



You need to type all variables. These do not have types.

The rest of the error messages are just as explanatory.

My code has more than 9k chars so i couldn't upload whole code. SO actually i defined motor1 at the beginnig of my code.

Moreover, I had all other variables defined at the beginning.

I will consider \\ issue for my future codes =)

thanks!

I did not see void setup() in the code.

You need at least these two sections in your code.

void setup() {
  // put your setup code here, to run once:

}

void loop() {
  // put your main code here, to run repeatedly:

}

I will consider \\ issue for my future codes =)

You need to consider it for THIS code, too.

You need to post ALL of your code. Use Reply (not the Quick Reply field) and attach it, using the Additional Options link, if it is too long. Though why you waited until the code was so large to compile is beyond me.

PaulS:
You need to consider it for THIS code, too.

You need to post ALL of your code. Use Reply (not the Quick Reply field) and attach it, using the Additional Options link, if it is too long. Though why you waited until the code was so large to compile is beyond me.

I did removed those but nothing changed actually. And also I've added whole code now.
As I told you Im new so.. Gonna learn some from you guys..

nathancamp:
I did not see void setup() in the code.

You need at least these two sections in your code.

void setup() {

// put your setup code here, to run once:

}

void loop() {
 // put your main code here, to run repeatedly:

}

I have those, now you can check it in from my .ino file.

uguryazici:
I have those, now you can check it in from my .ino file.

What ino file? You haven't posted it.

If you did the autoformat then why not post the formatted code? Are you intentionally trying to make it harder for us to help?

Delta_G:
What ino file? You haven't posted it.

If you did the autoformat then why not post the formatted code? Are you intentionally trying to make it harder for us to help?

Ive posted it, Its at the attachment of the first message of the topic. Well, i guess you dont see that im new on the forum, i could make mistakes like every one of us could do.

Ok. I didn't realize you had altered that post. I was looking for a response with the code and skipped that one because I had already just read it.

I do get that you are new and making mistakes. How do you expect to get any better if nobody points them out for you? my pointing them out is no impeachment on you personally. I'm trying to help you learn.

Unfortunately I'm posting from a mobile device so I can't view your attachment so I can't be much help now on the source of the error.

uguryazici:
My code has more than 9k chars so i couldn't upload whole code.

:o

How did you manage to write 9k of code riddled with compiler errors? Did you just sit down and type it all out without even checking once to see if it compiled? Imagine a carpenter or welder who just cuts out all the wood or metal, starts assembling, and doesn't once use a measure or square during the build and just assumes that it will all be ok!

When we write code, we build sections that do stuff and then we test that the stuff we just wrote does what we think it should do. You put in tests as you go - on Arduino, this means sticking some LEDs in and confirming that they flash when you think they should. Think in terms of components - the motor start and stopper, the pending-button-light handler. Once a component is written and tested, then go onto the next bit. You don't just chunder out 9k of C++ without so much as compiling it even once and just and expect it to go.

The other issue, of course, is that you don't need that much code to make an elevator go up and down. From the tiny snippets you have posted so far, it's clear you don't understand (for instance) arrays, which really are a pretty key thing.

Perhaps you should start on something smaller. Why not make an elevator controller with just two stations, two call buttons, a motor and a 'door open' sensor?

-- EDIT --

Ok, 9k of code really isn't that much. And you really need a shift register for the LEDs rather than consuming 8 output pins each.

So, your motor takes exactly 100ms to get from one floor to the next?

I also can't help noticing that you never actually stop the elevator once it reaches the correct floor. It will just keep going.

Look, here's your first project: write a pair of functions that display a digit in your two seven-segment displays. Then find out about passing arrays to functions and re-write them so that theres jus one function that accepts an array of pin numbers and a digit to be displayed. Then re-write it so that instead of a bunch of if() statments to display the digits, the pattern for the digits is stored in a 2-dimensional array. Then, for bonus points, instead of using an array to hold the digit patterns, put them in a bitfield.

Then go purchase a pair of serial-in/parallel-out shift registers (they are 5 bucks) and discover how to use them to drive a 7-segment display.

And at that stage, you will have displaying a digit in a 7-segment display down and it might be time to start thinking about coding up an elevator controller.

(ps: Oh - did you accidentally purchase the othr kind of shift register? Don't throw it out! You use that one for the buttons.)

I copied and pasted the code that you changed in your original post (THAT IS THE LAST TIME YOU WILL DO THAT!) and I get just one error:

Binary sketch size: 6,526 bytes (of a 258,048 byte maximum)