Activa JavaScript para disfrutar de los vídeos de la Mediateca.
Arduino: random - 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 reuse a previous circuit.
00:00:00
We are going to use the one with the digital input.
00:00:09
So here, if we have all the circuits we already have, we can duplicate whatever we want.
00:00:11
For instance, we are going to use the digital input.
00:00:19
If we click on the wheel, we can duplicate it, we can copy it.
00:00:22
We click on duplicate, wait a little bit, and a copy of this circuit will appear.
00:00:26
In this exercise, we are going to use more or less the same connections.
00:00:34
We are going to use the input, the digital input, with the button, the pull-down resistor,
00:00:38
and we are going to use LEDs as output.
00:00:42
But here, instead of having just one of them, we are going to use four of them.
00:00:45
So, the first thing we need is a room.
00:00:50
So, I'm going to click and drag the button here, for instance.
00:00:52
I'm going to click and drag the wire, I'm going to click and drag the pull-down resistor,
00:00:55
remember the 10 kOhms one, there you see, 10 kOhms one, and I'm going to click and drag
00:01:01
the wire, the input wire.
00:01:09
And I'm going to use number 13, 12, 11 and 10 to control 4 different LEDs, so I'm going
00:01:12
to click and drag the input wire from the button to number 9.
00:01:19
And now I'm going to click and drag the four LEDs.
00:01:25
Well, I already have one, so just three of them.
00:01:28
One, two, three, and four.
00:01:32
And I will also need three more resistors.
00:01:34
All of them connected to the anode, the one that is not straight.
00:01:38
One, two, and three.
00:01:43
And remember that I have to change their values.
00:01:49
220 ohms 1, because this is the value we need to protect the LEDs.
00:01:52
220 ohms. Ohms is not the same as kilo ohms, so that way I have changed the kilo ohms to 220 ohms.
00:02:00
And now I'm going to connect the LEDs using the wires.
00:02:10
The first connection I want is the four black wires that are connected to ground.
00:02:14
black again, and black again. Here, black again. Okay. All of them... I made a mistake here.
00:02:20
Be careful when you... I want to erase the whole thing. Be careful when you draw wires
00:02:33
because sometimes you make mistake and you don't realize you have made a mistake.
00:02:38
Now, I have a single wire. So, these four wires are connected to ground because this
00:02:43
because this horizontal line can you see the horizontal line is connected to
00:02:48
ground through this wire okay and now I want I need the connection from 12 to
00:02:52
this one from 11 to this one and from 10 to this one so I have everything I need
00:02:59
related to the different components now I need to program the circuit so I'm
00:03:07
going to open the window related to code and I have the previous program. I want
00:03:13
to modify it a little bit because some of the possibilities are, some of the ideas
00:03:21
are the same. Again I am reading the input from number 9, so instead of
00:03:26
reading from 12 now I'm reading from 9, so I will modify. Leer pasado digital, ok.
00:03:32
I have a variable, I read from number 9 and I store it
00:03:39
in this variable and if this variable
00:03:43
if this input is high, something will happen here and if the
00:03:47
input is not high, something else will happen here. So
00:03:51
the first thing we need is, before we start moving on, is a
00:03:55
random number. If we go to the
00:03:59
green library, the one related to maths, there is a
00:04:03
block here related to random number that allows us to generate random number here i want a random
00:04:09
number from 10 to 13. why 10 to 13 because i'm going to use these four connectors so i'm going
00:04:15
to select and i want to use a number from random number from 10 to 13. realize that there is a bar
00:04:24
here if there's no enough room you can click and drag this bar and you will have enough room
00:04:30
so the same way and we move on the same way we have done with this variable we are going to
00:04:35
uh i know i'm sorry i i need an extra variable because i have a random number i was moving too
00:04:43
fast i was a random number but i need to store it somewhere so i'm going to create a new variable
00:04:50
this variable will i i can name it however i want but i'm going to use output because this random
00:04:56
number will be the output that will shine so I'm going to work the same way
00:05:04
I worked before I'm going to define I output using this random number okay so
00:05:09
output will have this random number from 10 to 30 okay so what happens if I press
00:05:17
the button one of the LEDs will shine which one it depends on the random
00:05:25
number, so I have to check the value of the input, not the input, the output, I'm sorry.
00:05:30
So I'm going to use the comparison block again, I'm going to use the equal, and I'm going
00:05:37
to check the value of output.
00:05:44
So for instance, if output equals 13, something will happen, but I need the if block to C,
00:05:47
if C.
00:05:55
Now I'm comparing. If this output, that is the random number, equals 13, what will happen?
00:05:57
What do you think? It will happen that output number 13 will be high and this block will
00:06:04
be here, inside the first if, because if the input, the one we are reading here, is high
00:06:13
and the output, the random number, is 13, number 13 will shine.
00:06:22
Something similar will happen with 12, 11, and 10.
00:06:28
So I will duplicate this code.
00:06:33
If I right-click here, I have the possibility of duplicate,
00:06:36
and I will click and drag here.
00:06:39
This second if is inside the first if.
00:06:42
Can you see the structure?
00:06:45
But now, instead of comparing with 13, I'm going to compare with 12,
00:06:46
And now, if output equals 12, number 12 will be hide.
00:06:51
The same for 11.
00:06:57
If output equals 11, 11 will be hide.
00:07:00
And I'm going to duplicate again, duplicate.
00:07:07
No, not here, I made a mistake.
00:07:13
This one has not to be here, it has to be here.
00:07:14
Can you see the difference?
00:07:17
Now, if output equals 10, number 10 is the one that's going to be high.
00:07:18
All of them are here.
00:07:26
It means if I press the button, one of these three possibilities will be true
00:07:28
and one of these connectors will be high and the LED connected to it will shine.
00:07:33
But what happens if the input is not high?
00:07:42
If I'm not pressing the button, really easy, as you can guess, we will have four LEDs that are low.
00:07:47
13, sorry, be careful when you click and drag the block.
00:07:57
12, 11, I'm duplicating all the time.
00:08:04
And 10, here's 10.
00:08:13
So, if I don't press the button, it means this condition is not true, we go to the C
00:08:15
no, the else condition, and the four of them are low.
00:08:21
And the random number has to be here, with these four blocks.
00:08:24
Everything has been programmed properly, everything has been connected properly, so I can start
00:08:33
the simulation.
00:08:42
If I click on the button, ok, everything is working, nothing happens because I'm not pressing
00:08:43
the button, but if I press the button, one of them is shining, ok?
00:08:49
If I not press, none of them shines.
00:08:54
If I press again, another one is shining, again and again and again and again, but realize
00:08:57
that I cannot guess which one is going to shine because it's a random process, ok?
00:09:05
So, okay, this is the circuit.
00:09:11
We are going to connect and to program today, okay?
00:09:13
Good luck.
00:09:20
- Autor/es:
- David Gonzalez Arroyo
- Subido por:
- David G.
- Licencia:
- Reconocimiento - No comercial - Compartir igual
- Visualizaciones:
- 216
- Fecha:
- 10 de enero de 2021 - 18:20
- Visibilidad:
- Público
- Centro:
- IES MARIE CURIE Loeches
- Duración:
- 09′ 21″
- Relación de aspecto:
- 1.78:1
- Resolución:
- 1920x1080 píxeles
- Tamaño:
- 28.88 MBytes