On the Arduino – and this is something that we really went over a little bit in Lesson – number six but it’s such an important topic and something that we’re going to really be need to be able to do for the remainder of the lessons. It’S it’s, something that you really need to do for all types of different projects and also the reason I want to go over. It is that most of the tutorials that I see on the web make this unduly complicated there’s a lot of very tedious ways of doing it there’s a lot of very difficult ways of doing it. But what I want to do is I want to show you the easy way. Okay, I just want to show you the easy way that will simply work and you’re welcome to go in and learn the more complicated or the more in depth ways, but I just want something that will work: okay for almost every project that you’re going to do. You can do the project with base by utilizing basically three different data types, there’s a lot more data types than the three, but almost anything that I want to do on the Arduino. I can do if I use one or all of these three data types. Okay, there are other data types out there, but I want to kind of have the minimum set that will meet almost all of the requirements that I’m going to run into the three data types that will get you through.

Almost all of your projects are int for integer float for floating point number and remember in the world of programming. We call them floating point numbers in math class. You would call them real numbers, it’s, all those in between numbers that are between the integers, and the third thing you need is a string and basically a string is a string of text, and so, if you can have a variable, that’s, a string for a string Of text, an int for your round, integer numbers and a float for the in between numbers, you can do almost everything now it’s, true, that if you get more sophisticated, you maybe could do things a little more efficiently or you can do things more elegantly. But if you learn those three data types and how to get them across the serial port you’ll be able to do just about everything. Okay. So, if you’re going to have a project, one of the first thing that you’ve got to do is you’ve got to kind of identify all of those variables that you’re going to need. You need to identify all the variables that you’re going to be using and not just kind of like the variable name. Remember a variable it’s, like a bucket in the name of the variable, is the label on the bucket. You need to kind of figure out the bucket in the label that you’re going to put on the bucket the name of the variable, and then you need to figure out whether that variable should be an int, a float or a string.

Well, what was the first thing that we were going to prompt the person for for their name? Well, what type of variable would that be we’ll? The name would obviously be a string, and so we want to declare that a string STR. I and G remember: it starts with a B with an uppercase s and we’re going to declare it a string now as far as what the name of the variable is that’s, just the label on the bucket, and so you can call it whatever you want. I’M, going to call it my name: okay, we’re, not initializing, this to any specific value, we’re, just declaring it as a variable, so we don’t have to put it equal to anything. Just telling Arduino hey. This is a variable we’re, going to be using so we’re going to declare D Claire a string variable thing to hold name alright. What were we going to ask for next? How old you are so when you ask a person for their age, how do they usually answer? All that usually say: I’m, seventeen around 15 or I’m 56. Those are usually answered in round numbers, and so what cut the type of variable could we use that’s right? You would call it an int, so we’re going to call we’re going to declare it an int and that’s going to be a lowercase, okay, that’s going to be a lowercase, and I think I’ll just call it something simple age: okay, declare a int variable to hold Hold your page: okay float.

I guess I shouldn’t give it away yet the third thing we’re going to do was height in feet. Well, think about that. Would you want to say I’m four feet around five feet? Well, most people are sort of in between, and so you probably would want to give that as a decimal number, so we would probably want to make that a float so float for height API hgq, high ph t”i. Okay declare float variable to hold your height okay. I think those are the variables we need, so we come down here to our void set up now, in this case, we’re not doing anything with a circuit we’re not sending anything out to the pins or reading anything to them. So we don’t have to do our pin modes, but we do have to turn our serial port on so a little bit with serial dot begin 9600. That is what we are doing, is turning on serial port at 9600 baud. You can use whatever baud rate you want, but it needs to match how you have your serial port down in the law. Your serial monitor down in the lower right. Those two have to match. I think that’s. All we need to do on the serial on the serial port. I mean on the void soda alright. So what do we want to do on the on the program? We want to prompt the user to begin with, for his name well, to read his name over the serial port to read anything over the serial port.

So we say, while serial dot available equal, equal, zero what’s that saying, while there’s nothing at the serial port. That means, while no one has entered anything as long as no one’s entered anything hang up at this point. Okay, so basically that starts the while loop to open curly braket, that in the while loop closed curly bracket, and what do we do in the while loop? Absolutely nothing. We just sit there and we go around and around and around in this, while loop waiting for serial dot available to not be zero. When the person enters the number and hits indoor hits enter, then all of a sudden serial dot available will be equal to one and it’ll drop out of this loop. But until then it’s going to sit here and wait, so we prompt the user for input. Okay, then we read it in I mean we prompt the user for input. Then we wait for it and then, as soon as it’s there, we read it in okay. Now the first thing that we are going to do is we are going to read the string. Okay, so we’ve said that you can do almost everything with a string, a float run int. So the first thing we need to review here is: how do you read a string over the serial port? Well, first of all, you have to put it inside of a variable which variable were we going to put the person’s name and we’re going to put it in my name, and my name is going to be equal to what well we’re going to do a serial Dot we’re going to read the name over the serial port what’s, the command for reading the name, let’s serial dot, read string and you got to do it just like this serial uppercase s, dot, read, string, uppercase s, okay and you see when you do it right.

What do we do? We wait? So, while cereal available is zero, while we’re waiting for him to put it in there, we just circle along here, then what we do. We read it what’s the variable we’re going to read we’re going to read the variable age. Okay. Now, how do we read an int over the serial monitor? We wouldn’t read it with read string and we wouldn’t read it with read: int it’s a different command, its serial dot, parse int. Okay, see it turns orange because it recognizes it okay. So now we have the person’s name, and now we have the person’s age so what’s. The next thing we want. We want their height so again, I’m, going to paste those three lines: disabled it’ll work, we’re going to prompt them for their weight, and so what we’re going to say is how how much do you weigh so we are prompting the user for his weight. Then what do we do? We wait and then, when something has been entered, we drop out and we say: wait because that’s I’m sorry height how much I messed up help tall are you we were doing height, not weight. How tall are you prompt the user for his height weight for it and then read it into which variable it’s a variable that we called height HT? Okay, now we are not going to read string because height is not a string. We are not going to parse int, because height is not an int, then we are going to parse float because it is a floating point number.

So basically, if you look at this code right here, these are the commands that you need to do just about anything to get just about anything you’re ever going to need to off of the serial monitor. If it is a string, you use the command serial dot. Read string if it is an int, you use the command serial dot, parse int with a capital. I uppercase, I okay and then, if it is a float, you use the command serial dot. Parse float simple as that prompt them for the input wait for it with the while loop, the empty while loop and then go out and read it and just keep track of whether you’re going to use a read string, a parse int or a parsefloat command. Okay, let’s practice our printing a little bit so now, let’s come over here and let’s let’s sort of print. These things out so let’s send the person a gradient greeting back and let’s, say Siri, dot, print and let’s, say hello to them: aqui ello, oh, and then I put a space now. Why did I not put print L in print light? Because I want to string together several of these print statements, so it makes a nice sentence and I don’t want it to go to the next line, because I want to say hello and then the person’s name. In order to say hello and the person thing on the same line, I need to make sure that I don’t advance to the next line, so I say serial dot print line.

Hey I mean serial dot, print, okay and I’m. Just going to put all my comment here for all the next thing produce nicely: formatted: output, okay, now I’ll just call that comment good for the rest of the things. So now, what put is the person’s name I’m going to say serial dot, rent, okay, okay, and what is their name? Their name is a string, and the variable name is my name, okay. So my name okay. Now this is something very important, and this is something where students get messed up all the time if you’re just going to print out verbatim the word hello it’s, not a variable it’s, the string, hello and these string hello. You tell it that it’s a string by putting it in the quotes, but if you’re going to print a variable, my name is a string variable, you want to say print line, a serial print, my name you don’t, put quotes around it because it’s a variable, if You put quotes around it. It would put print out my name as opposed to the person’s name, but because we want the the value in the bucket, not the label on the bucket we don’t put quotes so hello, we’ll print hello, serial dot print. My name we’ll put thing whatever the content of that bucket is whatever the person told you that the name was no quotes in that case. Okay, now you need to give him a message: okay, serial dot, print B, we’re going to say, comma.

You are we’re going to tell them how old he is notice that I have to put that space after our, because if I don’t put that space after our it’s going to come in and put their age crammed up against the e here, you have to put That space and it doesn’t know to put that space in now, a serial dot, P dot print. Now what is their age? Their age is H. You are H again, age is a variable, so we don’t put the quotes on it. We want them to tell us the number we’re going to tell me the contents of that bucket H. You are age and serial print and then we want to put space so that it doesn’t run up against the end of the age space geo print years old period. Okay, that’s, probably enough for one line, so let’s get all of that. Let’S go to print l in and now it’ll go to the next slide, but all on the same line. You’Ll say like hello, Jo, you are 14 years old, that’ll all be on one line and then we’re going to say serial serial dot print and you are instance that’s a specific string and you are spaced the age, serial, dot, print serial dot print. And here we are going to put on – and you are height so we’re, going to put HC IG HT the variable serial, dot, n dot print space 8 tall period, okay and then we’ll wrap it up serial dot, print well n, so that this will finish off.

That line, and that did finish off let’s see we should finish off the line there with that Ln. Okay, so it’ll say hello, Joe. You are 15 years old if he entered 15 and then on the next slide, and you are four and a half feet tall and then what I’m going to do here is I’m just going to print a blank line. Just quote: quote: plant a print, a blank character and that will print a blank blank line. So I get some vertical spacing in there. That’Ll look nice. Ok! So just remember the things that you all want to go on. One line you just have cereal print, serial.print cereal print and then, when you want to finish that line and go to the next line, you put serial.println also notice that I’ve been careful to put my white spaces in and one of the things that really. I count off on what I come around and grade your work and other people if you’re taking this online. Other people are not going to like it if you don’t, if you’re, not careful about formatting your output, where it’s easy to read and that make means make sure that you put your white spaces in like. If you say on 33 years old, you don’t want to say I am 33 and then the three and the Y without a space you’ve got to put that space in there or your formats not going to look good.

Okay. So after I read that last thing that last input I’m just going to do a print, a blank line here at C rot right dellynne I get a blank line by just poped quote with nothing in it and then close that off. I think that will look a little bit nicer. I always I kind of do the best. I can the first time through and then I come back a second time and just clean things up a little bit so now let’s look at this. Please enter your name. I am mister reporter. Okay, how old are you? I am 53. How tall are you? I am 5.9 feet tall now, let’s see hello. Mr. McWhirter, you are 53 years old and you’re 5.9 feet tall because I said, and here that should not have been a period that should have been a comma, so let’s come here and say comma. So, like I say you do the best you can and then you look at any sort of tweak things to make it a little better. We did not like that. Let’S. Try it again again. I’Ve got this long, USB cable, so that my thing will reach over here and it think it might have taken at that time. Let’S see and mr. Porter I am 53 years old. I am 5.9 feet tall, okay, hello, mr. McWhirter. You are 53 years old, comma and you are 5.9 feet tall, okay and how let’s let’s say that it was mrs.

I want you to calculate their weight in ounces and then I want you to calculate their weight in grams and then I want you to calculate their weight and carrots that see AR et, like a diamond like a diamond. Is one carat that’s a weight, not a carat, not a CA. Rr ot like you eat, but a carat like a diamond or a gemstone, see AR 80 so calculate the person’s weight in carats and then give them their weights back to them and nicely formatted output. And so let me show you what it should. Look like. Okay, please enter your name. I am mr. McCourt er. Okay, how much do you weigh in pounds? I weigh 190 pounds. Ok and then it should come back and say hello. Mr. McWhirter, you weigh 190 pounds. You weigh 3040 ounces. You weigh eighty six thousand one hundred and eighty two point: four nine grams and you weigh four hundred and thirty thousand nine hundred and twelve point: seven, five carats, okay, and this is what it should look like and then you can put your name and your weight In there, but you can test it with my number to make sure that you’ve done the conversions now I’m, not going to tell you the conversion factors you’re going to have to go in and do a little research on the internet to figure out how to do Those conversions, but when you figure out how to do those conversions, then you can program them into your Arduino and I will come around for a grade tomorrow and I will be looking for nicely formatted text where you have the right.

You have white spaces where you need white spaces and you have spaces along the line where you need spaces along the line, and that is what I will greet you on tomorrow. Thank you very much guys. This has been Paul McCourt at top tech boy, calm and tomorrow we will hopefully see you again for lesson number 13.

# Paul McWhorter arduino lesson 13 Video

[mam_video id=VIa_QZWIonQ]

[mam_tag id=5698]

# Paul McWhorter arduino lesson 13 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.