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
Experts, Learning and Guidance
  • Technologies
  • More
Experts, Learning and Guidance
Ask an Expert Forum I think I have a coding error
  • Blog
  • Forum
  • Documents
  • Leaderboard
  • Files
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Join Experts, Learning and Guidance to participate - click to join for free!
Actions
  • Share
  • More
  • Cancel
Forum Thread Details
  • State Verified Answer
  • Replies 8 replies
  • Subscribers 304 subscribers
  • Views 780 views
  • Users 0 members are here
Related
See a helpful answer?

Be sure to click 'more' and select 'suggest as answer'!

If you're the thread creator, be sure to click 'more' then 'Verify as Answer'!

I think I have a coding error

oconnell
oconnell over 8 years ago

int redLED=8; //declaring redLED as an int and set in 8 position

int yellowLED=9;// declaring yellowLED as an int and set in postipn 9

int redOnTime = 500; //red LED is set to be on 500 milliseconds or a half second

int redOffTime= 500; //red LED is set to be off for 500 milliseconds or half a second

int yellowOnTime = 1000; //yellow is set to be on for 1000 milliseconds

int yellowOffTime = 500; //yellow LED is set to be off half a second

int numRedBlink=6; //j will be my counter in for loop

 

 

 

 

void setup() {

  pinMode { redLED, OUTPUT };

  pinMode { yellowLED, INPUT};

 

 

}

 

 

void loop() {

  for{int j=1; j<=numRedBlink;j=j+1};  { 

digitalWrite{redLED, HIGH}; //turn red LED on

delay {redOnTime}; //wait

digitalWrite {redLED, LOW}; // turn red LED off

delay {redOffTime}; //wait

}

digitalWrite{yellowLED, HIGH}; //turn yellow LED on

delay {yellowOnTime}; //wait

digitalWrite{yellowLED,LOW}; //turn yellow LED off

delay{yellowOffTime}; //wait

 

 

}

 

 

This is what I coded but I get and error saying it is an exit error 1. excpect " ; " before " } "

  • Sign in to reply
  • Cancel

Top Replies

  • oconnell
    oconnell over 8 years ago in reply to oconnell +1 verified
    I found the problem. I was using curly brackets throughout and it does not like that.
  • oconnell
    0 oconnell over 8 years ago

    actually the error says expected " ;" before " { "

    ( I had put the wrong bracket in on my original question)

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • koudelad
    0 koudelad over 8 years ago in reply to oconnell

    Hello, remove the last semicolon from this cycle definition:

     

    for{int j=1; j<=numRedBlink;j=j+1};

     

    EDIT: One more thing: there is one more closing curly bracket than needed in the loop function.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • koudelad
    0 koudelad over 8 years ago in reply to koudelad

    PS: formatting the section as code much improves readability:

     

    int redLED=8; //declaring redLED as an int and set in 8 position
    int yellowLED=9;// declaring yellowLED as an int and set in postipn 9
    int redOnTime = 500; //red LED is set to be on 500 milliseconds or a half second
    int redOffTime= 500; //red LED is set to be off for 500 milliseconds or half a second
    int yellowOnTime = 1000; //yellow is set to be on for 1000 milliseconds
    int yellowOffTime = 500; //yellow LED is set to be off half a second
    int numRedBlink=6; //j will be my counter in for loop
        
    void setup() {
      pinMode { redLED, OUTPUT };
      pinMode { yellowLED, INPUT};
    }
      
    void loop() {
      for{int j=1; j<=numRedBlink;j=j+1};  { 
         digitalWrite{redLED, HIGH}; //turn red LED on
         delay {redOnTime}; //wait
         digitalWrite {redLED, LOW}; // turn red LED off
         delay {redOffTime}; //wait
    
         digitalWrite{yellowLED, HIGH}; //turn yellow LED on
         delay {yellowOnTime}; //wait
         digitalWrite{yellowLED,LOW}; //turn yellow LED off
         delay{yellowOffTime}; //wait
    }

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • oconnell
    0 oconnell over 8 years ago in reply to koudelad

    Thank you for your reply. Where does it need another curly bracket? I have tried the program with and without the semicolon

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • koudelad
    0 koudelad over 8 years ago in reply to oconnell

    I added some comments with capital letters into the code snippet below:

     

    void loop() {
      for{int j=1; j<=numRedBlink;j=j+1}  { 
    digitalWrite{redLED, HIGH}; //turn red LED on
    delay {redOnTime}; //wait
    digitalWrite {redLED, LOW}; // turn red LED off
    delay {redOffTime}; //wait
    } // THIS IS REDUNDANT
    digitalWrite{yellowLED, HIGH}; //turn yellow LED on
    delay {yellowOnTime}; //wait
    digitalWrite{yellowLED,LOW}; //turn yellow LED off
    delay{yellowOffTime}; //wait
    } // IS THIS STILL THE LOOP FUNCTION?

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • oconnell
    0 oconnell over 8 years ago in reply to oconnell

    I found the problem. I was using curly brackets throughout and it does not like that.

    • Cancel
    • Vote Up +1 Vote Down
    • Sign in to reply
    • Verify Answer
    • Reject Answer
    • Cancel
  • volly
    0 volly over 8 years ago in reply to oconnell

    oconnell this is the best way of learning.image

    Happy to see you found your error through trial and error.

    You might have known the use of the type of brackets and semicolons,

    But ever so now and then one does something totally obviously wrong.

    Enjoy.

    Yunus.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • Cancel
  • oconnell
    0 oconnell over 8 years ago in reply to koudelad

    The first curvy ending bracket in the Void loop is for the "for loop" and only applies to the red LED. The last ending curvy bracket in the void loop is for the entire loop.

    • Cancel
    • Vote Up 0 Vote Down
    • Sign in to reply
    • Verify Answer
    • 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