Note that the C language syntax is not line-oriented; it is character-oriented. The following two programs are identical:
int ledpin=13;void setup(){pinMode(ledpin,OUTPUT);}void loop(){digitalWrite(ledpin,HIGH);delay(500);digitalWrite(ledpin,LOW);delay(500);}
int
ledpin
=
13
;
void
setup
(
)
{
pinMode
(
ledpin
,
OUTPUT
)
;
} void loop(
)
{
digitalWrite
(
ledpin
,
HIGH); delay(
500);
digitalWrite
(
ledpin
,
LOW
)
; delay
(
500);
}
Neither of these programs would be considered readable, but they are syntactically correct. Note that in both cases there is a semicolon before the void. Eliminate it in either one and you will get the same error message.
Your error was in assuming that it is line-oriented, that the ; has to be on the same line as the void. The compiler was telling you that there was a semicolon missing before the void. Nothing more. It is up to you to make sure that the semicolon is in the right place.
By the way, const byte is better than int, but that is a minor point.
Remember always that C is a character-structured language. If you put whitespace in the wrong place, it sees a space character which means the end of a word or number, so you could not say
void set up()
{
pin Mode(led pin, OUT PUT);
max value = 1 000 000;
message = "This is
a test" ;
}
because in a character-oriented language, whitespace (in any amount) is meaningful, but only within atomic units like names, strings and numbers. A string constant must be contained on a single line.
Leading spaces, tabs, newlines, and spaces outside the atomic units are always valid, and are ignored. However, you can't write
intledpin=13;
because the syntax wants the typename, then the variable name, and it only sees one name, intledpin, which it does not recognize as a typename. Since you have to specify two names, you have to separate them by some whitespace so they are seen as two names. But symbols such as ), ; and } do not have spacing requirements before or after:
int
ledpin = 13;
void setup ( )
{
pinMode (ledpin, OUTPUT
);}
You also can't write compound operators such as += or ++ or >= with spaces between them, because they are defined as atomic units.
You can't write the following
Text = "this
is
a
message";
But you can write
Text = "this "
"is "
"a "
"message");
if you do
Serial.print(Text)
you will get
this is a message
If you want a multiline message, you can end each line with \n:
Text = "Usage\n"
"+ Add the two values on the stack\n"
"- Subtract the two values on the stack\n"
"Good luck!"
and
Serial.print(Text) will print out the composite single string
Usage
+ Add the two values on the stack
- Subtract the two values on the stack
Good luck!
Note that #define has its own peculiar syntax rules, so that
#define mul(a, b) a * b
and
#define mul (a, b) a * b
are not the same at all. That space after mul changes the whole definition, so watch out for that.
By the way, the only correct way to write that is
#define mul(a, b) ((a)*(b))
but you are not yet ready to understand the answer. But you will be.
You can't sprinkle semicolons around like pixie dust and hope they will solve your problem.