WEBVTT

00:00.180 --> 00:07.350
Now, we have only used so survivors, we have only use integers for round numbers, but actually there

00:07.350 --> 00:09.090
are more data types you can use.

00:09.510 --> 00:12.830
So what kind of data that we will need in our program?

00:13.110 --> 00:16.180
The first foreign numbers, we have integers.

00:16.320 --> 00:22.250
Now, we also need let's say you want to store the value three point fourteen.

00:22.590 --> 00:26.050
You can put that in an integer as you try to do it.

00:26.640 --> 00:28.990
C is equal to three point fourteen.

00:29.250 --> 00:33.840
Well, this will be truncated and the real value will be three.

00:34.230 --> 00:36.280
OK, so how to store that?

00:36.300 --> 00:43.160
Well, you can use the float number so you can use float data type here.

00:43.500 --> 00:52.380
All you can use double the are roughly the same and you can store float number inside double and float

00:52.520 --> 00:52.780
that.

00:53.250 --> 00:55.970
So then of course you can do everything we did before.

00:55.980 --> 00:59.910
You can do a variation like plus minus multiply divided.

01:00.360 --> 01:03.030
You can combine variables, et cetera, et cetera.

01:03.390 --> 01:11.730
Another common data type that would be useful for us is the Boolean so that it will be bool and then

01:11.850 --> 01:16.890
name and a boolean can contain only two values.

01:17.130 --> 01:17.670
True.

01:18.890 --> 01:26.390
OK, you can see it turning blue or false, the booleans will be very useful when we try to test some

01:26.390 --> 01:30.090
conditions, for example, when we press a button in the car.

01:30.120 --> 01:33.430
We want to know where is the button priced or not.

01:33.800 --> 01:38.840
And in this case, we can use a Boolean to check that either it's true, it's false.

01:38.840 --> 01:43.160
And we are going to come back later to this when we see the conditions.

01:43.670 --> 01:51.650
And lastly, I'm going to show you the data type string, the string with an uppercase S. And this data

01:51.650 --> 01:55.100
type is actually not in the C and C++ language.

01:55.400 --> 01:57.290
This is specific to Arduino.

01:57.800 --> 02:00.950
So we string you can simply store some text.

02:01.130 --> 02:03.530
OK, so hello, Arduino.

02:03.890 --> 02:11.890
So when we have used that print and we've text before, actually that was a string.

02:11.900 --> 02:20.390
So it's like we could just do string name of the viable is equal to that piece of string and then I

02:20.390 --> 02:29.000
can print here and if you look at the same monitor, OK, and here it's interesting, we have an accurate

02:29.000 --> 02:33.920
away because we have tried to declare two variables with the same name.

02:33.990 --> 02:37.880
OK, this is in the same scope we're going to see later what is good.

02:38.150 --> 02:40.790
And we have two variables with the same thing.

02:40.790 --> 02:42.520
And this will produce an error.

02:42.860 --> 02:47.130
So we need to change here the variable to be unique.

02:47.180 --> 02:51.960
OK, so whenever you try to use to valuably with the same name, you will get an error.

02:53.220 --> 03:00.480
And now let's check what we have in the sale of print online and you will see hello and know can we

03:00.480 --> 03:03.890
are going to also practice more with strings later on in the schools.

03:03.900 --> 03:12.780
So you have integer foreign numbers, double for float numbers, but with a Kunoth million or booleans

03:12.780 --> 03:16.650
or true or false values and string for text.

03:17.160 --> 03:22.340
Now, one last thing to know about all of those data type is the range of the data.

03:23.130 --> 03:27.330
There is a limit actually to what you can store in those numbers.

03:27.410 --> 03:32.950
OK, so far in the jungling to just come to that later, that would be interesting.

03:32.970 --> 03:36.960
But for basically, you don't really need to worry about that.

03:37.360 --> 03:40.320
The value you can store is almost infinite.

03:40.320 --> 03:45.450
So no trouble about this boolean where there is no problem with it because you can just store value

03:45.450 --> 03:46.720
that are true or false.

03:46.750 --> 03:48.720
So there is no question about that.

03:49.140 --> 03:50.640
And train will.

03:50.640 --> 03:52.980
You can just do anything you want.

03:53.220 --> 03:55.470
The problem here comes with integers.

03:55.770 --> 04:00.830
Not an integer in order is stored in two debates.

04:01.410 --> 04:10.260
OK, and what does it mean for you practically is that you can store any value from minus thirty two

04:10.260 --> 04:17.940
thousand seven hundred sixty eight two plus thirty two thousand seven hundred sixty seven, if you try

04:17.950 --> 04:20.290
to start with a value that is bigger than that.

04:20.770 --> 04:23.730
Well, this will what we call overflow.

04:24.130 --> 04:26.010
So let's say you want to store.

04:26.310 --> 04:27.290
Let's make an example.

04:27.300 --> 04:36.330
Actually, I'm going to talk thirty two thousand seven hundred sixty eight, which is just above the

04:36.330 --> 04:36.840
limit.

04:37.110 --> 04:38.940
And let's print a.

04:44.670 --> 04:51.300
And you can see it's not that at all, it's minus thirty two thousand seven hundred sixty eight, which

04:51.300 --> 04:52.800
is the other opposite.

04:53.400 --> 04:58.110
So whenever you go below that value, you will actually come back to the maximum.

04:58.350 --> 05:02.370
And whenever you go after that value, you will come back to the minimum.

05:02.670 --> 05:04.260
This is what we call other flu.

05:04.440 --> 05:09.690
And this is a pretty common area you will get in your programs if, for example, you don't understand

05:09.690 --> 05:12.910
why you get some weird values with your integer numbers.

05:13.110 --> 05:14.780
Well, that may be because of debt.

05:15.090 --> 05:19.420
So when you use integer, make sure you don't use integer for high values.

05:19.670 --> 05:25.020
So whenever you need to use something more than, let's say, 10 or 20 thousands and you are not sure

05:25.020 --> 05:29.610
that you know the maximum, well, integer is not the best data type.

05:29.850 --> 05:31.140
How can you fix that?

05:31.440 --> 05:40.320
Well, you can use the data type long and a long data type is actually stored on four bytes, which

05:40.320 --> 05:47.110
means that you can go from two billion something to minus two billion, two plus two million.

05:47.670 --> 05:50.970
So we've long you should not have really any program.

05:51.420 --> 05:54.690
And the way to use long is the same as integer.

05:54.690 --> 05:59.730
So you just put any value like that.

05:59.740 --> 06:02.610
So you declare and you initialize it.

06:03.760 --> 06:09.430
I know if I print out here, this is four hundred thousand.

06:10.910 --> 06:13.790
Now, we should have the correct value.

06:13.860 --> 06:20.120
Yes, the four big integer numbers used long for smaller one use integer.

06:20.630 --> 06:25.480
All right, so now you have a global overview of what variables and why we need them.

06:25.790 --> 06:33.170
And just one more thing is that phone I've used later like a big to name valuables, but in any of your

06:33.170 --> 06:37.130
program and in the following of these goals, we will use meaningful names.

06:37.340 --> 06:38.300
It's very important.

06:38.300 --> 06:43.130
You put meaningful names for your valuables so you understand what it's OK.

06:43.130 --> 06:46.150
When I use a I don't know what is a OK.

06:46.400 --> 06:52.170
If you want to store, let's say, a user age, then simply name your valuable user age.

06:52.850 --> 06:55.610
OK, you can use the common keys.

06:55.760 --> 07:00.440
So you start with a lowercase and then for every new word you use uppercase.

07:00.890 --> 07:02.060
OK, with no space.

07:02.420 --> 07:04.550
So you use this convention for reliable.

07:04.880 --> 07:07.310
And this one for constants.

07:07.310 --> 07:11.840
So you can know what is the difference between a valuable you can change and a constant.

07:12.140 --> 07:14.540
So for example, you want to store a temperature.

07:14.540 --> 07:17.660
Let's, let's double temperature.

07:18.560 --> 07:22.520
OK, if you want to start a username then just name it.

07:24.070 --> 07:32.860
User name, and if you want to check that, that's senseor or any component is alive, then, for example,

07:32.860 --> 07:42.190
Boulle is alive, OK, using those variables, those names for the violence will make much more sense

07:42.370 --> 07:48.020
in your program and it will help you and other people read your code in the future.

07:48.580 --> 07:54.940
So to recap here, when you declare a viable in C and C++ with Arduino, you need to give it a type

07:55.150 --> 08:00.640
and to decide which type you should think about, what kind of data you want to store.

08:00.790 --> 08:07.590
And also, for example, when using wrong numbers, what is the maximum value you expect for the valuable?
