code

For makers who have purchased an Adafruit Starter Pack, get help with the tutorials here!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
swan7
 
Posts: 6
Joined: Sun Sep 21, 2014 1:46 am

code

Post by swan7 »

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

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: code

Post by adafruit_support_bill »

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.

User avatar
swan7
 
Posts: 6
Joined: Sun Sep 21, 2014 1:46 am

Re: code

Post by swan7 »

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

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: code

Post by adafruit_support_bill »

You do not need to type in the line numbers. This will only confuse the compiler.

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: code

Post by Franklin97355 »

The compare is == not = =

User avatar
swan7
 
Posts: 6
Joined: Sun Sep 21, 2014 1:46 am

Re: code

Post by swan7 »

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

User avatar
Franklin97355
 
Posts: 23910
Joined: Mon Apr 21, 2008 2:33 pm

Re: code

Post by Franklin97355 »

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

User avatar
swan7
 
Posts: 6
Joined: Sun Sep 21, 2014 1:46 am

Re: code

Post by swan7 »

no that did not help.

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: code

Post by adafruit_support_bill »

Post your code as it is now. switchState should be defined in the very first line:

Code: Select all

int switchState = 0;

User avatar
swan7
 
Posts: 6
Joined: Sun Sep 21, 2014 1:46 am

Re: code

Post by swan7 »

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

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: code

Post by adafruit_support_bill »

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:

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

User avatar
swan7
 
Posts: 6
Joined: Sun Sep 21, 2014 1:46 am

Re: code

Post by swan7 »

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

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: code

Post by adafruit_support_bill »

You are welcome. That is what we are here for!

User avatar
smbyrne4
 
Posts: 9
Joined: Fri Dec 26, 2014 6:01 pm

Re: code

Post by smbyrne4 »

i recently purchased the adafruit starter kit ardino uno R3. What was the actual code that the end of lesson 6 refers to. I'm having difficulty activating the serial monitor.

User avatar
adafruit_support_bill
 
Posts: 88091
Joined: Sat Feb 07, 2009 10:11 am

Re: code

Post by adafruit_support_bill »

@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.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino Starter Pack”