Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Arduino Syntax problem ('else' without a previous 'if')

  1. Nov 23, 2016 #1
    not sure why I am getting a syntax, I am new to programming so trying something simple. Can somone please explain why I am getting this error?

    Code (Text):

    int LED = 11;                                // on/off battery 2 control
    int LEDP = 5;



    void setup()
    {
     pinMode (LED, OUTPUT);
     pinMode (LEDP, INPUT);
    }

    void loop()
    {
     int light = digitalRead (LEDP);
     if (digitalRead (light) == HIGH);
     {
       digitalWrite (light, HIGH);
     }
     else
     {
       digitalWrite (light, LOW);
     }
    }
     


    Arduino: 1.6.12 (Windows 7), Board: "Arduino/Genuino Uno"

    C:\Users\User\Documents\LED_controller\LED_controllerIO\LED_controllerIO.ino: In function 'void loop()':

    LED_controllerIO:19: error: 'else' without a previous 'if'

    else

    ^

    exit status 1
    'else' without a previous 'if'

    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.
     
    Last edited by a moderator: Nov 23, 2016
  2. jcsd
  3. Nov 23, 2016 #2

    cnh1995

    User Avatar
    Homework Helper

    You have terminated the 'if' statement with a semi-colon...
     
  4. Nov 23, 2016 #3

    jim mcnamara

    User Avatar

    Staff: Mentor

    if (digitalRead (light) == HIGH);

    Remove the red semicolon.
     
  5. Nov 23, 2016 #4
    HAHA, thanks, had a feeling it was going to be something stupid. Lesson learned
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted



Similar Discussions: Arduino Syntax problem ('else' without a previous 'if')
  1. C# for arduino? (Replies: 5)

Loading...