Beginner here. I followed the Arduino code example exactly (I thought so anyway). Getting this error now, please help. 2 files attached
EddieSpaceship_interface2.ino (795 Bytes)
Beginner here. I followed the Arduino code example exactly (I thought so anyway). Getting this error now, please help. 2 files attached
EddieSpaceship_interface2.ino (795 Bytes)
Welcome to the forum
Coding is case sensitive and you should not type the line numbers in the code and square, curly brackets or parenthesis should match — when you open a { you need a corresponding closing }
look at this
int switchstate = 0; // <<---- starts with a lower case s and state as well
void setup() {
pinMode(3, OUTPUT);
pinMode(4, OUTPUT);
pinMode(5, OUTPUT);
pinMode(2, INPUT);
}
void loop() {
switchstate = digitalRead(2); // CAREFUL CODING IS CASE SENSITVE switchstate is not the same as SwitchState and digitalRead not the same as digitalread
// this is a comment // <<----- THIS IS A VERY USELESS COMMENT :)
if (switchstate == LOW) {// CAREFUL CODING IS CASE SENSITVE switchstate is not the same as SwitchState
// the button is not pressed
digitalWrite(3, HIGH); // green LED on
digitalWrite(4, LOW); // red LED off
digitalWrite(5, LOW); // red LED off
}
else { // the button is pressed
digitalWrite(3, LOW); // green LED off
digitalWrite(4, LOW); // red LED off
digitalWrite(5, HIGH); // red LED on
delay(250); // wait for a quarter second
//toggle the LED's
digitalWrite(4, HIGH);
digitalWrite(5, LOW);
delay(250); // wait for a quarter second
}
} // go back to the beginning of the loop
// } // <---- WHAT WAS THIS CLOSING ???
please don't post screen shot of an error message, just copy and paste it directly in the forum text.
Also in your post above you should have posted the code with code tags around your code:
[code]`` [color=blue]// your code is here[/color] ``[/code]
.
It should look like this:// your code is here
(Also press ctrl-T (PC) or cmd-T (Mac) in the IDE before copying to indent your code properly)
Looks like you are playing with LEDs, make sure you have appropriate current limiting resistors installed
Thanks for your reply. After several days of trying to make the corrections you suggested I still can't get it to run, it gives the same error as before. I pasted your code into a new window and it runs great, but when I look at my code next to yours I simply can't see what the difference is? I used the CTRL-T as you recommended which makes the code look quite different from the Arduino book I'm using.
1 int switchstate = 0;
2 void setup() {
3 pinMode(3, OUTPUT);
4 pinMode(4, OUTPUT);
5 pinMode(5, OUTPUT);
6 pinMode(2, INPUT);
7 }
8 void loop(){
9 switchstate = digitalRead(2);
10 // this is a comment
11 if (switchstate == LOW) {
12 // the button is not pressed
13 digitalWrite(3, HIGH); // green LED on
14 digitalWrite(4, LOW); // red LED off
15 digitalWrite(5, LOW); // red LED off
16
}
17 else { // the button is pressed
18 digitalWrite(3, LOW); // green LED off
19 digitalWrite(4, LOW); // red LED off
20 digitalWrite(5, HIGH); // red LED on
21 delay(250); // wait for a quarter second
22 //toggle the LEDs
23 digitalWrite(4, HIGH);
24 digitalWrite(5, LOW);
25 delay(250); // wait for a quarter second
26
}
27
} // go back to the beginning of the loop
Arduino: 1.8.3 (Windows 10), Board: "Arduino/Genuino Uno"
EddieSpaceship_interface2:3: error: expected unqualified-id before numeric constant
1 int switchstate = 0;
^
EddieSpaceship_interface2:4: error: expected unqualified-id before numeric constant
2 void setup() {
^
EddieSpaceship_interface2:11: error: expected unqualified-id before numeric constant
8 void loop(){
^
exit status 1
expected unqualified-id before numeric constant
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.
The compiler is complaining about the line numbers. Remove them !
That did it. I can't thank you enough. Have a great day!!!!!!
I told you so in the first post...
Thanks for your help J-M-L, I learned a lot by reading through all of your notes. I appreciate you taking the time to help me out. Have a great day!
I suggest you coggle "C++ tutorial" and do the first few lessons of any one of the free online tutorials. A couple of details won't translate across to arduino C++, but the basics of variables, functions and things like that will.