background top icon
background center wave icon
background filled rhombus icon
background two lines icon
background stroke rhombus icon

Download "Цикл уроков по программированию на C++ для Arduino. Часть 1."

input logo icon
Video tags
|

Video tags

Arduino
C++
Subtitles
|

Subtitles

subtitles menu arrow
  • ruRussian
Download
00:00:02
often asked by email to
00:00:04
help with some of their
00:00:06
unsolved problems,
00:00:07
but programming questions are
00:00:09
completely childish,
00:00:11
often I don’t have the time or desire to
00:00:13
dig into this nonsense, so I’m
00:00:17
not your Spider-Man in any way
00:00:19
friendly neighbor,
00:00:20
in general, all this infuriates me they have an
00:00:25
ambitious idea, most likely everything is unrealistic,
00:00:28
but let’s still try
00:00:30
to try to write down a few
00:00:32
lessons with the help of which people who
00:00:34
not only eat in their heads, but sometimes also
00:00:37
think, maybe they can start writing
00:00:40
simple sketches or at least read
00:00:43
someone else's code of average complexity and that
00:00:47
for this we will need any
00:00:51
arduino in my case it can be eaten
00:00:53
on 826 it will just compile the example
00:00:55
will be longer earlier between them I will
00:00:58
definitely indicate it but this is not important
00:01:04
since we do not yet need the arduino
00:01:06
haze environment they are the latest version, well, actually,
00:01:09
your desire and your open mind, and so
00:01:16
let’s get a little history, which
00:01:17
means the programming language for arduino
00:01:21
is Loring, it was created, more precisely, not a
00:01:26
subset of C plus plus, it is plus
00:01:28
plus with a certain add-on that is
00:01:31
a little forgiving of writing code for non-
00:01:35
specialists and complicates the code for
00:01:36
specialists accordingly, but that
00:01:41
is, plus plus,
00:01:42
most people write in it as in
00:01:46
regular C, but I kind of think that even
00:01:50
if you don’t use objects,
00:01:51
then using the extension that
00:01:54
appeared specifically siplus plus is quite
00:01:56
useful even for a regular session service
00:01:58
the C syntax was created a very long time ago,
00:02:04
it was created with the goal of being
00:02:09
able to write
00:02:10
fairly compact, fast-executing
00:02:13
code not on the server, why in general it was quite
00:02:15
consistent with the syntax of the language is very
00:02:18
finite, which is a big plus for those who
00:02:21
know how to write on it and a huge minus for
00:02:23
in order to start learning programming languages ​​with it,
00:02:27
but in the case of arduino we have no choice,
00:02:30
so its
00:02:34
semantics are very far from human language,
00:02:36
unlike the idiotic basic and or pascal,
00:02:38
for example, which is much better, of
00:02:42
course, to start with them, but it’s no big
00:02:44
deal, believe me everything is possible, so
00:02:50
let's try to start there
00:02:53
will be several lessons, which means everything will be new from
00:02:59
simple to complex,
00:03:00
I'll most likely forget a lot of
00:03:02
little things, but in any case, as a starting
00:03:04
point it will probably be good, well,
00:03:06
we'll see practice will show,
00:03:10
so let's get started
00:03:12
if you create a new arduino project,
00:03:15
you see the diet here fish you have here
00:03:18
two functions setup bow arduino for
00:03:24
any program in CB plus plus
00:03:28
contains several
00:03:30
one or more functions but in the case
00:03:33
of arduino these are 2 mandatory functions
00:03:34
setup and bow respectively the setup function
00:03:37
is called by the system itself without your
00:03:40
participation once function the forehead is called
00:03:42
constantly in a loop, respectively, the code
00:03:46
that you should get once
00:03:48
you place the functions the setup code that
00:03:51
you have is executed repeats
00:03:55
constantly you place the bow functions, so
00:04:00
accordingly you can create your
00:04:02
own functions to simplify the code
00:04:06
or increase in efficiency in order
00:04:11
to start working with the code yes, we
00:04:15
need some basic concepts,
00:04:18
so let's talk about types,
00:04:21
types are what
00:04:26
our program will actually work with,
00:04:31
that is, in human understanding, well, I do
00:04:36
n’t know, we have everything of type, but we think about
00:04:39
Victor Tirana in categories, let us still be
00:04:41
human Let’s not
00:04:43
build analogues before when you give an object, it
00:04:47
means with basic types,
00:04:50
for example, this is a type of enchantment, any single
00:04:57
character, for example, and with us it can be
00:05:01
represented as a
00:05:03
precursor to the enchantment type,
00:05:06
if we look at zero, then this is also a
00:05:10
zero symbol, not the value 0, but a
00:05:14
space symbol so we don’t see it, it’s also
00:05:16
a symbol,
00:05:17
and accordingly, there’s some kind of
00:05:19
special sign, it’s also a symbol,
00:05:22
type char, it takes us one byte and
00:05:25
quite actively naturally
00:05:27
large sketches are used, so the next type
00:05:33
we have is the logical type bool, which
00:05:39
we can have there are only two values, this is a
00:05:42
fall or a corpse, a fall is a lie, three, that is, it is
00:05:48
accordingly, and then logic is
00:05:52
all that we can compare with each other
00:05:54
when making a decision on this basis,
00:05:57
that is, for example, 0 is less than one, this is
00:06:01
true, yes, this is a logical expression
00:06:04
that, according to true, 0 is
00:06:06
greater units
00:06:07
is also a logical expression, but its
00:06:09
value is false, and so on, I am also
00:06:14
quite actively used, it takes up
00:06:18
one byte, but in fact it teaches it that
00:06:20
it has two values, then it would fit in one bit,
00:06:22
then go with integer
00:06:27
types, the base type int means in the case of a
00:06:33
fan, it takes two bytes
00:06:35
and can take values ​​from minus
00:06:40
32768
00:06:41
was 32767, that is, from -2 to the
00:06:47
fifteenth power to 215 ii power
00:06:50
minus one, if this is not enough for us, then
00:06:57
we add a long prefix to the int type
00:07:01
and we already get a value from -2 to the thirty-
00:07:09
first power to 230 first degree
00:07:14
minus one
00:07:18
if we have a lot - 32768 3867 then we add
00:07:25
the prefix count short here there is a
00:07:33
bad moment on the lake
00:07:36
it is equivalent to an ent so this will not
00:07:40
help us but we can
00:07:44
use the keep enchant not to store one
00:07:47
character to store a small
00:07:49
numeric value in this case we
00:07:52
get the opportunity to store from minus
00:07:54
128 to 127 numbers that is from minus 2 to the
00:08:00
seventh power to 2 to the seventh power
00:08:02
minus one so great and if we
00:08:10
only need positive values
00:08:14
then we add the prefix
00:08:20
on sand meaning by signed there is
00:08:25
also a prefix int
00:08:26
signed but when it it is omitted and so it is
00:08:30
added by default so
00:08:31
int in fact you have it with int int
00:08:34
from but the site accordingly indicates it
00:08:36
is not necessary ancient enchantment can already
00:08:40
store a value from zero since they are
00:08:42
only positive up to 200 55 and that is,
00:08:45
two to the eighth power is the place of ones, which
00:08:47
means case, by a signed integer
00:08:55
can store numbers from 0 to 65535, that
00:08:59
is, 22 16 minus one, and by a signed
00:09:05
long integer can once store a value
00:09:09
from 0 to 2 32 powers minus one, that
00:09:14
is, this is already a large value, so
00:09:19
great that everything is clear regarding integers
00:09:21
if we need roads for
00:09:24
fractions we have only one type fleet is not
00:09:30
very accurate and takes up four bytes
00:09:31
allows you to store a
00:09:33
value more than once and laughing and
00:09:36
some fractional values ​​but it’s very
00:09:39
slow and very cumbersome so it is
00:09:42
highly recommended to use
00:09:44
real arithmetic in your sketches
00:09:46
except cases when this is necessary, but life
00:09:48
is necessary, try to go with integer
00:09:50
arithmetic,
00:09:53
now let’s do it right away so that before you
00:09:57
forget the moment, it means the difference between r and
00:10:01
there is a t o r
00:10:04
even in Mecca we have memory, but here are mega
00:10:07
8 kilobytes of RAM, this is an 8-bit
00:10:11
microcontroller 86 is 32 bits per
00:10:14
microcontroller memory, there are 8 kilobytes each, so
00:10:18
the value of the length is more precisely the types int
00:10:25
lon and all sorts of other
00:10:28
derivatives, yes it differs on these
00:10:30
platforms,
00:10:32
that is, short int for example is equivalent to a
00:10:38
tape in over, but there is ps short and
00:10:41
just we have a two-byte
00:10:45
but and a 4-bit one, and if on faith
00:10:51
int and lonking differ by half, then
00:10:54
for n and int and races are the same,
00:11:00
but online, respectively, too,
00:11:05
this introduces some confusion
00:11:09
which, accordingly, can cost you dearly
00:11:12
in the end, which is what I recommend do not
00:11:19
use standard built-in types
00:11:21
in the compiler, use them, which means they are
00:11:26
synonyms and so the signed
00:11:33
integer place chart is so you can
00:11:37
get numbers from 128 to 127, use the int
00:11:44
8t type, how these are built and the names of these
00:11:47
types means int is clear integer
00:11:50
then comes poverty 8 bit handwriting you
00:11:53
just means that this is a type,
00:11:55
respectively, without signed letters, but
00:11:59
the symbol is from us, we will buy 8 t t u at the beginning
00:12:03
means on site by signed then comes
00:12:06
link then comes poverty 8 then you,
00:12:08
respectively, and double-byte is ours
00:12:11
and 16t
00:12:13
unsigned double-byte is uint 16t
00:12:19
long integer this is an int 32t and without anyone
00:12:30
long this is a uint 32 t
00:12:34
if you use these types
00:12:36
like this, then you will not have a difference
00:12:41
between r and n, that is, you will
00:12:46
know exactly what
00:12:48
maximum and minimum values
00:12:49
can fit into these variables or
00:12:52
accordingly, how long does it all
00:12:53
take, so I strongly recommend
00:12:56
switching to this kind of name for
00:12:59
types, well, accordingly, there are
00:13:01
no variations here, so it’s the same,
00:13:05
we talked about types, but why do we need types
00:13:09
to themselves, we need types in order, for
00:13:11
example, to define variables of the
00:13:15
required types, which such a change
00:13:17
is a named area of ​​memory that
00:13:21
is interpreted as
00:13:23
meaning, respectively, the value of a
00:13:25
specific type
00:13:26
and with it we can perform various
00:13:28
actions, that is, we can
00:13:30
write something to it, change it, read it, and
00:13:32
so on, that is, in code we can
00:13:34
use this exactly y per cell
00:13:38
since we need to set a variable of the
00:13:41
task variables simply, that is, we indicate the
00:13:43
type of the variable, well, that is, for
00:13:52
example, yes, although he himself said that this
00:13:55
should not be done, so let’s say
00:13:56
m 16 3 then indicate one or more
00:14:00
spaces or here emulators and
00:14:03
the name of the variable that we have means
00:14:07
the names of your objects must obey a
00:14:09
simple rule: they must begin with a
00:14:11
letter or an underscore,
00:14:13
contain letters, numbers and an
00:14:15
underscore, be unique and not
00:14:17
match keywords, that is, we
00:14:20
cannot name the variable inp
00:14:22
because it is a keyword but for example and 0
00:14:24
we call her husband can be called an
00:14:27
underscore, but you also don’t need to
00:14:30
do that, of course, but it’s better to
00:14:32
press it somehow, I don’t know, and for example, let
00:14:35
every language construction end with a
00:14:38
semicolon, that is, not every
00:14:41
line is for quality. and, but each
00:14:42
completed construction
00:14:44
and definition of a variable including its type
00:14:47
and name is a complete construction that
00:14:49
ends with us; if you need to
00:14:54
define several variables of the
00:14:56
same type, you can list them separated
00:14:58
by commas, but they must
00:15:00
again be unique, which must be answered by the
00:15:02
naming rule, which means that if you need
00:15:08
variables of a different type, additionally, then
00:15:11
you indicate
00:15:12
after the dot, but it’s better, of course, on a new
00:15:14
line, although you you are free to write the entire line,
00:15:17
but it will be a mess
00:15:18
to indicate a new type of variable, although no one
00:15:22
is stopping you, of course, and the same one is
00:15:23
just on different lines,
00:15:25
and accordingly here you have new
00:15:28
variables, which
00:15:32
means now we have learned how to go through the
00:15:37
types, we have gone over to learned how to create
00:15:41
very much, declare variables have become
00:15:45
completely a little bit to start writing,
00:15:47
imagine, so let’s
00:15:53
talk about constants in the code, you will encounter
00:15:57
values ​​that do not change during
00:15:59
execution, that is, these are numbers that are
00:16:03
specific, well, in particular in the
00:16:06
context of arduino, this is for example the pin number,
00:16:08
that is, you control the button to connect
00:16:11
how it Dallas's dad's same pin, that
00:16:13
is, you are in the code and you will use
00:16:14
the number of this leg, it is better to put such things
00:16:17
as constants at the beginning of the code,
00:16:20
so if you change something
00:16:22
in one place in the code you will need to
00:16:24
correct this constant,
00:16:25
recompile and you will have everything
00:16:26
to work if you
00:16:29
indicate this 7 leg everywhere in your code as a seven,
00:16:31
you will have to find all occurrences of this
00:16:34
seven in all your function calls and
00:16:37
change it everywhere to a new value, which is
00:16:40
of course inconvenient and since we have
00:16:43
constants to define there are two methods,
00:16:45
strong standard which is still
00:16:48
defined by many, but I don’t recommend it, but
00:16:50
again I’ll still say this
00:16:53
construction define means sharp define
00:16:56
then a space here you indicate some
00:16:59
name and then through one or
00:17:05
more spaces accumulators and so on
00:17:07
indicate the value after such a thing
00:17:11
everywhere where there will be a capital letter t, you
00:17:14
will have a replacement with one
00:17:16
define, these are not exactly constants, it
00:17:19
actually
00:17:22
changes all
00:17:24
the letters t before compiling the code, these are the occurrences in the code to
00:17:27
what is indicated here, this has
00:17:30
a lot of side effects, so it’s like
00:17:33
use constants like define, it’s
00:17:36
probably the best option,
00:17:37
take into account especially since we have C plus plus
00:17:39
they are pluses of
00:17:40
the mixture and we can use its
00:17:42
syntax extension,
00:17:46
so use constants and so to
00:17:49
define a constant as a
00:17:51
specific type, we must write the
00:17:53
keyword const then type data, well,
00:17:57
that is, also as a variable, then
00:17:58
it will be, for example, fifth 8 t,
00:18:03
then the name of the constant and then equal to its
00:18:09
value, so
00:18:11
if now we will have this pin in
00:18:14
capital letters, and that’s all if the prize plus
00:18:18
large small letters differ in the
00:18:20
names of the function variables and so on and so on
00:18:22
that you will be careful if
00:18:24
you see this pin somewhere in the code, then
00:18:26
in fact seven will be used there,
00:18:28
and accordingly, in order for us to
00:18:32
change something, we changed it in one place here
00:18:33
and don’t touch anything else,
00:18:35
recompile for a year, everything
00:18:36
works great for us, I recommend you should
00:18:39
still use constants, they
00:18:42
are defined, although dolphins have their advantages,
00:18:45
but this is not for the first lesson, so
00:18:52
around the perimeter of the variable we talked about
00:18:55
constants, let's now talk
00:18:56
a little about functions, although now we are
00:18:58
new functions, for now we should do something and
00:19:00
so the syntax of a function is the following type of
00:19:05
value returned by the function for
00:19:08
functions there is also added the type void
00:19:10
which means nothing, that is, the function at this
00:19:12
stage does not return anything, but if
00:19:16
you have a function to count, I don’t know,
00:19:19
give a square, for example, an
00:19:25
integer argument, it accepts and
00:19:27
returns the ends of
00:19:29
the argument, we say that it
00:19:30
returns int then goes the name of the function and
00:19:36
square but in the case of square in brackets
00:19:41
we list its parameters which
00:19:43
may not be in the setup created by Lupi
00:19:45
but of course we need a parameter
00:19:48
to return it exactly square the
00:19:52
parameters are also defined as
00:19:54
variables that is the type and then its name well
00:19:59
let's say let the oasis be and then they go
00:20:03
in curly brackets, we have the
00:20:06
function code, which means the function code can
00:20:13
be any, several lines can
00:20:14
occupy, accordingly, it is understandable that it
00:20:16
is important that if our function
00:20:20
returns something, then
00:20:21
the construction must be used, because it is
00:20:23
what we actually have not
00:20:27
only does it exit
00:20:29
the function, but it also returns a value, that
00:20:33
is, in our case, we can write like this, that
00:20:37
is, the argument, and we
00:20:42
will have you need it on itself and will be
00:20:46
returned to this as the value of
00:20:47
the function if we have it, then we we can
00:20:54
simply use a
00:20:55
writer and exit the function immediately as soon
00:20:59
as this code meets everything after
00:21:01
it it will never be executed,
00:21:08
or the function will exit upon
00:21:12
reaching the closing curly brace in
00:21:15
any case, but just be
00:21:18
careful if you have a return
00:21:19
value and you we got to the end electron is
00:21:21
nowhere to be found, it’s as if it won’t be returned to you by the
00:21:24
compiler, in principle, swear, so
00:21:29
the functions exist while no one understands them,
00:21:34
but let’s get to specific examples, you
00:21:35
stand with it now let’s go back to
00:21:40
variables again, why because in changes
00:21:43
there is such a thing as scope
00:21:46
means if you define variables
00:21:49
outside of any functions, that is, at the beginning
00:21:52
of the code, or even Sergey or at the end,
00:21:54
it doesn’t matter, then these variables
00:21:57
are called global, they occupy
00:22:01
RAM and will be visible in all
00:22:04
functions defined after this
00:22:07
variable,
00:22:08
if you define a variable inside
00:22:16
which -of a function, it is local,
00:22:19
it can be seen only in this function and upon
00:22:22
exiting it, and it is destroyed, that is,
00:22:25
it occupies memory only inside this
00:22:28
function, in fact, it occupies not even
00:22:30
RAM up to but the
00:22:32
stack, that is, special, as it were, a section of
00:22:35
memory in which It’s the changes that are stored locally,
00:22:37
so try to
00:22:41
unnecessarily avoid global changes
00:22:44
since in most cases they are not
00:22:46
needed, many code examples contain
00:22:50
global variables instead of constants, that
00:22:54
is, something like this and then in the code
00:22:59
it uses this variable as a
00:23:01
constant, which is pointless, that is,
00:23:03
if If we had something like this, it would
00:23:06
n’t take up anything in memory, but it would
00:23:08
do everything the same so that it would be clearer for you,
00:23:16
let’s move on to something
00:23:18
because you can look at the
00:23:23
scope, so that means
00:23:27
we can now use different
00:23:29
examples, we will use the output of everything
00:23:32
to the interface in order to understand how
00:23:35
our program works; for this, the code
00:23:37
will be the same everywhere in the
00:23:39
setup function; in the first line you insert the
00:23:42
serial construction.
00:23:44
begin and port speed, well, I’ll
00:23:48
use the optimal speed of 15200,
00:23:50
here’s the semicolon like this, after that we
00:23:54
can now
00:23:57
display the value of the variables in serial, there are some
00:24:00
constants or something else,
00:24:01
so we can already see something, so the
00:24:11
second option if we have the code does not require
00:24:18
repetitions of any kind, we can concentrate the whole code in
00:24:20
a stage for fools, it
00:24:22
will be completely empty, now we will
00:24:25
do that, that is, such a design
00:24:27
will also come across sometimes and don’t be
00:24:29
alarmed, there’s nothing wrong with that, no
00:24:31
let’s write a new function like this print
00:24:41
wars some kind without arguments that
00:24:45
returns nothing empty for now, so in
00:24:49
the setup we will call this function, to call the
00:24:52
function you need to directly write its name and in parentheses
00:24:57
indicate the parameters specifically or the
00:25:00
values ​​or names of the variables that
00:25:02
we pass to since we have a function
00:25:04
without parameters, then we just by decree, two
00:25:06
curly braces, now
00:25:09
we’ll write the code for the function itself, so we’re demonstrating
00:25:17
we’re demonstrating this kind of nonsense,
00:25:20
let’s assume an
00:25:23
8t factory variable, and so when creating a
00:25:34
variable, we can immediately indicate its
00:25:35
initial value by
00:25:40
indicating after its name an equal sign
00:25:42
and some- or a constant that
00:25:44
the compiler can calculate on so
00:25:46
compilation of that, let's say
00:25:48
we assign one and ours will be equal to one, which
00:25:52
means that the class series has a
00:25:55
print method and printers pineapple printers
00:25:58
print and goes to the next line directly
00:26:01
prints and remains on the same line it does
00:26:05
not accept one an argument of any type
00:26:06
is a string and characters and any number and
00:26:10
float and integers and so on,
00:26:14
now we will print
00:26:17
that is, if we do it like this, our code will
00:26:22
print one, which is logical
00:26:24
because it means the variable is globally
00:26:26
visible in all functions and the value of
00:26:28
one accordingly units we
00:26:30
get here is not interesting
00:26:34
local variables can have the same
00:26:37
name as a global variable
00:26:40
so they will cover them up their visibility that
00:26:43
is, turning but that is, here we
00:26:45
can write
00:26:46
and 8 you name is the same as hell but equal to
00:26:52
two yes now it’s already will come out
00:26:55
two further we have operator
00:27:04
brackets so called where there can be
00:27:08
one operator with the help of curly braces
00:27:11
open with the opening one we can
00:27:12
use as many as we want inside
00:27:14
the operators they will be interpreted
00:27:16
as one the side effect of this
00:27:19
is that here is the actual
00:27:24
scope and we can once again
00:27:27
use a local variable with the
00:27:28
same name, and the compiler will not
00:27:34
give us an error, that
00:27:43
is, if we now insert
00:27:49
print l.n here again. otherwise we
00:27:51
will get a triple there so beautiful how can we
00:27:56
get to the global variable
00:27:58
and even then if we have a change with the same
00:28:00
name
00:28:02
since we use
00:28:04
c plus plus then we have the opportunity to
00:28:09
use the two dots construction and
00:28:13
then the name of the variable is just that access
00:28:15
to the global level, here we have a
00:28:19
local context, another vocal
00:28:21
context, and here a global context,
00:28:24
let's see what happens if we
00:28:26
now leave one local
00:28:29
context, come back here, this is the
00:28:32
code, in fact, this is already interesting,
00:28:35
let's connect the arduino,
00:28:43
well, actually you don’t need the picture from
00:28:47
compiling, let’s open the serial monitor,
00:28:57
select the speed 100 15200 that is
00:28:59
indicated in the series, run not
00:29:01
and see our value, so first we
00:29:08
print a two since this is
00:29:11
local and it blocked our
00:29:17
global variable, so then we
00:29:22
enter operator brackets
00:29:24
another local variable with a name and a
00:29:26
value of three, that is, we see on
00:29:29
print and and
00:29:30
and then we print a global
00:29:34
variable, that is, we cannot go to
00:29:35
this level from here, that is,
00:29:37
not as the syntax will allow, here is one
00:29:40
and in the end we Let’s also print out the
00:29:43
global variable again, that is, the difference in the
00:29:46
local context here is generally
00:29:48
not, that is,
00:29:50
we can’t reach this variable from the inside of this block by
00:29:53
me side by side with
00:29:55
it, but as you can see from this it should
00:29:57
be clear that is, a global
00:29:59
variable We can see everywhere that the local one
00:30:02
can have the same name, but then to
00:30:04
access the global one you need to use
00:30:06
two dots at the beginning, and this is just
00:30:09
a way to unnoticed an error that you
00:30:13
will look for for a very long time when you named a
00:30:14
variable inside a function in the same way as
00:30:17
you have some kind of global one and then not
00:30:19
you will be able to understand why the value is
00:30:20
incorrect, so I strongly do not
00:30:22
recommend using exactly the
00:30:25
same ones for global and local variables,
00:30:28
but it is possible so
00:30:34
great, then let’s download what we
00:30:37
have already done to the
00:30:38
code and load another
00:30:40
example,
00:30:41
it shows the length of the types short
00:30:45
int int lonking and a long
00:30:48
pointer, well, that is, the adapters haven’t
00:30:50
arrived yet, but it doesn’t matter, we load this code, so
00:30:58
it means you see something short, an integer,
00:31:01
we still have two bytes, just like an
00:31:03
integer, a long integer, 4 bytes, a pointer,
00:31:06
two bytes, if we load the same code
00:31:08
into sp8 266 then here we get
00:31:12
two bytes an integer is already 4 a long integer is also
00:31:16
4 a pointer four bytes
00:31:18
so I say again if you want to
00:31:22
create code that is portable between
00:31:24
platforms then use type i from int
00:31:28
8t to this int 16 so on to
00:31:31
ensure that on each platform
00:31:32
this heat takes up exactly as many bytes
00:31:35
as you need and take the
00:31:37
values ​​you want with simplicity, which
00:31:41
means advice right away about writing
00:31:45
programs first avoid global
00:31:48
variables it wastes your RAM
00:31:52
especially if there is really no need for it
00:31:54
second use the minimum type of variables
00:31:58
that allows you to accommodate that
00:32:01
what you need
00:32:02
do not do indiscriminately int and drive there
00:32:05
16-bit
00:32:06
if you need to store there I don’t know from
00:32:09
one to ten the value it
00:32:10
fits perfectly in and 8 t or
00:32:13
uint8 you mean don’t use longin
00:32:17
if you also don’t need anything
00:32:19
long to store the fleet do not use
00:32:21
plum integer values, especially those
00:32:24
that fit into a long integer, and so on,
00:32:27
that is, always use a type that
00:32:29
minimally accommodates you, even the minimal
00:32:33
data type that accommodates what you
00:32:35
want to use,
00:32:37
make it a rule and don’t
00:32:40
relax because in this case you wo
00:32:42
n’t have to I’ll pick out the batik for you to
00:32:44
fit in the
00:32:46
RAM, so you’re probably tired, of course, but
00:32:50
now the most interesting thing will come,
00:32:52
in fact, we already have in the heap, which
00:32:55
means knowledge of the information, we’re off to
00:33:02
remove everything, so let’s start with the first
00:33:10
operator, this is the assignment operator,
00:33:15
which means if we define the variables,
00:33:25
well some kind of food then in order to
00:33:31
assign a value we must write
00:33:32
the name an
00:33:33
equal sign and then either a constant
00:33:37
or an expression, that is, we can 50 but we
00:33:39
can write 7 there without knowing on 8 + 1, but we
00:33:47
can write an expression using
00:33:50
other variables if they of course
00:33:52
already have a certain moment jenna 2 for example
00:33:55
and here we must immediately
00:34:03
move on to the brevity of the syntax of the axis,
00:34:07
which is actually why they love it and
00:34:10
hate it, the
00:34:11
expression of which this variable itself is involved
00:34:14
for example and is equal to and by 2
00:34:16
which is completely correct, that is, the
00:34:18
current value of the variable and is multiplied
00:34:20
by 2 and fits into this approximately and it
00:34:25
can be written in a short form for this
00:34:28
we write and there multiplies equal to 2 this
00:34:32
means the same thing, that is, if we
00:34:34
had plus 3 for example, yes, then we
00:34:38
could write more precisely and plus
00:34:40
equals 3 and so on, that is,
00:34:44
divide, multiply
00:34:50
anything, so the short form is
00:34:55
wonderful,
00:34:56
especially it is wonderful when we
00:35:00
increase or decrease the value by
00:35:02
one, we can become like this and plus
00:35:05
is equal to 1, or we can use the short
00:35:07
form and plus plus, it also happens
00:35:11
prefers and there is a post sex on this
00:35:13
after ks directed now it
00:35:14
can be used this form minus minus
00:35:17
I will reduce it by units when
00:35:21
it is used as a whole operator like
00:35:24
this the difference between the prefix n'ai pas there is
00:35:26
no close form but if we use
00:35:32
it like this then here there is already a difference between the
00:35:36
reason after that form, that is,
00:35:38
this means that the operator will assign
00:35:43
g the value of the variable and then the variable
00:35:48
and increase units, and if we write like
00:35:52
this, then first the variable will decrease
00:35:55
by units and then this value
00:35:57
will be copied into the variable g,
00:36:01
here is the difference there are these constructions you
00:36:05
will definitely often come across in other people’s code,
00:36:07
it’s like something sacred, that is,
00:36:09
every deer thinks it’s cool if
00:36:12
they use it and yes, these are actually
00:36:15
short forms, this is an important thing, it’s needed
00:36:17
and it’s like a sin and not to use something new,
00:36:20
some of them are evil consumes
00:36:24
means what expressions can be
00:36:28
more precisely what operations can be used with an expression
00:36:31
means they can use the operations
00:36:33
addition subtraction multiplication and division
00:36:37
division integer operation of the remainder of the
00:36:42
separation, that is, 5 here are the two remainders of
00:36:47
dividing 5 by 2 this is one if there I don’t
00:36:52
know there will be 32 two
00:36:58
accordingly we can use parentheses
00:37:01
arguments in brackets have a higher
00:37:04
priority when performing operations, that
00:37:08
is, 5 by 2 + 3 is our 13 to 5,
00:37:18
for example, by 2 + 3 in brackets we have
00:37:21
25, respectively,
00:37:28
well, that’s all in that spirit, so this is what
00:37:36
concerned us about the assignment, which is very important
00:37:39
things like that, well, let's now move on
00:37:45
to some kind of
00:37:48
decision-making operator, so the first
00:37:53
thing you've already seen is operator
00:37:55
brackets, curly brace, opening,
00:37:59
closing, are equivalent to any one
00:38:02
operator, that is,
00:38:03
any number of separated operators can be contained inside
00:38:05
; so interpret this
00:38:08
as one action,
00:38:10
we have already seen this to get a local
00:38:13
variable another level of localization,
00:38:14
but this is kind of stupid
00:38:17
enough to use more often this will be
00:38:19
used in the following constructions, the
00:38:23
conditional operator iv means it looks
00:38:28
like in brackets we have some conditional values ​​-
00:38:33
then
00:38:34
then we have one operator,
00:38:38
if you need several, then at height 100,
00:38:40
use curly braces, writes
00:38:42
several there before, if this condition is
00:38:45
true, then it is fulfilled, what is here, if
00:38:51
it is false, then such a short
00:38:53
construction
00:38:54
will not be executed and nothing and this
00:38:58
operator may have an expanded form
00:39:01
after the operator that must be
00:39:06
executed if the conditions are true, there may
00:39:07
be an els and another operator or
00:39:11
operator brackets and a bunch of operators they
00:39:13
will be executed if the condition is false,
00:39:17
respectively, if we have work to
00:39:20
do this, if possible, then this is,
00:39:24
as it were, a special case of this this is after ls
00:39:30
one more and one more condition and so on
00:39:34
and so on, whatever means there, so
00:39:39
here is the first point that you should
00:39:41
understand
00:39:42
and for the future it means since here
00:39:45
we have one operator after IFA, it’s
00:39:49
always better to put
00:39:51
operator brackets and inside, even if
00:39:54
you only have one operator, then
00:39:56
you definitely won’t forget them, so
00:39:59
use them if you need several
00:40:00
operators in the future, you may become
00:40:04
more experienced and you will see for yourself where
00:40:07
you only have one operator should
00:40:09
use it there, please
00:40:11
don’t do this, but you will It’s easier if you
00:40:13
always do this with how you
00:40:17
format the code is your personal
00:40:19
business, but most often it means that the
00:40:23
closing operator on the bracket
00:40:26
is on the same level as the
00:40:28
construction itself, that is, if we
00:40:29
write snapper accordingly, then too
00:40:34
how would it be like this
00:40:35
and here we can indicate
00:40:37
several different operators that are
00:40:39
inside these pens of whom God
00:40:41
is located, but no one forbids you to do it like
00:40:47
this,
00:40:49
do it like this, and so on,
00:40:52
the only one, as if I advise you to unify
00:40:54
some kind of approach, I
00:40:57
like this approach because it
00:41:01
saves trickles one extra at a time, we don’t
00:41:04
use it, but again I say it as if
00:41:07
it’s your personal business,
00:41:10
naturally, now there is a constant
00:41:12
true, there should be some kind of
00:41:13
expression, for example, and greater than 0, here is any
00:41:19
expression that here is located this
00:41:23
is trying to be interpreted as logic and
00:41:25
based on its value it is
00:41:27
executed either this code or this or and
00:41:30
there is no stealth and the condition is false this will
00:41:33
not be fulfilled what
00:41:37
comparison operations are possible for us to make
00:41:40
logical decisions the equality operation
00:41:43
looks like two equal signs do not
00:41:45
confuse with assignment, the most common
00:41:47
mistake is that you will use one
00:41:49
equal sign and the compiler will scold you,
00:41:51
don’t be the same for it, this is a correct
00:41:52
construction, that is, you write
00:41:53
if a is equal to zero, it assumes that there will be a
00:42:00
comparison with zero, but in fact you
00:42:01
assign the variable 0 and the value
00:42:06
will be 0 interpreted as a spoon, you
00:42:08
will have a transition here, but if
00:42:11
you had such a construction, then
00:42:13
you can’t change the value, and if
00:42:16
you have zero, then this
00:42:18
section will be executed, be careful, it means
00:42:21
equal, this is what it looks like for us, not equal, this is an
00:42:24
exclamation point equality,
00:42:26
respectively, is greater than less more
00:42:30
or equal less than or equal
00:42:33
if the condition requires several
00:42:37
variations that part of the conditions can be
00:42:41
connected with each other using
00:42:42
logical operations means a is equal to zero,
00:42:48
for example,
00:42:51
and this is logical and two ampersands the
00:42:56
following conditions there, well, let’s say it would be
00:42:59
equal to zero
00:43:01
this expression will be true only in
00:43:04
the case when the designation and will be equal to 0
00:43:07
equal to 0 and b equal to zero if you need a
00:43:11
condition or then it means indicated by
00:43:15
two fingers
00:43:17
means in this case either if a is
00:43:20
equal to zero or b is equal to zero
00:43:22
this cat will be executed like this There are also
00:43:27
conditions for negation, that is, you can
00:43:32
write and is not equal to zero, and in this case it
00:43:40
will only be called if they are equal to
00:43:42
zero, you can deny the obvious
00:43:46
using the not construction, which
00:43:51
looks like it!
00:43:53
you reverse the logical value of
00:43:58
this expression, that is, if it
00:43:59
becomes difficult to lie, if it is false, then it
00:44:01
becomes true, in this case,
00:44:04
you and the conditions
00:44:05
will work if a is not equal to zero, and
00:44:11
accordingly, a combination of
00:44:13
different ones can be both logical and and or not, and
00:44:17
so on do not confuse a single ampersand a
00:44:24
single pipe with a double single these are
00:44:28
bit operations they are also
00:44:30
not broken out by compilers which is not correct and but this is
00:44:32
not at all the same as what you want
00:44:33
logical operations double always before
00:44:38
battles operations we will not dwell on them now in the
00:44:43
next lessons therefore as if not with
00:44:44
your fingers and so on with the help and you
00:44:47
can already do a lot of things, in fact,
00:44:50
let’s not do
00:44:52
examples on individual things now, then I’ll generally get to the
00:44:55
materials and then we’ll
00:44:56
move on to consolidation, as if
00:44:58
I understand, it’s more complicated, but this way the tarn is
00:45:00
more effective of all, the
00:45:03
next construction is a while loop
00:45:09
we're the simplest, which means it looks like a
00:45:12
wile in parentheses, we have conditions, this is again
00:45:17
some kind of logical expression that
00:45:20
can take the values ​​true and false, and
00:45:22
then we have some one argument,
00:45:24
or operator brackets and a bunch means
00:45:27
operators, if you put a semicolon here,
00:45:35
this means that you do not have a single
00:45:36
operator and this condition will be executed in a cycle
00:45:40
until it becomes false here,
00:45:42
after that you will move on with a blow,
00:45:44
so the file is very often used
00:45:50
for,
00:45:53
but, as it were, making various cyclic
00:45:58
decisions, well for example, here we have a variable
00:46:03
and it is defined before if we make it,
00:46:08
we assign the value 0 there at the beginning and then
00:46:12
we make i less until we have there I don’t know
00:46:16
that we have anything here and then
00:46:21
plus plus then we will have 100 passes
00:46:27
first and we will be zero, then it will be
00:46:30
seen as two threes and until it
00:46:32
becomes hundreds after that we will leave
00:46:34
here until then we will have the
00:46:37
loop here executed sequentially
00:46:40
accordingly and in our our code means the
00:46:45
loops have two key
00:46:50
additional words, this is the word break
00:46:55
it causes an exit from the loop, well, by
00:46:59
itself it is rarely used, it is clear that
00:47:00
it should be called if in
00:47:03
some additional exit condition
00:47:05
is met, that is, for example, we can
00:47:08
do what if
00:47:09
and is
00:47:10
greater than or equal to 99, for example,
00:47:16
break now as soon as and 199 is equal to we
00:47:22
will exit cycle and the value 99, we wo
00:47:26
n’t be processed here at all
00:47:28
because this piece will not be fully
00:47:29
executed despite the fact that according to the
00:47:32
condition we are going to hit you, that is,
00:47:34
these are some specific additional
00:47:37
exits from the loop so as not to specify
00:47:38
exit conditions; the output is basically a condition
00:47:41
loop and there is also a cantina construction, so
00:47:51
let’s say if it’s less than ten, it
00:47:59
immediately calls a new check, as if a
00:48:03
condition for exiting the loop and further
00:48:05
execution, that is, if we call
00:48:07
continue to, this piece of code was also
00:48:10
used, it will be executed, it will not be
00:48:12
executed, we will go to The next
00:48:13
immediate
00:48:14
step of the cycle, this code
00:48:19
will begin to be executed and the value from 10, that
00:48:22
is, we will skip everything before that,
00:48:25
but also up to 99, respectively, these cantina break
00:48:31
constructs are not used so often,
00:48:33
but in fact they are
00:48:35
useful and important, just you know people doesn’t
00:48:37
know how to use them, here is the file, this is a
00:48:41
simple loop, it also has some
00:48:44
specific addition, this is the spirit of a
00:48:50
while-loop, similar
00:48:53
here, too, the conditions are what is the difference between them,
00:48:57
if this value of
00:49:01
the expression is initially false at the very beginning,
00:49:04
then not a single pass in the loop will
00:49:07
immediately get there for the following code, do will
00:49:11
first perform what is indicated here and
00:49:15
then will compare in this way
00:49:19
do-while one one pass always does this and
00:49:23
plus and minus plus this is if you have a code
00:49:26
that must be executed at least
00:49:27
once then you can use I think minus
00:49:31
accordingly if your code may
00:49:34
execute erroneously, which would be better,
00:49:37
of course, the construction where the comparison
00:49:39
takes place began to be clear that
00:49:43
break cantina also works in these too,
00:49:45
and now the most powerful ones are
00:49:50
like the for loop operator, which means it
00:49:55
consists of and now it has three arguments,
00:49:58
all of them are not required
00:50:02
means the first argument is a starting argument,
00:50:06
something that will be used once, the
00:50:08
second argument is the exit conditions, the
00:50:10
third argument is the conditions for changing
00:50:14
the operation, as it is easier for you to explain, but you
00:50:18
watch our cycle, the previous one is similar to
00:50:21
the previous one, we can format it as
00:50:23
equal to zero as the starting conditions separated by a
00:50:27
comma, all these three arguments
00:50:28
are then divided and less than a hundred are the
00:50:32
exit conditions and immediately plus plus we
00:50:36
can make an increment right here and
00:50:40
here we have some code accordingly,
00:50:42
this is a very powerful
00:50:47
construction because
00:50:48
you can write a
00:50:52
bunch of things as the starting condition and the exit condition is complex
00:50:54
maybe a cycle may not have a body at all,
00:50:58
since its entire body, if it is
00:51:01
just one operation, you can immediately
00:51:02
place it here as the third argument is
00:51:05
also supported by continue a break
00:51:07
everything is the same, there are such seemingly
00:51:13
flawed forms, for example, eternal loops, that
00:51:16
is, in its own case this is ours, well,
00:51:18
let’s say wilder,
00:51:21
this loop will be eternal in the case of SFO,
00:51:27
we have all three arguments missing,
00:51:31
this is also an eternal loop,
00:51:36
yes, we need to say something else about the
00:51:39
calculation of conditions when you use it
00:51:43
logically, but comparison, that is, the operators
00:51:46
there are more less equal there is not equal, it’s
00:51:49
clear, but if you use,
00:51:54
for example, such a construction, then it is
00:51:56
also legal; any operation,
00:52:01
more precisely, any expression that is specified
00:52:03
as a logical value, it will be
00:52:06
interpreted as follows 0
00:52:08
will be perceived as false, different from zero,
00:52:11
values ​​as true, that is, a file from -1
00:52:15
is also an eternal cycle, just like in the forehead 1, just like
00:52:18
in one plus four, just like
00:52:21
anything new mode 0 will never be executed, I
00:52:24
often use my construction
00:52:27
in general, when comparison operators
00:52:30
use a direct value
00:52:32
without the comparison itself, then this means
00:52:35
that the comparison is with zero, it’s just
00:52:38
this kind of hidden, it
00:52:40
will become clearer to you when we get
00:52:42
to the examples, for now, relax and in fact,
00:52:48
well, in general, the last construction
00:52:50
that we will talk about means the
00:52:57
switch construction if you have many
00:53:01
many comparisons, for example if
00:53:06
and equals zero then there is something else
00:53:11
if it means and is equal to one then something
00:53:19
else if and equals two well and so on,
00:53:25
there is such a design that can be
00:53:28
replaced with a more efficient one, I’m not sure about the
00:53:32
compilation, but at least according to the
00:53:34
source code for sure switch construction
00:53:36
it looks like a switch in brackets we have a
00:53:40
certain expression here and then in curly
00:53:46
braces we have a specific value of
00:53:51
the expression and what will be executed as a
00:53:53
result the
00:53:55
keyword case is used in our
00:53:59
case here is case 0
00:54:00
then: and then here comes some code
00:54:06
then means case 1 of 2
00:54:14
and at the very end,
00:54:19
if we have a person with such a thing,
00:54:23
then here we have a default construction and
00:54:29
here is also some code here, candles,
00:54:33
everything is so simple for me, but that is, here we have a
00:54:35
candle case and
00:54:36
that is, this constant will be
00:54:39
compared with the value of the expression in
00:54:42
which the candle is specified
00:54:43
and if there is a match,
00:54:46
this code will be applied, which means at what point you must
00:54:52
at the end before the next comparison
00:54:55
be sure to apply the break construction
00:54:57
because this code will be executed
00:55:00
oak here is the first comparison
00:55:03
you will have before and after this if you missed it
00:55:05
break the will be executed until the very
00:55:07
end, all the operator which is found even in other
00:55:10
cases, that is, the case is
00:55:12
a comparison but not the conditions for exiting the
00:55:15
comparison, which is why the design is
00:55:18
quite cumbersome it looks like this,
00:55:19
usually don’t forget in
00:55:23
any case the breaks before the
00:55:24
next cases means if you you need to
00:55:26
compare with several values, then
00:55:30
such a design is allowed case 01
00:55:32
there and then that is, several labels, one
00:55:35
code if it matches any of them,
00:55:37
accordingly, it will execute
00:55:39
after the default break is not necessary
00:55:42
since we will fix it anyway in any case
00:55:43
this operator
00:55:47
has code in which the breaks are missed
00:55:50
intentionally these are complex, quite
00:55:54
variations, even I used it, I
00:55:56
sags, I comment on the moment that this is
00:55:58
not like a break is skipped, that’s why we have a
00:56:01
switch design, it’s dark enough for
00:56:02
beginners, that is, you will
00:56:04
skip one hundred percent there, be
00:56:06
surprised why you are some kind of nonsense, but
00:56:09
it’s enough powerful, that is, if you
00:56:10
need to compare the same
00:56:13
expression with a bunch of constants and execute different code
00:56:17
at the same time, then of course you have it
00:56:18
a little more compact, in fact, all the
00:56:23
main operators, oddly enough, we have already
00:56:25
gone through that is, and the rest is, as it
00:56:27
were, not necessary Now we can
00:56:30
theoretically start writing sketches, but
00:56:33
in practice, let's
00:56:35
start writing, we need to
00:56:42
talk about what is used in the
00:56:46
Arduino, I am very active, too, now we will
00:56:51
consider the absolute minimum, then
00:56:55
over time, maybe someday we will
00:56:56
add something else and so on since
00:57:01
arduino works with pins, first of all
00:57:04
we must determine the mode in
00:57:07
which the pin works, which means the pin can
00:57:10
work in the
00:57:11
pull-up input and output mode,
00:57:15
respectively, in order to determine more
00:57:18
precisely to indicate to the system in which mode
00:57:22
our house operates, we must use the
00:57:25
pinmode function.
00:57:27
it has two arguments in parentheses,
00:57:29
the first is the pin number, the second argument is a
00:57:33
constant input input handwriting pull up or
00:57:38
output
00:57:40
this is the mode accordingly for them this is the input for
00:57:42
them underground bypass by pull-up and for this the
00:57:45
output by default is all pins as inputs
00:57:48
designed but I strongly recommend in the
00:57:51
once stage all the pins that you
00:57:56
use to log in are still
00:57:57
forced to be written in input so that you do
00:58:00
n’t get confused later, and the second point
00:58:02
that I talked about at the very beginning, don’t
00:58:05
use hardcore constants yet, that is,
00:58:08
define a constant with the name pin and
00:58:11
use it everywhere, well, something in this
00:58:24
spirit, so
00:58:25
now I’ll just write it as a
00:58:30
global one, of course it doesn’t
00:58:31
compile, it’s just to show you, it
00:58:33
means so pin, now we have a curve in
00:58:37
what mode we’ll allow, but either it’s a
00:58:39
bad story, let’s mean we have a
00:58:42
uart interface and we use it so let's
00:58:45
start with the second, after all, we won't
00:58:48
use 01 so that we can
00:58:53
control it, it
00:58:54
finds a digital output, we use the
00:58:59
digital
00:59:01
right function, it also has two arguments, this is
00:59:06
the number of pins or constants, of course it's better and the value of x
00:59:10
and this is a high level
00:59:12
logically flow this is low actually
00:59:16
you you can use one as
00:59:18
high 0 as low you can
00:59:20
use a variable mace of some kind
00:59:23
accordingly
00:59:24
false will be a low level and truth will be a
00:59:28
high level you can
00:59:31
use some expression here
00:59:35
oh Thorin before drying the palette
00:59:39
night mode came so it holds
00:59:44
write shield if you want to read
00:59:47
digital pen which is in the
00:59:49
reading mode, then you use it, it
00:59:53
creates one argument, a screw, and this is a
00:59:55
function that returns something, that is,
00:59:59
you must use its return value
01:00:02
or assign it to some variable or
01:00:05
in some kind of comparison
01:00:10
or something - something like this, if you have
01:00:16
analog pins,
01:00:18
then accordingly we have an analogue of rate,
01:00:24
here values ​​​​from 0 to 255; an analogue of read,
01:00:32
we return by pin number a value
01:00:46
from 0 to 1023, we have 10-bit disconnects,
01:00:52
and the last design, which
01:00:55
will also often be used, is this the delay
01:00:58
function looks like business and has one
01:01:00
parameter, which
01:01:01
means here the number of milliseconds, that
01:01:04
is, 1 second t1000 that you need for
01:01:09
which you need to delay the execution here, a
01:01:12
32-bit value that means 4
01:01:14
billion
01:01:15
or more, respectively, you
01:01:17
can delay a large enough delay using business
01:01:19
and do it, and actually everything is now
01:01:22
possible to do some kind of code, that is, we
01:01:25
have sufficient knowledge, and so
01:01:30
let's change the built-in LED,
01:01:33
do everything wisely, and so the constant
01:01:36
is determined by the slide LED is built, this is
01:01:41
our thirteenth pin, which means from the stage if
01:01:50
this horror we remove pinmode here we have
01:01:56
years he puts us out of the way, everything is like that, we
01:01:59
no longer do everything else, it goes into our bow
01:02:05
and so we do digital do
01:02:13
right
01:02:15
constant years, let's allow a high level,
01:02:18
then we wait one second
01:02:26
or display a low level, that is, we turn off
01:02:31
the LED, wait another second,
01:02:33
we will have this
01:02:34
let's repeat this code, we'll load it into arduino,
01:02:40
now we'll see that our built-in LED
01:02:42
will start blinking, well, after 1
01:02:46
second,
01:02:47
it's great that this is a deer's cat, but more precisely, a deer
01:02:51
with experience because we still
01:02:53
brought out a constant, that's
01:02:55
why, well, because let's
01:03:02
reduce it to two lines, despite the fact
01:03:07
that we defined the leg of the years as out put
01:03:10
hold creates, we can still
01:03:12
use it for this leg, it will
01:03:14
read us the current value of this pin,
01:03:19
that is, if we use
01:03:27
reading the current value here and using the
01:03:30
logical negation operation, forgive it, we will
01:03:35
reverse it then this code will
01:03:40
work the same as
01:03:46
yours, of course, forgive me, but years before,
01:03:59
as you can see, we have a blinking again for one
01:04:02
second, and such things can be
01:04:06
a whole lot of such improvements,
01:04:09
simplifications, let's assume we have a
01:04:12
button, too, let's do everything according to our minds, that
01:04:18
means the pin is where it is we will be sitting, but
01:04:23
some let it be 2, we will define
01:04:30
the mode of this gp as input pull up,
01:04:38
let
01:04:39
us pull it to the ground as a
01:04:46
deer would write, let’s say it means to show
01:04:49
which button is pressed, the LED lights up as it
01:04:51
is released, it will be erased, it doesn’t light up, so
01:04:59
there is no deer in Catalina give it very straight so it
01:05:01
will be here in means there is some kind of b to
01:05:06
torture me yes it means so btn equals
01:05:15
runs
01:05:16
soars constants thank God yes so if b
01:05:23
t m
01:05:24
equals club the digital right
01:05:33
oh let's do it
01:05:42
so if we have a button on
01:05:45
the ground it means we is pressed and we
01:05:48
turn on my light bulb, if not,
01:05:51
we turn it off and, accordingly, to the delay I
01:05:54
need, that is, a cycle while we hold
01:05:55
the button, the whole thing works, the code is
01:05:58
functional, absolutely cons, what for
01:06:01
desant if bull and that’s enough, the person on duty
01:06:06
returns zero or one, and secondly,
01:06:11
why is there a variable if at all? it
01:06:15
would be enough, and thirdly, if we
01:06:24
compare with zero, we can
01:06:32
do it like this, and fourthly, why do we need a
01:06:38
comparison at all and two lines means that if
01:06:44
we have zero, then we should do a high yes, that
01:06:48
is, well, that is, that’s not
01:06:56
enough
01:07:01
[music]
01:07:06
so here we have button 2 and the ground
01:07:18
is thunder, so
01:07:20
I press adonis, it goes, I release
01:07:26
the LED goes out, as you can see, everything
01:07:31
works great, and
01:07:34
in general, this kind of optimization can be done
01:07:36
a lot, so let’s probably for the first
01:07:41
time all this is enough, that is, you
01:07:43
already you can play with all sorts of nonsense there
01:07:48
but don’t ask Morse code what topic I’ll
01:07:50
demonstrate so that you have something to
01:07:53
fight with next so
01:07:55
the button we assume we don’t need their bodies
01:08:00
is considered to be creating a new function let’s say
01:08:08
with here we won’t flash the LED three
01:08:15
dots 3-3 dots to respectively there
01:08:21
digitalwrite red high turn on the LED,
01:08:28
wait, let's say. we will have 100
01:08:33
milliseconds,
01:08:37
extinguishing the difference between
01:08:46
means there will be, for example, 500 milliseconds, so it’s
01:08:48
unnecessary to do this right away, then
01:08:50
it’s better to immediately put all these constants out as
01:08:52
constants, well, let me go through several stages of
01:08:57
optimization,
01:08:58
so we have one. yes, again, to
01:09:01
quench three dots then dash, we have
01:09:11
500 each, there will be three terme
01:09:18
and three more dots
01:09:31
so I made a mistake somewhere, so between the
01:09:34
raita
01:09:35
500 tak hai and like this and here we have a sosa
01:09:45
now
01:09:53
let's eat the button will be pressed then we
01:09:59
call this our function sos we load
01:10:13
we press
01:10:22
that that point I was at the end of
01:10:30
1 and I copied one more freedom a little
01:10:37
now like this but it doesn’t matter to write down from
01:10:40
horror it’s great yes but this is a deer cat we write
01:10:49
another function
01:10:50
well I don’t know there blink for example yes it
01:10:59
will have two arguments, but we blink
01:11:02
the LED, which means the argument with the
01:11:04
leg number can be omitted, then
01:11:08
it turns out that we pass it the
01:11:10
argument time of pressing, look out for the
01:11:13
glow time and pause time,
01:11:17
so
01:11:18
since we are using white, it has
01:11:21
32-bit arguments, let’s
01:11:24
see 32t and we will to use as a type of
01:11:28
variable means this is our time,
01:11:32
pulse is the burning time, and this is our
01:11:38
pause time, here are two arguments for the pulse,
01:11:44
pause and code,
01:11:52
but not normal, means
01:11:56
we light up, do this, wait for the time indicated
01:12:00
in the pulse parameter up to 700 diode, wait for the time
01:12:03
indicated in the pause parameter
01:12:05
our suction is degenerating then yes so
01:12:16
blink means one hundred and five hundred and
01:12:23
three times then this 500 will still
01:12:31
melt
01:12:34
load
01:12:43
we press in front of the short 3 long three
01:12:48
short great my second
01:12:53
generation Italy why don’t you see we have
01:12:57
three identical calls and that means
01:13:02
what do we need a cycle and so we can
01:13:09
define a variable at the very beginning,
01:13:12
8-bit by signed is enough for the eyes,
01:13:16
but you can, but with a variable, in
01:13:20
fact, at any moment, including in the body of
01:13:24
the loop,
01:13:26
it will be local, no big deal, when we
01:13:28
exit the loop, we will lose, so
01:13:32
we have three passes, that is, if it is
01:13:35
initially zero, then less than three and at
01:13:40
the end it turns, then we can
01:13:44
perform one blink like this, well,
01:13:55
all the other blinks we also change
01:14:00
since this variable no longer
01:14:02
exists, then
01:14:04
we can make the same one again with the following forms option, another
01:14:07
option, we’ll still help you do it like this,
01:14:12
define the changes at once at the very
01:14:14
beginning, and here I have to refer to
01:14:16
the difference, in general, there is no memory,
01:14:19
it will occupy the same amount at the junction, that
01:14:23
is, nothing else will happen,
01:14:31
so let’s go,
01:14:33
press three dots 3-3 dots
01:14:40
are great, well, as you can see,
01:14:43
we had all this about optimized, so
01:14:46
try in general to go to such code,
01:14:49
of course, as I said again, it’s even better, after
01:14:52
all, our constants are so
01:15:03
then we do dot this is 100
01:15:10
milliseconds for us, so dash this only in my opinion,
01:15:22
we have a pause of 500, so let’s just
01:15:28
do everything beautifully
01:15:51
and in general there is no difference, of course,
01:15:53
but this is more or less the absolutely
01:15:55
necessary code, we click and we see everything the
01:15:58
same, if you
01:16:02
stick to something... then this and that,
01:16:04
in fact, you have a chance to become
01:16:06
one day, well, in general, writing your
01:16:11
sketches is quite serious and
01:16:13
accompanied, that is, if you need
01:16:16
time, for example, reduce the pause to then
01:16:18
we are in one place, now here we
01:16:20
will change the constants and do that and nothing else it is
01:16:23
not necessary, that is, due to the fact that
01:16:24
our code is not located several times, but that is, we did
01:16:27
not multiply it on the 1st floor,
01:16:29
use constants there, everything
01:16:31
will change, we will switch ourselves, the harmony
01:16:33
goes to another please, years, we changed
01:16:35
everything in one place, too, and if we take
01:16:39
an example and are ready, for example, keep creating as a
01:16:43
goal, then we’ll see how our beauties
01:16:48
work,
01:16:49
they use a push loaf as a constant,
01:16:52
but define it not as a constant, but as a
01:16:54
variable, and even of type int, that is, they are
01:16:56
two bytes of memory,
01:16:57
just like that, you king, there’s nothing
01:17:01
wrong there, but nothing there is also no good thing there,
01:17:03
plus for some reason they save the value of the
01:17:08
pressed button despite the fact that it was used in
01:17:10
one place, respectively, you can
01:17:12
rewrite all of this at once plus they
01:17:15
also use int here, although it
01:17:17
would be enough, as you can see
01:17:23
there, for example, built-in ones, that is,
01:17:25
which they have existed for many, many years, they
01:17:27
also generally smell of this shedding, they
01:17:29
smell, God forbid, it’s
01:17:31
very easy to see, look,
01:17:34
we’re not compiling this code and
01:17:37
I’m not going to push it, and we’re writing, we see that the global
01:17:40
change uses one hundred and eighty-
01:17:41
eight bytes of dynamic memory from
01:17:44
a little because we have two kilobyte,
01:17:45
but let's even change the primacy of just
01:17:49
one such thing, add the definition of push
01:17:53
bottom as a constant and we should have 108
01:17:56
6 bytes become a consumption of RAM in
01:17:59
general, a small thing dad 188 nifiga
01:18:04
report a complete compiler that
01:18:11
but beautifully the compiler turns out to
01:18:15
make a decision itself but that's all equally bad
01:18:16
history funny well it should have been
01:18:24
different
01:18:25
okay anyway don’t do it like that anyway
01:18:28
use a constant
01:18:29
because in reality it’s actually a
01:18:32
global variable that takes up
01:18:35
memory and it’s unclear why it didn’t affect
01:18:37
anything honestly I’ll say more than strange well
01:18:42
okay that’s not the point but that’s it for today,
01:18:45
I understand that it was difficult, probably
01:18:47
your head there got sick, swollen,
01:18:49
most of the people didn’t watch it
01:18:51
to the end, boring and sad, incomprehensible, a
01:18:55
million questions, let’s bombard the author
01:18:58
so that he curses everything in the world for taking on
01:19:00
such a mediocre event,
01:19:06
but those who survived to the end and who is interested in this,
01:19:10
in the next lesson we will probably
01:19:12
look at arrays, respectively, the
01:19:15
string pointer, working with strings,
01:19:19
and then someday we will deal with
01:19:22
objects and then you
01:19:24
can do a lot of things, just like mothers,
01:19:26
but that’s all, thanks to everyone for
01:19:29
your creative attention success to everyone, try your
01:19:33
best to understand, or
01:19:37
understand that this is not yours, and then
01:19:38
just don’t do this anymore,
01:19:41
if you still managed to help someone, I’m glad,
01:19:44
goodbye, see you again

Description:

Вероятно безнадежная попытка в нескольких уроках научить писать скетчи для Arduino. Первая часть охватывает скалярные типы данных и основные конструкции языка. Во второй части будут рассмотрены массивы, строки и производные типы (https://www.youtube.com/watch?v=5q5Cago_UfM). Третья часть будет посвящена ООП (https://www.youtube.com/watch?v=ZbV_C4ejUQ0). PS: кто найдет логическую ошибку в примере, рассказывающем о while, может собой гордиться. :)

Preparing download options

popular icon
Popular
hd icon
HD video
audio icon
Only sound
total icon
All
* — If the video is playing in a new tab, go to it, then right-click on the video and select "Save video as..."
** — Link intended for online playback in specialized players

Questions about downloading video

mobile menu iconHow can I download "Цикл уроков по программированию на C++ для Arduino. Часть 1." video?mobile menu icon

  • http://unidownloader.com/ website is the best way to download a video or a separate audio track if you want to do without installing programs and extensions.

  • The UDL Helper extension is a convenient button that is seamlessly integrated into YouTube, Instagram and OK.ru sites for fast content download.

  • UDL Client program (for Windows) is the most powerful solution that supports more than 900 websites, social networks and video hosting sites, as well as any video quality that is available in the source.

  • UDL Lite is a really convenient way to access a website from your mobile device. With its help, you can easily download videos directly to your smartphone.

mobile menu iconWhich format of "Цикл уроков по программированию на C++ для Arduino. Часть 1." video should I choose?mobile menu icon

  • The best quality formats are FullHD (1080p), 2K (1440p), 4K (2160p) and 8K (4320p). The higher the resolution of your screen, the higher the video quality should be. However, there are other factors to consider: download speed, amount of free space, and device performance during playback.

mobile menu iconWhy does my computer freeze when loading a "Цикл уроков по программированию на C++ для Arduino. Часть 1." video?mobile menu icon

  • The browser/computer should not freeze completely! If this happens, please report it with a link to the video. Sometimes videos cannot be downloaded directly in a suitable format, so we have added the ability to convert the file to the desired format. In some cases, this process may actively use computer resources.

mobile menu iconHow can I download "Цикл уроков по программированию на C++ для Arduino. Часть 1." video to my phone?mobile menu icon

  • You can download a video to your smartphone using the website or the PWA application UDL Lite. It is also possible to send a download link via QR code using the UDL Helper extension.

mobile menu iconHow can I download an audio track (music) to MP3 "Цикл уроков по программированию на C++ для Arduino. Часть 1."?mobile menu icon

  • The most convenient way is to use the UDL Client program, which supports converting video to MP3 format. In some cases, MP3 can also be downloaded through the UDL Helper extension.

mobile menu iconHow can I save a frame from a video "Цикл уроков по программированию на C++ для Arduino. Часть 1."?mobile menu icon

  • This feature is available in the UDL Helper extension. Make sure that "Show the video snapshot button" is checked in the settings. A camera icon should appear in the lower right corner of the player to the left of the "Settings" icon. When you click on it, the current frame from the video will be saved to your computer in JPEG format.

mobile menu iconWhat's the price of all this stuff?mobile menu icon

  • It costs nothing. Our services are absolutely free for all users. There are no PRO subscriptions, no restrictions on the number or maximum length of downloaded videos.