This is going to be a short lesson, but an important lesson in lesson: number five. We will be using the same circuit that we have used in the last couple of lessons. Specifically, that is this one here you can see down in the lower left. We already have it hooked up, but if you need to take a few minutes to get it hooked up, hopefully you already have it hooked up because we’ve been working with it for a while, but if you don’t, you can pause here and hook it up. If you need help and hooking it up in lesson, number three watch the video. I go through it step by step about how to get it hooked up, but hopefully you’re getting comfortable with it at this point and that you can just kind of hook. These things up yourself, we will be using this schematic for this exercise and then also, hopefully in lesson number three and lesson number four. You still have your code. If you don’t have your code, I have it here, go to top tech boy. Comm go to lesson! Number five and you can get the code if you want to get the code, you can get it right off with this right off of this posting I’ve said this before and I’ve said this again. I really hope that you’re not just going in and copying and pasting my code, because if you do that you’re going to be able to mirror image what I’ve done, but you’re never going to be able to do anything on your own.

Let’S just give a quick recap of this code. The last thing that we talked about was let’s see we set everything up here. We declare our variables and assign our variables and two of the key things are the number of time that the yellow, LED blinks is set to five the number of times the red LED blinks is set to five, and then we have two for loops. We we loop through this for loop blinking, the red five times we blink through this. We loop through this one five times to blink the yellow one five times, and so we’ve got two for loops. By changing these two numbers, we can change how many times these respectively blink and by setting these various time parameters up here, we can control how long each one is on or off so by playing around with this code up here, we can make these LEDs do Whatever we want them to do, okay, what we talked about in Lesson four is: is that you get to the point, though, that you want to be able to interact with the outside world, so we do that over the serial port and your void set up. You turn your serial port on with a serial begin. I’Ve set the baud rate here to 115200. If we look at the serial monitor by clicking here, you with a little look – and I need to maybe pop this up here – what you can see is the things that we are saying to print here are printing out on our serial monitor.

Also, if you look, the serial monitor, is in sync with a circuit over here. So it says: blinking red as it’s blinking red it says. Blinking, yellow is it’s, blinking, yellow, so everything’s kind of starting to work together, live and so that’s sort of that’s sort of exciting we’re kind of getting a lot of things going a lot of different directions here, but one of the things I want to talk to You a little bit about here today is using strings in our lessons up in this point. We’Ve used a lot of variables, but we have always used variables of type int for integer, which means everything that we’ve done so far. That’S been a variable we could handle with an integer and an integer. Basically, the round numbers it’s like minus one, zero one, two, three four it’s the positive and the negative round numbers with also including zero and because we’re doing things like blinking a certain number of times or we’re. Talking about a certain pin. All of those things can be represented by round numbers if you think I’m going to have a pen, 9 or I’m going to have pen 10, but I would never have pen 9 and a half, so I can use integers on the amount of time that I’m Going to leave the LED on in milliseconds 250, you know we would in in milliseconds. We probably wouldn’t want a fraction of a millisecond, so we can use integers there now if we want the in between numbers or what you learned in math classes, the real numbers.

What we would do to get the in between numbers or the real numbers? We would declare these things as floats. So once we start doing, calculations like let’s, say we’re going to do a temperature sensor and we’re going to measure temperature and then we’re going to put the temperature that temperature reading in a variable that we called temperature. We probably want that to be a float, because you might want to know that it’s 87 and 12 degrees it’s supposed to 87 point three degrees. And so, when we start doing more precise calculations we’ll go to float. But the reason for using intz ints intz is integers is that they take a lot less memory in the microcontroller. Now, when we’re doing, Windows, machines and we’re writing programs, you don’t think about you’ve got just so much memory in your big machines a lot of times. You don’t think that much about how much memory a float versus an int would use, but when we get down here to the Arduino, you can actually run out of memory on board. An Arduino and I’ve had several programs that have gotten complicated enough that actually ran out of memory, and so, when we’re working on a microcontroller that’s got a more limited amount of memory. We do want to be mindful about using intz versus using floats, but what I’m really going to talk to you today about in this videos? It’S, not about floats it’s about a different type of variable, called a string and a string is really it’s.

A string of characters. Okay, so if I want to say the word hello, the word hello would be a string of characters, and so I would declare that as a string and if you look, I sort of already started using strings this last program. It’S, just we didn’t declare them a variable. We just plugged the string in we didn’t put the string in a variable. We just use the string directly and so, for instance, in this line here, where we say serial dot print line, the red LED is blinking. The red LED is blinking, those are inside, quotes the double quotes, and what that’s telling Arduino is everything between those double quotes? Is a string and it’s saying hey print everything between the double quotes and what’s between the double quotes is the string, but what I want to show you is there’s a different way to do that that we can actually take that string and we can put it Into a variable, what type of variable would we need a string variable if we’re going to use a variable in Arduino? We need to declare the variable remember that if we do things up here, they are global variables, meaning anything we declare up here everywhere in the program is going to know it and so we’re going to go ahead and make this a we’re going to go ahead And make this a global variable, and so what type of variable should it be? It should be a string, and it makes me happy that it turns orange, which means I type it in right, because it recognized it sometimes it’s kind of funny.

If you look at int, you declare an int with the lowercase I, but if I try to declare string with a lowercase s, it doesn’t work string, needs to be a capital list and that’s. Why it’s kind of nice in these integrated development environments, like we are using here and maybe a third time, will be a charm there? It is, is to watch when something doesn’t, color it’s sort of a flag that it hasn’t been recognized in. So you see string so we’re going to declare a variable in the variable that I’m going to declare is red message: okay and read messages the variable it’s, not a it’s it’s, a variable of top string, it’s a variable now that I can assign a string to And what do I want to assign to read message? Well, my read message was down here: the red LED is blinking, the red LED is blinking blinking, okay, and we will close that it turns blue, which means hey. I recognize it so that always gives us a little warm fuzzy feeling when these things turn colors. It means that it’s recognizing what we’re doing and then what we are doing is we are declaring a stream variable. Okay, the variable is red message. That’S, like the bucket, the bucket is called red message. The message in the bucket is the red LED, is blinking, so you’ve got to get your mind around the difference between the name of the variable that’s, like the label that’s on the can, and then the message in the can is the red LED is blinking.

It says read message you just said print that exactly you don’t want to print the string. Read message. What you want to print is: there is a bucket named a bucket. A variable named, read message: what message is in that bucket? The red LED is blinking, so we don’t put quotes around it. If you want to directly print a string, you put the quotes around. If you want to print the variable that contains the string you don’t put, quotes on it, and the reason I kind of go into this is: is that it as I’m teaching students? It seems to me this is something that they stumble on. You stumble on for a little while, but once you kind of get familiar with it, it’s really pretty it’s, really pretty easy, and so just think of the variable as a bucket and the variable name is the label on the bucket and then the string or the Number or whatever it is, what value you put you put in that bucket. So just like, we said, read message here down here. We should probably set this to two yellow message: okay, but if we’re going to set this to yellow message, we’ve got to declare the variable. You can never use a variable without declaring it. So we come down here. What type is it going to be it’s going to be a strong it’s going to be yellow message, and so we just made a new bucket that new bucket is labeled, yellow message.

And what message are we going to put in the yellow bucket we’re going to say the yellow LED is King end closed everything out, don’t forget the semicolon, be a good boy and put a comment. We are declaring a stream very edible. Okay, so now let’s see – and now we come down here and instead of printing the string directly we’re going to print we’re going to tell it to print the variable yellow message print the print. The contents of that variable is what we’re going to say. Oh wow did I do wrong because I am NOT so there is no in prepares no in parentheses needed there. Okay. Sometimes I make mistakes on purpose just to see if you’re paying attention that one was just a good old fashioned real mistake. So let’s look here: okay, so the red LED is blinking. That is red message. Red message is the red LED is blinking, yellow LED is blinking that’s, yellow message, but yellow message is set up here and so that’s just kind of neat that’s, a that’s sort of a that’s sort of a handy thing that you cannot just have numbers or numerical Values in variables, but you can also have strings and texts and there’s also things that you can do like let’s come down here. I don’t have to declare my variables up here: okay, I’m, going to make a local variable I’m going to make a local variable and I’m going to make it in my void setup, which means the only buddy that knows about this.

This variable is going to be void setup if I’m outside the void setup it’s not going to know about it’s a local variable, local to void setup but I’m, going to make a string, I’m going to say string does not like it because I said sting string Is going to be equal to I’m, going to say hello or I’m going to say, welcome to and welcome to all right, be good and put a comment, declare a string variable and assign a value so I’m declaring the string. I forgot to put the name here: I’m going to say: welcome message: 1, WM, 1 we’re going to declare the string variable and the name of the bucket is WM 1 and its content is welcome to remember anything that I put out here after these slashes it’s. Just a comment: Arduino doesn’t read it but it’s just for me and anybody that might be working with me to know a little bit more it’s like what am I thinking why don’t I put in that line in there. Okay now let’s make another string. Another variable string welcome message: 2 is going to be equal to and I’m gon na say my program, ok and then close that, and what did I forget up here? Why didn’t you warn me why didn’t somebody stop me inside in your semicolon: okay and then I’m gon na cite slash, slash, Eclair screen, variable wm2 and assign a value. Okay, so I’ve made two new string variables.

The first one is labeled WM, 1 and that’s. Welcome to the second variable, the second bucket is labeled WN 2 what’s inside that bucket the words my program, okay, and actually I need to do that after I turn on the serial monitor. So I like that sorry about that, need to get that serial, monitor on because I’m going to try to print something here and then let’s say that I’m now going to do a serial dot print line – and I just say: WM: 1, okay and I’m, going to Close that and let’s see what happens when we do that and this we’ll just do it one time it won’t loop, because it’s in the void, setup, you’ll just print it one time, okay and now let’s see what I have here welcome to all right. Why did it print the rest of it because I didn’t tell it to print the rest of it? I just said serial print line, W m1 okay. So if we want the rest of it, let’s make it and you’ll see why I’m doing this in a minute. You’Ll see I’m kind of trying to show you some new stuff you can do, but it will make sense admit what I’m doing this way: okay, serial dot print line and what’s the next thing that I want well, I want them to be 1 2, that 2nd String variable I’m going to print that now, let’s download that okay now it says, welcome to my program.

Well, it kind of printed the two things but it’s printing one on one line: the next on the next slide. How could I get this all to print on? One line: do you remember that this print line says go to the next line? Well, on this first one, we want it to stay on that line, so we just want to do a print if I just do a print now, I can come over here. Okay and I can wait for it and then it says – welcome to my program now what’s wrong with this look at this welcome to in my program, but I didn’t put a space in there anywhere. I guess I could make a third variable, which was a space and print that, or I could just add a space here and now, if I do that, it’ll print that space as far as as part of the first one let’s see what happens. Okay, welcome to my program: okay, that’s, looking pretty good that’s, looking pretty good, but I did it with two variables. Okay, I want to show you something that you can actually kind of almost do math or it’s called concatenation. What, if I want to bring those two strings together, make a new string, so let’s make a new string. My new string is going to be wm3, okay and then what’s wm3 going to be equal to and this what are we’ll show you is. I just declared the variable I did not assign a value to it.

You can just declare a variable without assigning anything to it. I’M, just gon na say I declare a string variable wm3 that’s, just a play so we’re, saying later on I’m, going to use a variable called wm3 it’s, a string don’t panic I’ve told you that I’m going to use it. Okay, I’ve told you I’m going to use it so I’ve declared it, but you can’t use it until you declare it now I’m going to come down here and now I’m going to assign a value to it. Wm 3 is equal to w m1 plus w m2, and what this is called is this is called concatenation. It puts the two strings together and it puts them in a new bucket called WN 3, which I declare it in the step above and so let’s come up here and say that we assign aa, WM, 1 plus or basically, what we’re doing is. We are concatenate in and I’m, not even going to try to spell that right: concatenative WM, 1 WM 2 and into WM 3. So I take WM 2 WM 1 WM to put them together and then put it in a new variable called WM 3. And now what I am going to do here is I’m going to print WM 3 and with a little luck let’s see what happens, looks like it’s going to compile. That is always good news, and then we look and look at that. Welcome to my program and it’s, okay, I see what’s happening you see.

Only the red LED blink is blinking it’s I mean the yellow LED, is blinking everything sort of working together, and so one of the things that we have to do as a programmers make our program work in the real world, make it work with real people who Might not be programmers or might not be engineers, and so we’ve got to sort of wrap our code and stuff that’s, very usable and very intuitive for people to to use and right now we just start by by trying to make our text well, formatted and and Document our code and make things where it’s sort of easy to understand what is going on. Okay we’ve had a little bit of fun with strings. I appreciate you tuning in for lesson number five. Please come back for lesson number six and lesson number six we’re going to be seeing. How do you get information we’ve seen how to get information from the Arduino to the screen? How do we get information from the screen down into the Arduino? We want to start sending data the other way on the serial port, and that is a really really important thing and that’s what we will be doing in lesson. Six again on Palma, quarter from top tech boy.

# Paul McWhorter arduino lesson 4 Video

[mam_video id=DwOLDLDqWUk]

[mam_tag id=5735]

# Paul McWhorter arduino lesson 4 Social

official.arduino
2019-11-01T16:44:56+0000

Use an Nano 33 BLE along with arturo182’s BBQ10 keyboard to create a functional BLE HID keyboard: https://bit.ly/2N7ST8H
official.arduino
2019-11-01T12:50:41+0000

Deforestation is one of the most significant problems our generation faces across the world. To address this issue, Senso is a MKR FOX 1200-based device that can identify the sound of logging machinery and notify relevant authorities.