Discover this podcast and so much more

Podcasts are free to enjoy without a subscription. We also offer ebooks, audiobooks, and so much more for just $11.99/month.

Understanding the Arduino uber functions loop() and setup()

Understanding the Arduino uber functions loop() and setup()

FromLearn Programming and Electronics with Arduino


Understanding the Arduino uber functions loop() and setup()

FromLearn Programming and Electronics with Arduino

ratings:
Length:
10 minutes
Released:
Mar 29, 2017
Format:
Podcast episode

Description

Discussion: In this lesson, we're going to discuss two very special functions that you will use in every single Arduino sketch that you write.  They're called Setup and Loop. Specifically, we’ll cover: How Setup Operates and the type of code that it executes How Loop Operates and the type of code that it executes Loop Function’s Responsive Outputs How to get those little ships inside the glass bottles I want you to pretend for a moment that you own a specialty Italian sub shop.  Business is great, and you have wonderful customers. However, you have one major problem.  Employee turnover is very high.  This is mostly because the majority of your employees are teenagers who, by nature, tend to move on to different things. It feels like as soon as you get an employee trained, they move on to Harvard Business School or get a scholarship to MIT - or they just decide that bungee jumping all day long is better than making subs. In order to help train new employees, you create two binders of procedure lists.  One binder is called “The Morning Setup Binder”, and it lists all the stuff that you have to do when you open the store. This binder contains things like unlock the front and back doors, turn on the “Open” sign, put the delivered sausage in the fridge, and get the broccoli out of the fridge.  It's stuff that only has to be done once. Once all of that stuff has been done, a new employee can take that binder and stick it on the shelf.  Then, they can pull out “The Sub Making Binder”.  This is the binder that lists step-by-step everything an employee has to do to make a sub and deliver quality customer service. It might go something like this:  When a customer walks in, welcome them with a warm, "Hello!"  Ask them what type of sub they want.  Ask them what type of bread they want.  Ask them what type of condiments they want.  Ask them if it will be for here or to go.  See if they want to add one of Mama's homemade cookies to their order.  I think you get the gist. The binder lists these steps in detail and talks about the quantities of toppings for different subs.  “The Sub Making Binder” is really the procedure list that drives the task of the employee and will be the binder that the new employee will keep open all day long when they're starting out.  They're going to go back to it over and over again for every sub. So, what does this have to do with programming?  Well, a program in Arduino has to do similar things like the sub shop. The Setup Function There are certain tasks that need to be done just once when the program first starts.  These are things like: setting up a serial communication to talk with the computer over a USB port, setting the modes of microcontroller pins as either inputs or outputs, displaying a welcome message on an attached LCD screen, or possibly turning a servo to a default location. All of these things might only need to happen once when the sketch first starts and never need to be bothered with again until the program is restarted or the Arduino is reset.  These are the type of tasks that are put into a special function called Setup. Let's take a look at Setup.  First, notice that the color of Setup is different.  Unfortunately, the color is reminiscent of baby poop. This automatic coloring, though, is letting you know that the Arduino IDE recognizes the function Setup as a special type of function that's used for controlling the structure of the code. You'll also notice that right after the word Setup there is an opening and closing parenthesis.  The Setup function doesn't need any arguments to operate, but you still have to include the opening and closing parentheses just as you would in any other function. To the left is the word void.  Void means that the Setup function will not return any data. So this is a function that doesn't need any arguments from us in order to operate and doesn't return any values to us, but it does do something.  Its job is to execute all the code inside its opening and
Released:
Mar 29, 2017
Format:
Podcast episode

Titles in the series (61)

Video lessons on learning programming and electronics with Arduino. This is part of our Arduino Crash Course and Arduino Course for Absolute Beginners. It's designed to take someone with little or no experience in programming and electronics and get them fast-tracked to learning the skills to prototype using Arduino. We'll include some lessons from the first edition and the second edition of our training course.