MegaSack DRAW - 6pm Christmas Eve - LIVE on our YouTube Channel
Can anyone tell me why this keeps throwing up an error please....
const int reedswitch = 2;
const int ledpin = 8;
void setup() {
pinMode(reedswitch, digitalRead);
pinMode(ledpin, digitalWrite);
}
void loop() {
if (digitalRead(reedswitch) == HIGH);{
digitalWrite(ledpin, HIGH);
}
else {
digitalWrite (ledpin, LOW);
}
}
It's doing my head in now, I've been moving the brackets all over the place to try to get it to compile but it keeps throwing up errors.
I can do the basic switching stuff on and off but the if/else thing seems to have me stuck.
As you can probably tell I'm at the start of the learning curve! 😀
What's the error?
if (digitalRead(reedswitch) == HIGH);{
Remove the semi-colon and try again.
Oh, just spotted syntax error. You have a semicolon after the if statement, before the curly brace.
Edit: beaten to it!!!!
you dont need the semi colon at the end of the if
too slow...
Aaaaaarrrrgggghhhh!
Thanks for that, I've been staring at it for ages and didn't notice it.
I'll probably be back later 🙂
What's the error?
Exactly what I was going to ask.
I've been moving the brackets all over the place to try to get it to compile
Stop doing that and work out where they need to be.
I don't know the language, but this looks wrong to me:
if (digitalRead(reedswitch) == HIGH);{
... I don't think that semi-colon should be there.
Curses, you lot are fast.
The language is C or something derived from it I think, I'm using the Arduino IDE to learn.
If it was something in the real world I would've hit it with a big hammer eventually, STW is the IT equivalent! 😀
This is probably not the easiest way to learn C by the way.
But hey ho.. these may be useful, particularly 102:
The language is C or something derived from it I think, I'm using the Arduino IDE to learn.
TBH the principles of any high level language are broadly the same, that's how I spotted it without really knowing what it was.
Here you need semi-colons to separate statements. An If... Then... Else loop is all one statement.

