Activa JavaScript para disfrutar de los vídeos de la Mediateca.
Arduino: serial II - Contenido educativo
Ajuste de pantallaEl ajuste de pantalla se aprecia al ver el vídeo en pantalla completa. Elige la presentación que más te guste:
Hello. In this exercise, we are going to continue studying how the computer can communicate,
00:00:00
can send and receive information from the Arduino board.
00:00:06
Here on the screen, you can see the circuit we are going to use.
00:00:09
We have four LEDs connected to the usual connectors, 13, 12, 11 and 10.
00:00:13
We are going to use digital outputs and every LED is connected to a 220 ohms protection resistor.
00:00:21
okay so nothing new for the moment let's go to the code we're going to have a look at the code here
00:00:27
this block layer de la serie read from the serial monitor is the the new one this is a
00:00:36
purple block it means that this from the input library and it means that the Arduino board is
00:00:43
reading from the serial connection it means it's reading from the wire that is connected to the
00:00:49
from the USB that is connected to the computer.
00:00:54
So we have a variable that is called serie, just because I want
00:00:58
this name. So we take the value, the number, from the USB, from the wire,
00:01:01
and we store it inside the variable.
00:01:07
And now I'm going to use this variable to control the Arduino board. Here, for
00:01:11
instance, just because I want, if this variable equals 1, 13 will be
00:01:17
high so it means the red led will shine so let's have a look let's start the simulation
00:01:22
i start nothing happens remember that the serial monitor is here if i click here and to send
00:01:30
variables we send number we have to type here in this box if i type one and i press enter
00:01:36
nothing happens. Yes, because there is a problem. This block, LeerSerie, is not
00:01:44
a good one if we want to read integer numbers. There is a problem with the
00:01:52
simulation, but it's not a huge problem, it's not a big problem, we can solve it
00:01:57
this way. We are going to change from Blocks to Text. Remember
00:02:00
when we... well, don't remember, it's the first time we do this. When we change
00:02:06
from blocks to code we will not be able to come back to the blocks okay so when
00:02:11
we change we have to be sure about the things we are doing okay so we click
00:02:18
here continue and we have here the code so here this is the variable I mean the
00:02:26
function we are using to read serie the variable equals this function so here
00:02:33
instead of using SerialRead, we are going to use a new function that is
00:02:38
called SerialParseInt. If you have any problem writing here, try a
00:02:43
second time or a third time, okay? It works, but sometimes you can't do it the
00:02:52
first time, I don't know why. So here we have the new code. I have only
00:02:58
changed this function we are using to read the number, and now I'm going to
00:03:02
start the simulation again. And now, if I press 1 here, the LED is
00:03:07
shining, okay? This is really really simple. So, your exercise. Your exercise is
00:03:16
a little bit more complicated than this one. You will repeat the code, you will go
00:03:22
back, you will remember that you can stop the video and go back, and you
00:03:30
You will read the variable the same way and you will add several blocks for switching
00:03:35
it on, switching it on, switching it on, switching it on.
00:03:43
You will have four numbers to switch each one of them on and you will use other four
00:03:46
numbers to switch them off.
00:03:51
And remember, the serial monitor here for you is here, okay?
00:03:53
So for example, you can use one, two, three and four to switch them, one, two, three and
00:03:58
four the four of them or maybe you can or and then you can use for instance five six seven and eight
00:04:03
to make them off the orders you are sending to the i mean through the usb okay i think it's not
00:04:07
really easy if you can you can program it instead of repeating the blocks you can copy and paste
00:04:16
this part okay this is the part we you can copy and paste to reproduce the different orders the
00:04:21
different possibilities 13 is the number of the connector instead of high you can use low and
00:04:28
one is here is the number of the code we use to send information so you can copy and paste this
00:04:34
part of the code if you want to okay you don't have to go back to the blocks program a new a
00:04:39
new circuit and then create a new a new code you don't have to you can copy and paste this part
00:04:43
however many times you want okay so the exercise is really simple but before i leave i want to
00:04:48
show you this exercise in the real life here i have copied and pasted my code and i go to i'm
00:04:55
going to upload it to the computer and check that everything is correct verificar okay compilado
00:05:04
fine everything works i upload it to the arduino board okay subiendo subido upload it and now i go
00:05:10
to the serial monitor here so i'm going to send my commands the first one is 13 why 13 just because
00:05:17
I want to and I want to type 13 the first LED is shining what happens if I type 12 why 12 just
00:05:25
because the green one is shining what happens if I type 11 the yellow one is shining again why 11
00:05:34
just because I want to what happens if I type 113 the red one is off 112 the green one is off
00:05:42
and 111 the yellow one is off so the real interesting thing here is that i can control
00:05:55
the arduino board from my keyboard okay for me this is the the amazing thing so and you can see
00:06:05
that it's true in real life it works okay so okay remember distractions you have to do something
00:06:11
like this programming orders orders to switch all the leds on and to switch all of them off
00:06:16
If you have understood the exercise with one LED switching it on, it's enough.
00:06:23
You don't need nothing more to understand and to do the exercise, okay?
00:06:28
So, good luck.
00:06:32
- Autor/es:
- David Gonzalez Arroyo
- Subido por:
- David G.
- Licencia:
- Reconocimiento - No comercial - Compartir igual
- Visualizaciones:
- 137
- Fecha:
- 10 de enero de 2021 - 18:35
- Visibilidad:
- Público
- Centro:
- IES MARIE CURIE Loeches
- Duración:
- 06′ 35″
- Relación de aspecto:
- 1.78:1
- Resolución:
- 1920x1080 píxeles
- Tamaño:
- 20.74 MBytes