Hi,
Im new to Arduino and just got my starter kit. Im on the second lesson, Spaceship Interface and Im having trouble uploading my code to the Arduino UNO. It always tells me:
Spaceship_Interface.ino:10:1: error: expected initializer before 'switchstate'
Spaceship_Interface.ino:16:14: error: expected constructor, destructor, or type conversion before '(' token
Spaceship_Interface.ino:17:14: error: expected constructor, destructor, or type conversion before '(' token
Spaceship_Interface.ino:18:1: error: expected declaration before '}' token
Error compiling.
Im not sure what any of this means or how to troubleshoot it.
Any ideas?
Here is my code:
int switchState = 0;
void setup() {
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop()
switchstate = digitalRead(2)
// digitalRead checks for voltage
if(switchState == LOW)
// two equal signs compare two things
digitalWrite(3, HIGH); //green LED
digitalWrite(4, LOW); //red LED
digitalWrite(5, LOW);// red LED
}
else {
digitalWrite(3,LOW);
digitalWrite(4,LOW) ;
digitalWrite(5,HIGH);
delay(250);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(250);
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
Missing ; here:
switchstate = digitalRead(2)
Missing { here:
if(switchState == LOW)
Missing } at the end to finish loop()
Thank you but it still shows an error:
Spaceship_Interface.ino:10:2: error: 'switchstate' does not name a type
Spaceship_Interface.ino:19:2: error: expected unqualified-id before '{' token
Error compiling.
And i followed up with the mistakes so here is the new code:
int switchState = 0;
void setup() {
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop()
;switchstate = digitalRead(2)
// digitalRead checks for voltage
{if(switchState == LOW)
// two equal signs compare two things
digitalWrite(3, HIGH); //green LED
digitalWrite(4, LOW); //red LED
digitalWrite(5, LOW);// red LED
}
else {
digitalWrite(3,LOW);
digitalWrite(4,LOW) ;
digitalWrite(5,HIGH);
delay(250);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(250);
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
Hi,
Im new to Arduino and just got my starter kit. Im on the second lesson, Spaceship Interface and Im having trouble uploading my code to the Arduino UNO.Please, I really need HELP!!! It always tells me:
Spaceship_Interface.ino:10:2: error: 'switchstate' does not name a type
Spaceship_Interface.ino:19:2: error: expected unqualified-id before '{' token
Error compiling.
Here is my code:
int switchState = 0;
void setup() {
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
pinMode(2,INPUT);
}
void loop()
;switchstate = digitalRead(2)
// digitalRead checks for voltage
{if(switchState == LOW)
// two equal signs compare two things
digitalWrite(3, HIGH); //green LED
digitalWrite(4, LOW); //red LED
digitalWrite(5, LOW);// red LED
}
else {
digitalWrite(3,LOW);
digitalWrite(4,LOW) ;
digitalWrite(5,HIGH);
delay(250);
digitalWrite(4,HIGH);
digitalWrite(5,LOW);
delay(250);
}
}
Moderator edit:
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags added.
Why did you start a new thread on this problem? That's a no-no here. (And damned annoying to boot.)
Error Spaceship Interface Starter Kit
I just realised you also started a thread back in December last year on this very same topic:-
Error: Expected unqualified-id before 'else'
You had good replies back then, but appear to have completely ignored them.
First, you need an opening bracket { at the beginning of 'loop()' immediately after this:-
void loop()
Next, move the semicolon from the beginning to the end of this line:-
;switchstate = digitalRead(2)
Also, in this same line, change this:- "switchstate" to this:- "switchState".
(C++ is case-sensitive.) You want it to look like this:-
switchState = digitalRead(2);
Then change this:-
{if(switchState == LOW)
to this:-
if(switchState == LOW){
ie Move the opening brace from the beginning to the end of the line.
Edit: Oh and also:-
You really should have read the How to use this forum - please read post at the top of the index page and How to use this forum before posting.
ie Your code and any error messages should always be placed between code tags. Posting it inline as you have done makes it much harder to read or copy and paste for diagnosis.
It's still not too late to edit your posts and do this.
Delta_G:
void loop()
;switchstate = digitalRead(2)
Looks like you miscopied some stuff. For instance that ; should probably be a {
And a ; is needed at the end of the line. Also "switchstate" should be "switchState". And more.....
This is actually a cross-post. The first one is here:-
Spaceship Interface Arduino Starter Kit Error
OldSteve:
This is actually a cross-post. The first one is here:-
Spaceship Interface Arduino Starter Kit Error
Going to report it.
-Malhar
Please do not cross-post. Threads merged.
Please use
</mark> <mark>[code]</mark> <mark>
</mark> <mark>[/code]</mark> <mark>
tags.