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.


ratings:
Length:
11 minutes
Released:
Mar 26, 2017
Format:
Podcast episode

Description

Discussion: This lesson covers one of the most fundamental of all programming concepts:  Variables. This is a really exciting topic because once you have a handle on how variables work, you have one of the biggest keys to understanding how programming works. Specifically, we'll be discussing: Memory Data Types Declaring a Variable Naming Conventions Initializing a Variable What is a variable?  Variables are a programming tool that help us store and recall information in our programs. Memory A microcontroller, like the one the Arduino uses, as well as computers in general, have something called memory.  Memory is really handy because it allows us to store information for use at a later time. Let's say I'm working on a project that will monitor temperature during the day.  I have a temperature sensor that reads the current temperature every 60 minutes from 1 am until midnight.  I want the program to record the highest temperature and then display it at the end of the day on an LCD screen. In order for the program to accomplish this, it needs to store two key pieces of information.  It needs to store the value of the current temperature, and then it also needs to store the value of the highest temperature that it has encountered thus far. But how do we actually save this information in a sketch?  Furthermore, how do we recall it when we need to remember it?  In order to do this, we need to use the memory. For now, think of memory as a big wall of lockers, and you can use the lockers to store something.  When you need that something again, you just go back to locker and grab it. But how do you remember what locker you put it in?  In order for us to do that, we first have to give the locker a name.  That name you gave to the “locker”, the place where you’re storing your stuff, is called a variable. Now technically speaking, a variable is the named address of a specific location of memory.  However, I don't want to get caught up in all of the technical stuff.  I want to dive into the practical use of variables.  Therefore, let's go back to this temperature project. As previously stated, we want to record the highest temperature during a 24 hour period.  For our program, I need to store those two key pieces of information: the current temperature and the highest temperature. That means I’ll have to name two lockers.  I’ll call one locker "Current Temperature", and I'll name another locker "Highest Temperature". Let's say my Arduino begins taking the first reading of the day.  Maybe the temperature is 50 degrees.  So I'll open the “Current Temperature” locker, and I'll put in the number 50. At the same time, I'll also open up the “Highest Temperature” locker.  Right now there's nothing in it, but 50 is larger than nothing.  Therefore, I'll put the number 50 in the “Highest Temperature” locker, as well.  So now both of our lockers have the number 50 in them. After 60 minutes pass, I read the temperature again.  Let's say it has raised two degrees to read 52 degrees Fahrenheit outside. I open up my “Current Temperature” locker, and I put in 52.  This means that 52 overwrites the number 50 so that now the “Current Temperature” locker has the number 52 in it. I also peek inside the “Highest Temperature” locker.  I see that 52 is hotter than 50.  I go ahead and replace that also.  I'm just going to repeat that process every hour. I open up the “Current Temperature” locker, replace the old value with the new value, and then check to see if I need to replace the temperature in the “Highest Temperature” locker. This reveals the first really important thing about variables and the most powerful thing about variables.  The contents of a variable change.  The name of the variable stays the same because the variable is just the container for the information. We don't want to confuse it with the actual information itself.  The variable is the locker.  It's not the actual stuff inside the locker. Let's recap what we’ve learned thus far.  We nee
Released:
Mar 26, 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.