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 3979 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
  • phoenixcomm
    phoenixcomm over 1 year ago

    genebren Gene, you can only have a good programming style which is an art in itself.

    for instance in my normal program.

    program xyz.c or xyz.pde

    #incllude <pins.h>  //#define pinName  pin Number  or int pinName = 30,

    #Include <modes.h>  // pinMode( pinName, INPUT_PULLUP );

    void setup() { }  /is only for assingments like i=0, or things that are run once ie. bitSet(TCCR1B, CS12);  // 256 prescaler  NEVER LOOPS!! unless you are Initalizing an arry buy I might just put the array in a .pde file and include it.

     

    now Loop() is the other bag of worms how do you exit the loop so if you had this code:

    void loop() {

    int i =0;

    int iMax = 100;

    for i = 0 ; I < 100; I++){

    print i; }}

     

    what would do?? yop count 0 -100 forever. there is no control mechanism to leave the loop. such as

    int main() {

    do {

    somethine

    } while (n == TRUE);

    retrun( erroNum()); }

    }

     

    and every function.c should have a function.h  in this way you choose what to expose to the world.

    That's why I do my Arduino programming in C on Eclipse IDE.

    ~~Cris

    • Cancel
    • Up 0 Down
    • Reply
    • More
    • Cancel
  • WestfW
    WestfW over 1 year ago in reply to phoenixcomm

    void setup() { }  /is only for assingments like i=0, or things that are run once ie. bitSet(TCCR1B, CS12);  // 256 prescaler  NEVER LOOPS!! unless you are Initalizing an arry buy I might just put the array in a .pde file and include it.

    Since you're still posting this opinion after a year, I thought I'd offer a counter-opinion.

     

    1. setup() is just a C++ function.  You can put any code you want inside it.  The statements inside of setup ARE "executable code", so your earlier emphasis ("NEVER put executable code in setup!" is just wrong.  Your examples all contain "executable code."  (loop() is just a C++ function too.  I interpret the current form of the question as checking whether the quiz-ee understands that they're just functions, not "magic names that do something special."
    2. A statement like "Serial.println("Arduino sketch that does neat things!");" inside setup() is entirely appropriate.  And guess what?  It loops (down inside of Print, but still... looping is looping.)
    3. It is a STANDARD RECOMMENDATION, when porting C code to Arduino, to "rename main() to setup() and leave loop() empty."  setup() behaves essentially similar to main() in a normal C program, except it happens after the core code sets up the chip for the Arduino environment.
    4. For the example from the quiz "blink an LED 10 times" (or any "do X for a limited time" scenario), you wind up with three choices:   A) Put a loop in setup().  B) put loop inside of loop() and then have it stop.   C) torture and obfuscate code in loop to let it do the LED thing 10 (perhaps 20) times and then have it stop touching the LED.   All of these have advantages and disadvantages, at least stylistically.  None of them are going to fit well within the "best style for Arduino sketches" because the example is NOT a good example of a typical Arduino application...

     

    void setup() {
      pinMode(13, OUTPUT);
      for (int i=0; i < 20; i++) { // 20 toggles == 10 flashes.  Check for fenceposts!
        digitalWrite(13, !digitalRead(13));
        delay(500);
      }
    }
    void loop() {}

     

     

    void setup() {
      pinMode(13, OUTPUT);
    }
    void loop() {
      for (int i=0; i < 20; i++) {  // 20 toggles == 10 flashes.  Check for fenceposts!
        digitalWrite(13, !digitalRead(13));
        delay(500);
      }
      while (1) ;   // stop
    }

     

    void setup() {
     pinMode(13, OUTPUT);
    }
    int i = 0;   // global counter
    void loop() {
     if (i < 20) {  // 20 toggles == 10 flashes.  Check for fenceposts!
        digitalWrite(13, !digitalRead(13));
        delay(500);
        i++;
      }
      // after 10 flashes, loop will do nothing.
    }

     

    (I should add that I dislike the third example, IF all you need to do is "flash the LED 10x."  However, it is the path that you'd need to go toward if you wanted to "flash the LED 10 times WHILE ALSO DOING SOMETHING ELSE.")

    • Cancel
    • Up +1 Down
    • Reply
    • More
    • Cancel
Comment
  • WestfW
    WestfW over 1 year ago in reply to phoenixcomm

    void setup() { }  /is only for assingments like i=0, or things that are run once ie. bitSet(TCCR1B, CS12);  // 256 prescaler  NEVER LOOPS!! unless you are Initalizing an arry buy I might just put the array in a .pde file and include it.

    Since you're still posting this opinion after a year, I thought I'd offer a counter-opinion.

     

    1. setup() is just a C++ function.  You can put any code you want inside it.  The statements inside of setup ARE "executable code", so your earlier emphasis ("NEVER put executable code in setup!" is just wrong.  Your examples all contain "executable code."  (loop() is just a C++ function too.  I interpret the current form of the question as checking whether the quiz-ee understands that they're just functions, not "magic names that do something special."
    2. A statement like "Serial.println("Arduino sketch that does neat things!");" inside setup() is entirely appropriate.  And guess what?  It loops (down inside of Print, but still... looping is looping.)
    3. It is a STANDARD RECOMMENDATION, when porting C code to Arduino, to "rename main() to setup() and leave loop() empty."  setup() behaves essentially similar to main() in a normal C program, except it happens after the core code sets up the chip for the Arduino environment.
    4. For the example from the quiz "blink an LED 10 times" (or any "do X for a limited time" scenario), you wind up with three choices:   A) Put a loop in setup().  B) put loop inside of loop() and then have it stop.   C) torture and obfuscate code in loop to let it do the LED thing 10 (perhaps 20) times and then have it stop touching the LED.   All of these have advantages and disadvantages, at least stylistically.  None of them are going to fit well within the "best style for Arduino sketches" because the example is NOT a good example of a typical Arduino application...

     

    void setup() {
      pinMode(13, OUTPUT);
      for (int i=0; i < 20; i++) { // 20 toggles == 10 flashes.  Check for fenceposts!
        digitalWrite(13, !digitalRead(13));
        delay(500);
      }
    }
    void loop() {}

     

     

    void setup() {
      pinMode(13, OUTPUT);
    }
    void loop() {
      for (int i=0; i < 20; i++) {  // 20 toggles == 10 flashes.  Check for fenceposts!
        digitalWrite(13, !digitalRead(13));
        delay(500);
      }
      while (1) ;   // stop
    }

     

    void setup() {
     pinMode(13, OUTPUT);
    }
    int i = 0;   // global counter
    void loop() {
     if (i < 20) {  // 20 toggles == 10 flashes.  Check for fenceposts!
        digitalWrite(13, !digitalRead(13));
        delay(500);
        i++;
      }
      // after 10 flashes, loop will do nothing.
    }

     

    (I should add that I dislike the third example, IF all you need to do is "flash the LED 10x."  However, it is the path that you'd need to go toward if you wanted to "flash the LED 10 times WHILE ALSO DOING SOMETHING ELSE.")

    • Cancel
    • Up +1 Down
    • Reply
    • More
    • Cancel
Children
  • phoenixcomm
    phoenixcomm over 1 year ago in reply to WestfW

    WestfW Bill this is a never-ending story! I know that setup is a function in C++ but I still disagree.

    let say you want to initialize an array[] = {{........ll.}, {.....}...............} is fine.

    when I set my IO pins to names  I do it with #defines as it makes life easier and this is in its own file. that is included before the setup().

    saying this you could make your assignments with a loop ie..   for ( int i = 22;  i < 40;  i++ ) {

    if ( i > 30 ) { set pinMode (i, OUTPUT); }

    else {

    set pinMode (i, INPUT); }

     

    now about loop(), main(0, init() personly I set up my code like blocks one sits on the other. so this is what I do:

     

    //each function  has  a assoceated .h file and some times 2 as some may be public, and some private.

    #include main.h // this has a lot of things the main() needs

    #include inti.h // most of stuff that the init needs

    int main ( argc, argv) {

        init() // this is atken to setup

        setup() { the Radio Sub Stystem in my Sim, init and setup are very diferant animials. }  

       do {

    } while(  sometihg is true);

     

    ~~Cris

    BTW Modularize your code. easier to read.

    • 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