element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Community Hub
    Community Hub
    • What's New on element14
    • Feedback and Support
    • Benefits of Membership
    • Personal Blogs
    • Members Area
    • Achievement Levels
  • Learn
    Learn
    • Ask an Expert
    • eBooks
    • element14 presents
    • Learning Center
    • Tech Spotlight
    • STEM Academy
    • Webinars, Training and Events
    • Learning Groups
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • Technology Groups
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents Projects
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • Project Groups
  • Products
    Products
    • Arduino
    • Avnet & Tria Boards Community
    • Dev Tools
    • Manufacturers
    • Multicomp Pro
    • Product Groups
    • Raspberry Pi
    • RoadTests & Reviews
  • About Us
  • Store
    Store
    • Visit Your Store
    • Choose another store...
      • Europe
      •  Austria (German)
      •  Belgium (Dutch, French)
      •  Bulgaria (Bulgarian)
      •  Czech Republic (Czech)
      •  Denmark (Danish)
      •  Estonia (Estonian)
      •  Finland (Finnish)
      •  France (French)
      •  Germany (German)
      •  Hungary (Hungarian)
      •  Ireland
      •  Israel
      •  Italy (Italian)
      •  Latvia (Latvian)
      •  
      •  Lithuania (Lithuanian)
      •  Netherlands (Dutch)
      •  Norway (Norwegian)
      •  Poland (Polish)
      •  Portugal (Portuguese)
      •  Romania (Romanian)
      •  Russia (Russian)
      •  Slovakia (Slovak)
      •  Slovenia (Slovenian)
      •  Spain (Spanish)
      •  Sweden (Swedish)
      •  Switzerland(German, French)
      •  Turkey (Turkish)
      •  United Kingdom
      • Asia Pacific
      •  Australia
      •  China
      •  Hong Kong
      •  India
      • Japan
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • Vietnam
      • Americas
      •  Brazil (Portuguese)
      •  Canada
      •  Mexico (Spanish)
      •  United States
      Can't find the country/region you're looking for? Visit our export site or find a local distributor.
  • Translate
  • Profile
  • Settings
Arduino
  • Products
  • More
Arduino
Arduino Forum Error in sketch code
  • Blog
  • Forum
  • Documents
  • Quiz
  • Events
  • Polls
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Arduino to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • Replies 38 replies
  • Subscribers 403 subscribers
  • Views 3822 views
  • Users 0 members are here
Related

Error in sketch code

Former Member
Former Member over 12 years ago

I am trying to learn to write some code for my BCD clock project.  Before doing the actual clock code I wired up 7 LEDs on my breadboard with 7 resistors.

Then I ran wires from each LED to a digital pin on the Arduino UNO. Specifically pins 7 to 13.

 

Then I wrote some code and tried to upload it but it is flagging 3 errors and I can't see where it is wrong. Probably something that I am missing as a newbie. The errors are as follows:

 

BoardTest:57: error: expected `;' before '{' token

BoardTest:64: error: expected `;' before '{' token

BoardTest:68: error: expected `;' before '{' token

 

The code is as follows:

 

 

// Short sketch to see if breadboard and UNO is properly wired.

 

int led1=7;

int led2=8;

int led3=9;

int led4=10;

int led5=11;

int led6=12;

int led7=13;

 

int seconds=0

 

void setup(){

  ledMode(led1, OUTPUT);

  ledMode(led2, OUTPUT);

  ledMode(led3, OUTPUT);

  ledMode(led4, OUTPUT);

  ledMode(led5, OUTPUT);

  ledMode(led6, OUTPUT);

  ledMode(led7 OUTPUT);

}

 

void loop(){

  seconds++;

    If(seconds == 1){

      digitalWrite(led1, HIGH);

      delay(1000);

    }

    If(seconds == 2){

      digitalWrite(led2, HIGH);

      digitalWrite(led1, LOW);

      delay(1000);

    }

  If(seconds == 3){

      digitalWrite(led1, HIGH);

      delay(1000);

    }

    If(seconds == 4){

      digitalWrite(led3, HIGH);

      digitalWrite(led2, LOW);

      digitalWrite(led1, LOW);

      delay(1000);

    }

    If(seconds == 5){

      digitalWrite(led1, HIGH);

      delay(1000);

    }

    If(seconds == 6){

      digitalWrite(led2, HIGH);

      digitalWrite(led1, LOW);

      delay(1000);

    }

    If(seconds == 7){

      digitalWrite(led1, HIGH);

      delay(1000);

    }

    If(seconds == 8){

      digitalWrite(led4, HIGH);

      digitalWrite(led3, LOW);

      digitalWrite(led2, LOW);

      digitalWrite(led1, LOW);

      delay(1000);

    }

    If(seconds == 9){

      digitalWrite(led1, HIGH);

      delay(1000);

    }

    If(seconds == 10){

      digitalWrite(led2, HIGH);

      digitalWrite(led1, LOW);

      delay(1000);

      digitalWrite(led1, LOW);

      digitalWrite(led2, LOW);

      digitalWrite(led3, LOW);

      digitalWrite(led4, LOW);

  seconds=0;

    }

}

 

 

 

Any help appreciated.

 

Thanks

  • Sign in to reply
  • Cancel

Top Replies

  • Former Member
    Former Member over 12 years ago +1
    John, Are those the only errors you're seeing? It looks to me that on line 11, you are missing a semicolon at the end of the line: int seconds=0 and on line 20, you are missing a comma after led7 ledMode…
  • Former Member
    Former Member over 12 years ago in reply to Former Member +1
    John, A table is just a fancy name for array, although in some languages it might be a fancy type of array such as an associative array. If you have 10 digits, each involving 4 led settings, you might…
Parents
  • Former Member
    Former Member over 12 years ago

    John,

      Are those the only errors you're seeing?

    It looks to me that on line 11, you are missing a semicolon

    at the end of the line:

       int seconds=0

     

    and on line 20, you are missing a comma after led7

        ledMode(led7 OUTPUT);

     

    and all your "if" statements should use lowercase "if"

    instead of "If".

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to Former Member

    Yes Coder27, you are correct.  I didn't notice the other errors because they had scrolled up and were not visible.

    This is my first attempt using the Arduino IDE and coding in 'C'.

     

    I have added the semi colon after 'seconds=0' and the comma after the (led7, OUTPUT).  As well I have changed all of the If to if.

     

    Thanks for pointing these out.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Reply
  • Former Member
    Former Member over 12 years ago in reply to Former Member

    Yes Coder27, you are correct.  I didn't notice the other errors because they had scrolled up and were not visible.

    This is my first attempt using the Arduino IDE and coding in 'C'.

     

    I have added the semi colon after 'seconds=0' and the comma after the (led7, OUTPUT).  As well I have changed all of the If to if.

     

    Thanks for pointing these out.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
Children
  • billabott
    billabott over 12 years ago in reply to Former Member

    One thing you seem to have overlooked JohnC.

    That tiny little number in the lowest left hand corner of the IDE is the line number of the .pde being edited.  Moving the cursor to a different line changes the number.  Good for seeking out the location the error message pertains to.  Don't you agree?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • Former Member
    Former Member over 12 years ago in reply to billabott

    I think the problem here is that the error message indicating a missing

    semicolon was misleading.  The problem was a mis-capitalized keyword,

    rather than a missing semicolon.  It didn't help that previous error messages

    had scrolled off the screen, since that might lead one to believe that the

    previous if-statements were OK.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
  • billabott
    billabott over 12 years ago in reply to Former Member

    http://ecx.images-amazon.com/images/I/41w7lABe%2B%2BL._SL500_AA300_.jpg

    Merry Kiss-a-Gir.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Cancel
element14 Community

element14 is the first online community specifically for engineers. Connect with your peers and get expert answers to your questions.

  • Members
  • Learn
  • Technologies
  • Challenges & Projects
  • Products
  • Store
  • About Us
  • Feedback & Support
  • FAQs
  • Terms of Use
  • Privacy Policy
  • Legal and Copyright Notices
  • Sitemap
  • Cookies

An Avnet Company © 2025 Premier Farnell Limited. All Rights Reserved.

Premier Farnell Ltd, registered in England and Wales (no 00876412), registered office: Farnell House, Forge Lane, Leeds LS12 2NE.

ICP 备案号 10220084.

Follow element14

  • X
  • Facebook
  • linkedin
  • YouTube