i don't know if i am doing something wrong but this is happening to me and its getting really frustrating, please fix or if i'm just being bad then please tell me what to do
You need to explain your problem and post your code; we're not psychic.
here's the code
int ledpin13 = 13
void setup() {
}
void loop() {
;digitalWrite(ledpin13, HIGH)
;delay(100)
;digitalWrite(ledpin13, LOW)
;delay(100)
}
i'm trying to do a simple led setup but it expects ;void setup even if usually it doesnt, and if i put ; there it still wants me to put ;.
By the way im using arduino create on a chromebook
Does that code look anything like any of the many examples provided in the IDE?
You don't have to work in the dark, you know - there are many examples of code out there, even "blink with delay".
thats exactly the one i used and modified, only problem is when i add the int it wants the semicolon before void setup, i add the semicolon but it still wants a semicolon.
i attached a screenshot
thats exactly the one i used and modified
Please point out where in the example code you see anything like this ;digitalWrite(ledpin13, HIGH)
Also, if you're going to write to a pin, it is usually a good idea to make it an output first, otherwise you're just waggling the pullup resistor on and off.
making ledpin13 an output didnt fix my problem. i do thank you for telling me to make it an output as im kinda new, but the problem is with the "void setup() {}" it says that it requires a semicolon before void, when i add the semicolon it still wants me to add a semicolon, even if ive done that
const byte ledpin = 13;
void setup() {
pinMode (ledpin, OUTPUT);
}
void loop() {
digitalWrite(ledpin, HIGH);
delay(100);
digitalWrite(ledpin, LOW);
delay(100);
}
Can you see the differences?
only a const and byte, for the rest no.
You can't see that semicolons are at the end of the lines, not the beginning? :o
ok so yes i didnt see that, but my arduino create says before and if you look at the screenshot i sent a few replies ago you would see it say "expected ',' or ';' before 'void'. and you didnt add any ; after or before void right? but now a new problem is that i added semicolons both before and after void, it wanted that with 'setup' aswell and now it says setup does not name a type
im attaching a screenshot to this reply
im attaching a screenshot to this reply
Why should I waste 123 kB of my mobile data plan, when you could have posted a couple of hundred bytes of text?
Let me ask you again - where have you ever seen code that looks like yours?
Do you think there may be a reason for that?
Here is the code you posted (badly) originally
int ledpin13 = 13
void setup() {
Can you see that the first line is missing a semicolon?
That semicolon that isn't there syntactically should come before the compiler sees the word "void" (or a whole host of other words).
okay so here is the whole code right now, including the ';void; ;setup;' weird semicolons
int ledpin13 = 13
;void; ;setup;() {
ledpin13 = OUTPUT
}
void loop() {
;digitalWrite(ledpin13, HIGH);
;delay(100);
;digitalWrite(ledpin13, LOW);
;delay(100);
}
i got it from blink in basics in examples and i tried modifying it, but then it wanted me to add a semicolon before void and then it asked again.
Put your sketch away for now, and find yourself a good online C/C++ tutorial.
It looks like you're trying to make up your own syntax.
That never ends well.
ok, thanks for atleast trying lol
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.
Qwerzer23:
here's the codeint ledpin13 = 13
void setup() {}
void loop() {
;digitalWrite(ledpin13, HIGH)
;delay(100)
;digitalWrite(ledpin13, LOW)
;delay(100)
}
The compiler sees that you have written your loop as if it had been written
int ledpin13 = 13 <=== missing semicolon, not detected until 'void' is seen
void setup() {
}
void loop() {
; // <==== this is an "empty statement" and is syntactically valid
digitalWrite(ledpin13, HIGH);
delay(100);
digitalWrite(ledpin13, LOW);
delay(100) // <=== note missing semicolon and this is an error
}
By the way, the name ledpin13
is a silly name; what if your next board has, for some reason, the led on pin 9? You would have to write int ledpin13=9;
so your name would be confusing. Drop the 13 from the name.