I have Arduino stater Kit and in project book, project 2, Spaceship interface will not work after i type in my sketch and click to verify. I have check for errors in sketch it seems OK, I get the error message " expected unqualified-id before numeric constant"
I don't know what this means. I can get the sketch out of the library and verify and upload and everything works fine. Can someone help me? Thank You
code
Moderators: adafruit_support_bill, adafruit
Please be positive and constructive with your questions and comments.
- adafruit_support_bill
- Posts: 88091
- Joined: Sat Feb 07, 2009 10:11 am
Re: code
If it works from the library and not when you type it in, then there must be a typo. Post the code you are having a problem with.
- swan7
- Posts: 6
- Joined: Sun Sep 21, 2014 1:46 am
Re: code
Here is the sketch i typed in. Thank You
1 int switchState = 0;
2 void setup(){
3 pinMode(3,OUTPUT);
4 pinMode(4,OUTPUT);
5 pinMode(5,OUTPUT);
6 pimMode(2,Input);
7 }
8 void loop(){
9 switchState = digitalRead(2);
10 // this is for comment
11 if (switchState = = LOW) {
12 // the button is not pressed
13 digitalWrite(3, HIGH); // green LED
14 digitalWrite(4, LOW); // red LED
15 digitalWrite(5, LOW); // red LED
16 }
17 else { // the button is pressed
18 digitalWrite(3, LOW);
19 digitalWrite(4, LOW);
20 digitalWrite(5, HIGH);
21 delay(250); //wait for quarter second
22 // toggle the LEDs
23 digitalWrite(4, HIGH);
24 digitalWrite(5, LOW);
25 delay(250); // waitfor a quarter second
26 }
27 } //go back to the beginning of the loop
1 int switchState = 0;
2 void setup(){
3 pinMode(3,OUTPUT);
4 pinMode(4,OUTPUT);
5 pinMode(5,OUTPUT);
6 pimMode(2,Input);
7 }
8 void loop(){
9 switchState = digitalRead(2);
10 // this is for comment
11 if (switchState = = LOW) {
12 // the button is not pressed
13 digitalWrite(3, HIGH); // green LED
14 digitalWrite(4, LOW); // red LED
15 digitalWrite(5, LOW); // red LED
16 }
17 else { // the button is pressed
18 digitalWrite(3, LOW);
19 digitalWrite(4, LOW);
20 digitalWrite(5, HIGH);
21 delay(250); //wait for quarter second
22 // toggle the LEDs
23 digitalWrite(4, HIGH);
24 digitalWrite(5, LOW);
25 delay(250); // waitfor a quarter second
26 }
27 } //go back to the beginning of the loop
- adafruit_support_bill
- Posts: 88091
- Joined: Sat Feb 07, 2009 10:11 am
Re: code
You do not need to type in the line numbers. This will only confuse the compiler.
- swan7
- Posts: 6
- Joined: Sun Sep 21, 2014 1:46 am
Re: code
Thank You Removing the line numbers fixed that problem, but another error pop up " switchState was not declared in this scope." In the book the lines are numbered i did not know not to include them. If you can help me again i would be very Thank full. Which one of your books on programming would be the most helpful ?
Thank you so much
Thank you so much
- Franklin97355
- Posts: 23910
- Joined: Mon Apr 21, 2008 2:33 pm
Re: code
Did you fix the problem with the == ? This is a good starter book https://www.adafruit.com/product/1019 There are also 18 lessons on the Arduino by Simon Monk starting here https://learn.adafruit.com/adafruit-ard ... on-1-blink
- adafruit_support_bill
- Posts: 88091
- Joined: Sat Feb 07, 2009 10:11 am
Re: code
Post your code as it is now. switchState should be defined in the very first line:
Code: Select all
int switchState = 0;
- swan7
- Posts: 6
- Joined: Sun Sep 21, 2014 1:46 am
Re: code
int switchState = 0;
void setup() {
// declare the LED pins as output
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
//declare the switch pin as an input
pinMode(2,INput);
}
void loop() {
// read the value of switch
// digitalRead () checks to see if there is voltage
//on the pin or not
switchstate =digitalRead(2);
// if the button is not pressed
// turn on the green LED and turn off the red LEDs
if (switchState ==LOW) {
//the button is not pressed
digitalWrite(3, HIGH); // turn the green LED on pin 3 on
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, LOW); // turn the red LED on pin 5 off
}
// this else is part of the above if () statement.
// if the switch is not LOW (the button is pressed)
// turn off the green LED and blink BANNED the red LEDs
else { // the button is pressed
digitalWrite(3, LOW); // turn the green LED on pin 3 off
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, HIGH); // turn the red LED on pin5 on
// wait for a quarter second
// toggle the LEDs
digitalWrite(4, HIGH);
digitalWrite(5, LOw);
delay(250); // wait for a quarter second
}
}//go back to the beginning of the loop
void setup() {
// declare the LED pins as output
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
//declare the switch pin as an input
pinMode(2,INput);
}
void loop() {
// read the value of switch
// digitalRead () checks to see if there is voltage
//on the pin or not
switchstate =digitalRead(2);
// if the button is not pressed
// turn on the green LED and turn off the red LEDs
if (switchState ==LOW) {
//the button is not pressed
digitalWrite(3, HIGH); // turn the green LED on pin 3 on
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, LOW); // turn the red LED on pin 5 off
}
// this else is part of the above if () statement.
// if the switch is not LOW (the button is pressed)
// turn off the green LED and blink BANNED the red LEDs
else { // the button is pressed
digitalWrite(3, LOW); // turn the green LED on pin 3 off
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, HIGH); // turn the red LED on pin5 on
// wait for a quarter second
// toggle the LEDs
digitalWrite(4, HIGH);
digitalWrite(5, LOw);
delay(250); // wait for a quarter second
}
}//go back to the beginning of the loop
- adafruit_support_bill
- Posts: 88091
- Joined: Sat Feb 07, 2009 10:11 am
Re: code
There were several places where you had capitalization errors. The compiler is very unforgiving with that. "switchstate" is not the same as "switchState".
This should compile for you:
This should compile for you:
Code: Select all
int switchState = 0;
void setup() {
// declare the LED pins as output
pinMode(3,OUTPUT);
pinMode(4,OUTPUT);
pinMode(5,OUTPUT);
//declare the switch pin as an input
pinMode(2,INPUT);
}
void loop() {
// read the value of switch
// digitalRead () checks to see if there is voltage
//on the pin or not
switchState =digitalRead(2);
// if the button is not pressed
// turn on the green LED and turn off the red LEDs
if (switchState ==LOW) {
//the button is not pressed
digitalWrite(3, HIGH); // turn the green LED on pin 3 on
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, LOW); // turn the red LED on pin 5 off
}
// this else is part of the above if () statement.
// if the switch is not LOW (the button is pressed)
// turn off the green LED and blink BANNED the red LEDs
else { // the button is pressed
digitalWrite(3, LOW); // turn the green LED on pin 3 off
digitalWrite(4, LOW); // turn the red LED on pin 4 off
digitalWrite(5, HIGH); // turn the red LED on pin5 on
// wait for a quarter second
// toggle the LEDs
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); // wait for a quarter second
}
}//go back to the beginning of the loop
- swan7
- Posts: 6
- Joined: Sun Sep 21, 2014 1:46 am
Re: code
I finely got it to work Thank to You !!!. I will order that programming book as soon as i send this e-mail.
I just want to say Thanks to Adafruit and there dedicated employee who worked with me to get my little sketch working. Now all i have to do is find the barn and the gate to it, to have a new roof put on it. It's like a Jungle out back there, that is what my brother said about my driveway, just think what the back looks like. I want to Thank You again for being so nice.
THANK YOU
Jim Andersen
I just want to say Thanks to Adafruit and there dedicated employee who worked with me to get my little sketch working. Now all i have to do is find the barn and the gate to it, to have a new roof put on it. It's like a Jungle out back there, that is what my brother said about my driveway, just think what the back looks like. I want to Thank You again for being so nice.
THANK YOU
Jim Andersen
- adafruit_support_bill
- Posts: 88091
- Joined: Sat Feb 07, 2009 10:11 am
Re: code
You are welcome. That is what we are here for!
- adafruit_support_bill
- Posts: 88091
- Joined: Sat Feb 07, 2009 10:11 am
Re: code
@smbyrne4 - I'm not sure I understand the question. Is it about the lesson 6 code or the serial monitor?
Please tell us what you are trying to do.
Please tell us what you are trying to do.
Please be positive and constructive with your questions and comments.