Messing about with ...
 

MegaSack DRAW - 6pm Christmas Eve - LIVE on our YouTube Channel

[Closed] Messing about with an Arduino

11 Posts
6 Users
0 Reactions
61 Views
Posts: 843
Free Member
Topic starter
 

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! 😀


 
Posted : 20/06/2017 1:05 pm
Posts: 1834
Full Member
 

What's the error?


 
Posted : 20/06/2017 1:11 pm
Posts: 15
Full Member
 

if (digitalRead(reedswitch) == HIGH);{

Remove the semi-colon and try again.


 
Posted : 20/06/2017 1:12 pm
Posts: 1834
Full Member
 

Oh, just spotted syntax error. You have a semicolon after the if statement, before the curly brace.

Edit: beaten to it!!!!


 
Posted : 20/06/2017 1:12 pm
Posts: 4597
Free Member
 

you dont need the semi colon at the end of the if

too slow...


 
Posted : 20/06/2017 1:14 pm
Posts: 843
Free Member
Topic starter
 

Aaaaaarrrrgggghhhh!

Thanks for that, I've been staring at it for ages and didn't notice it.

I'll probably be back later 🙂


 
Posted : 20/06/2017 1:15 pm
Posts: 77691
Free Member
 

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.


 
Posted : 20/06/2017 1:17 pm
Posts: 77691
Free Member
 

Curses, you lot are fast.


 
Posted : 20/06/2017 1:18 pm
Posts: 843
Free Member
Topic starter
 

The language is C or something derived from it I think, I'm using the Arduino IDE to learn.


 
Posted : 20/06/2017 1:19 pm
Posts: 843
Free Member
Topic starter
 

If it was something in the real world I would've hit it with a big hammer eventually, STW is the IT equivalent! 😀


 
Posted : 20/06/2017 1:20 pm
Posts: 31206
Full Member
 

This is probably not the easiest way to learn C by the way.

But hey ho.. these may be useful, particularly 102:


 
Posted : 20/06/2017 1:31 pm
Posts: 77691
Free Member
 

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.


 
Posted : 20/06/2017 1:33 pm