element14 Community
element14 Community
    Register Log In
  • Site
  • Search
  • Log In Register
  • Members
    Members
    • Benefits of Membership
    • Achievement Levels
    • Members Area
    • Personal Blogs
    • Feedback and Support
    • What's New on element14
  • Learn
    Learn
    • Learning Center
    • eBooks
    • STEM Academy
    • Webinars, Training and Events
    • More
  • Technologies
    Technologies
    • 3D Printing
    • FPGA
    • Industrial Automation
    • Internet of Things
    • Power & Energy
    • Sensors
    • More
  • Challenges & Projects
    Challenges & Projects
    • Design Challenges
    • element14 presents
    • Project14
    • Arduino Projects
    • Raspberry Pi Projects
    • More
  • Products
    Products
    • Arduino
    • Dev Tools
    • Manufacturers
    • Raspberry Pi
    • RoadTests & Reviews
    • Avnet Boards Community
    • More
  • 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
      •  Korea (Korean)
      •  Malaysia
      •  New Zealand
      •  Philippines
      •  Singapore
      •  Taiwan
      •  Thailand (Thai)
      • 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
Arduino
  • Products
  • More
Arduino
Documents Arduino Fundamentals: Part I: Quiz
  • Blog
  • Forum
  • Documents
  • Events
  • Members
  • Mentions
  • Sub-Groups
  • Tags
  • More
  • Cancel
  • New
Arduino requires membership for participation - click to join
Actions
  • Share
  • More
  • Cancel
Engagement
  • Author Author: tariq.ahmad
  • Date Created: 16 Feb 2020 5:22 AM Date Created
  • Last Updated Last Updated: 18 Nov 2021 7:14 PM
  • Views 3970 views
  • Likes 20 likes
  • Comments 207 comments
Related
Recommended

Arduino Fundamentals: Part I: Quiz

Arduino Fundamentals: Part 1: Quiz

Quiz | Arduino Day 2021  | Workshop | Digital Fever  | Attack of the Drones | Project14 |Arduino Tutorials | Arduino Projects | Arduino Homepage

 

Are you ready to demonstrate your Arduino knowledge? Then take this 25-question quiz to test your knowledge of Arduino and see how ready you are for Arduino Certification.

To earn the Arduino Fundamentals I Badge, attain 100% on the quiz, leave us some feedback in the comments section, and give the quiz a star rating.

 

  • e14quiz
  • featured_arduino
  • arduino fundamentals: part i: quiz
  • arduino fundamentals
  • quiz
  • Share
  • History
  • More
  • Cancel
Anonymous

Top Comments

  • beacon_dave
    beacon_dave over 2 years ago +11

    Question 24 depends on whether or not you are 'sinking' or 'sourcing' the LED which has been connected...

  • tariq.ahmad
    tariq.ahmad over 2 years ago +10

    There's no one way to do #13 so in hindsight it wasn't the best question.   We've made a tweak to the quiz to reflect this and how people actually code.  We thank everyone who took this quiz early…

  • BigG
    BigG over 2 years ago +8

    Hmmm, not so sure about question 13 as you can create code such that either can apply "Place code in _____ to make an LED flash 10 times."

Parents
  • BigG
    BigG over 2 years ago

    Hmmm, not so sure about question 13 as you can create code such that either can apply "Place code in _____ to make an LED flash 10 times."

    • Cancel
    • Up +8 Down
    • Reply
    • More
    • Cancel
Comment
  • BigG
    BigG over 2 years ago

    Hmmm, not so sure about question 13 as you can create code such that either can apply "Place code in _____ to make an LED flash 10 times."

    • Cancel
    • Up +8 Down
    • Reply
    • More
    • Cancel
Children
  • cstanton
    cstanton over 2 years ago in reply to BigG

    There's the right answer, the wrong answer, and the best practice answer.

    • Cancel
    • Up +4 Down
    • Reply
    • More
    • Cancel
  • BigG
    BigG over 2 years ago in reply to cstanton

    Not sure about a "best practice" in this case.

     

    Case 1.

    void setup() {

    for (int i = 0; i < 10); i++) {insert LED code}

    }

     

    Case 2.

    void loop() {

      static int i = 0;

      if (i < 10) {

        insert LED code

        i++;

      }

    }

    • Cancel
    • Up +3 Down
    • Reply
    • More
    • Cancel
  • cstanton
    cstanton over 2 years ago in reply to BigG

    I believe it's considered that the setup would only be for one-time run commands and functions, so typically you wouldn't want to run code in a loop within it, as it's delaying the setup. Similarly not having a loop but having ten lines of 'blink' would not be very optimal.

     

    Instead you'd set it up, and then have the loop that's running to execute the ten times to blink, as it's looping anyway. A trade off might be made in a condition statement, though it then depends on your code, however because it's Arduino it's going to be executing a loop anyway and so it would be somewhat redundant if you put the code you intended to execute in the setup function.

     

    Personally I may not have declared i within the scope of the loop, I may have considered declaring it as a more global variable and re-used it as necessary.

     

    So the 'best answer' may be, use the loop that's already there, rather than introducing an additional one. Similar principle to games programming.

    • Cancel
    • Up +4 Down
    • Reply
    • More
    • Cancel
  • du00000001
    du00000001 over 2 years ago in reply to BigG

    Placing the flashing code in setup() requires a loop (or a repetition of code).

    Contrasting to that, placing the code in loop() requires some code to stop the flashing once 10 cycles have passed.

    So flashing in setup() might be somewhat easier 

    • Cancel
    • Up +3 Down
    • Reply
    • More
    • Cancel
  • phoenixcomm
    phoenixcomm over 2 years ago in reply to du00000001

    du00000001 Duh this is the way it should have been done NEVER put executable code in setup!! setup() is akin to c.h file

    what I show below  is that I used a variable 'setflash' and I set it to 0

    then in loop() I test 'setflash' to make sure it's still 0

    if its still 0 then I call my function flash() and then bump setflash to 1

    In this way, no-mater how many time loop() runs for flash will only be called the first time around! and never again.

     

    void setup() {

    int setflash = 0;}

     

    void loop {

    if (setflash == 0) {

           flash();

           setflash =1; }

    else { other stuff }}

     

    void flash( )

    // the code

    }

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • Jan Cumps
    Jan Cumps over 2 years ago in reply to phoenixcomm

    Christina, I think that’s a personal style. Not a common one. (edit: and loop() would have no access to setflash because it’s in local scope of setup(). )

     

    Most people put variables outside the setup and loop, initialise them, and set up initial state in setup,

    And then the lifecycle code in the loop.

    • Cancel
    • Up +3 Down
    • Reply
    • More
    • Cancel
  • du00000001
    du00000001 over 2 years ago in reply to phoenixcomm

    Christina, as Jan already commented: your code won't work because setflash would be local to setup().

     

    setup()   basically equals the initialization that's (maybe called as an initialization block) at the beginning of the "normal" main().

    loop()     equates the FOREVER loop in a standard main().

     

    I resently gauged a pit specific to the Arduino sketches, erroneously putting some variable declarations/initializations into the loop() function:

    while this is considered reasonable style in standard C programming (putting these into main() ), in sketches the initialization is repeated every time loop() is executed. Not exactly what I wanted to have 

     

    So be advised: loop() is not main() - it's only the endless loop in main().

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
Element14

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 © 2022 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

  • Facebook
  • Twitter
  • linkedin
  • YouTube