Viewing 12 posts - 1 through 12 (of 12 total)
  • Messing about with an Arduino
  • spursn17
    Free Member

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

    goldfish24
    Full Member

    What’s the error?

    kaysee
    Full Member

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

    Remove the semi-colon and try again.

    goldfish24
    Full Member

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

    Edit: beaten to it!!!!

    julians
    Free Member

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

    too slow…

    spursn17
    Free Member

    Aaaaaarrrrgggghhhh!

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

    I’ll probably be back later 🙂

    Cougar
    Full 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.

    Cougar
    Full Member

    Curses, you lot are fast.

    spursn17
    Free Member

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

    spursn17
    Free Member

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

    GrahamS
    Full Member

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

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

    [video]https://www.youtube.com/watch?v=BtLwoNJ6klE[/video]

    [video]https://www.youtube.com/watch?v=YT3birSKLLU[/video]

    Cougar
    Full 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.

Viewing 12 posts - 1 through 12 (of 12 total)

The topic ‘Messing about with an Arduino’ is closed to new replies.