Bài 3: Lập trình robot giáo dục KC-Bot điều khiển đen led và còi báo

Kidscode STEM
12 người theo dõi
81 Lượt xem video·20 thg 11, 2023
---------- ★ ----------
* Website: http://kidscode.edu.vn/
* Email: [email protected]
* Hotline: 0888 424 222.
---------- ★ ----------
In the 3rd lesson, we will learn about 3 main parts.
First, we will learn about the technique on its structure.
Next, we will learn about the two objects of the lesson, LED and Coil Buzzer.
In each object, we will learn about the structure as well as how to program and control these devices.
Finally, we will learn about the exercises to combine LED and Coil Buzzer.
First, you will see a potest on the robot's body.
With this potest, we can create different types of electrodes.
It is called mini potest because it is one of the smallest potest.
This is the potest we will use on our robot.
It has many different colors.
If we remove this potest, we will see the structure inside.
In contrast to these two images, we can see that the potest is made of steel plates.
If we observe closely, we can see that the holes in the potest are connected to each other.
1, 2, 3, 4, 5.
These 5 holes are connected to each other.
They are separated by a gap like this.
This gap is on the potest.
These 5 holes are connected to each other.
The two next to each other will not be connected to each other.
This is the structure of the potest.
If you look at the potest, you will see that these 5 holes are connected to each other.
These 2 holes will not be connected to each other.
The gap between these 2 holes is the same as the gap between the legs of a standard IC.
This helps us to prevent ICs from overlapping.
Next, we will look at the LED.
It is the abbreviation of LED.
Light Emitting Diode.
If we look at this image, we can see that the LED is designed with 2 legs.
There are 2 legs, which are transverse and transverse.
The transverse leg is usually longer than the transverse leg.
But there is a question.
If we cut off these 2 legs and they are the same, how do we distinguish them?
There is another way.
If we look inside the LED, we will see that there are 2 transverse boards.
The transverse board is larger than the transverse board.
This is the abbreviation of LED.
In addition, the LED has a plastic cover on the outside.
These covers are painted in different colors or placed inside.
So which element depends on the light?
Usually, there will be yellow, red, green, pink, blue or purple covers.
These covers are colored so that we will understand the light inside the LED.
The light emitted by the LED does not depend on the color of the leather, it depends on the wavelength of the light that the LED can emit.
Now we will perform the first exercise, which is LED control.
In fact, we have already done this exercise in the first exercise.
Some of you have done the 8-LED control, right?
However, for this exercise, I suggest a signal light for the control mode.
We will install 2 LEDs like this, on the left and right, so that we can control the control mode in the signal mode.
When turning left, the left LED will light up, and when turning right, the right LED will light up.
Now, to do this exercise, we can go back to the KISScode software.
This exercise is simple, but I will do it again on this software.
First of all, you need to draw a simulation.
This is the simulation that we had the other day.
Here you can see that the 3, 8, 6, and 7 legs are used to control the previous engine.
We can use the remaining legs to control the LED.
For example, you can see the 9, 10, 11, 13, 4, 5, 0, 1 legs.
Now we will use the 9 and 10 legs to control the LED.
To get the component, remember to press the P key.
And we also call it LED.
There are many different types of LEDs in here.
But we pay attention to which LED is called Animated, so it can be animated.
I still like to choose the color green, blue, or yellow to make it easier to see.
The other day, we learned how to control the engine.
To make it easier to imagine, I will connect these two LEDs to these two engines.
The first LED is connected to the engine above.
The second LED is connected to the engine below.
Later we can imagine it as a signal.
This LED, the head of the LED, can be connected to the source or the ground, depending on how we control it.
If I use the ground here, I connect it to the sound of the LED.
Then we will control the head of the LED.
Click here to have a guide.
Then we name it.
Instead of connecting directly to the leg, we can connect through the name of the leg.
Select the LED.
We can name it LED1.
Similarly, we will connect to the ground of this LED.
Select the LED1.
Note that if you click here, you will not be able to name the wire, but you have to click on the wire.
Select the LED2.
We will connect the LED1 to leg 9.
To connect to the leg, instead of connecting the wire, we pull the wire here.
Click here.
This leg is inside, so it cannot be connected.
I will get a connection point here.
To get a connection point, you can choose the junction dot mode.
Click here.
We keep the control and the mouse wheel to enlarge the area of concern.
Connect to leg 9.
Connect to leg 10.
I'm testing a dot.
Delete it.
Now let's name it.
Go back to the label.
Select.
For example, leg 9 is LED1.
The name LED1 must be exactly the same as the name I just put on it.
For example, the letter L is written in Chinese.
The letter E and the letter D are written normally.
The number 1 is written immediately.
It must be exactly the same as above.
Leg 10 is LED.
OK.
We have completed the principle.
We have connected LED1 to leg 9 and LED2 to leg 10.
Now let's go back to the KISCode editing software.
Select KISCode.
Select the start block.
Select the input block.
Select the output block.
We will choose the output block.
Select the block.
Select the height and the distance.
Select leg 9.
Select leg 10 as set.
Let's make the height of leg 9 and leg 10 lower.
Both are opposites.
Then we click the button.
About the program.
We wait a while.
In fact, the editing process of the Arduino IDE is quite long compared to the editing process of other video games.
Next, there is one more time to switch from drawing to text, so it will take a little longer.
Click on the onTab button to switch to the window of the imitator software.
Double-click on the link for our request.
We will choose in the Storytech section so that we don't have to choose again next time.
Currently, I am putting the Qiskode software in the H folder.
You can put it anywhere.
The version is v3.beta because we are still updating some more features, so I am still in beta.
We will go to Storytech.
Here, I want to add a tool for you to refer to.
Suppose we don't see the guidelines like this, there is a very cool little trick like this.
You can download the Search Everything software.
For example, I have downloaded this software.
Search Everything is very convenient for us.
For example, we just need to search for Storytech and it will come up.
Let's double-click on it.
The other day, I saw that some people couldn't download the software because they didn't know where the program data was.
For example, with this MS Exchange software, you can just click here and it will come up.
Everything we need is available.
This software is very light, it only has a few MBs and it is very convenient to use.
You can use this tool for your work.
Let's go back to the tutorial.
Now we load this program into the imitation software.
Let's double-click on it.
Select Storytech.
And we always choose gitcode-scans.info.hack.
And this is the only time we have to do this.
But next time, the program will automatically load this guide.
And when we edit a new file, it will automatically copy the light.
Click OK.
Let's make it bigger.
Now I turn on 1 light and turn off 1 light, right?
And I press play here.
Or you can press F12.
F12.
I'm testing this light.
I'm turning on both of them at the same height.
I haven't turned it off yet, so it's still bright.
Then I'll turn it off.
Edit again.
Okay, we're done.
Now let's go to the imitation software.
And just press F12.
You can see right away that it has 1 light on and 1 light off, right?
This operation is simple.
However, today I will do it again from the beginning for you to see.
To make it easier.
This is the fastest way I think.
You use shortcuts.
And you use search tools.
To search faster.
In this tutorial, we will have a small exercise.
We will set up so that when the zoom button is on the left, the left light is on.
And when the zoom button is on the right, the right light is on.
To do this exercise, we will use the engine control block again, right?
But today we can use another command.
Here you can see there are a lot of commands.
Later, I will open the Kimcode software so that you can create your own commands.
For example, I don't like to install each engine anymore.
But I will use the command to move up.
With 100 power, we can imagine the power ratio of the engine.
The larger this number, the faster the robot will run.
And the largest is 255.
The reason is that we have 8 bits to divide the energy levels.
With the robot operating in units of 2.8 to 256.
It means that from 0 to 255.
So 255 is the largest.
So if this 100 is here, then we understand that 100 divided by 255.
It's exactly like that.
If our battery is strong, the robot will run better.
And if our battery is weak, the robot will run weaker.
So in the process, you need to make a full battery.
When you run it, you need to have a standard level.
We have to use a watch to measure exactly how many volts the battery is.
Setting the speed to 100 always returns the correct speed in the same condition.
Now we use the command to move up with 100 power.
Here we can click on it.
We can see that it reverses, turns left, turns right.
Let's say I want the robot to turn left.
The first light turns on.
Then after a while, we have to wait.
Let's say we wait 2 seconds.
The robot will turn left and the left signal light will turn on.
Within 2 seconds.
Then the robot will turn right.
And the right light turns on.
At this time, the right light turns on, so we have to turn it up, right?
But if we don't turn off the top light, both lights will turn on at the same time.
We can try.
However, we see that the left light does not turn off, right?
And it will be as bright as that.
To fix the program, if there is an error like this, it is often called a logic error.
We have to go back to the program to fix it.
Fixing the program is simple.
At first, the robot will turn left and the left light will turn on.
But after turning left, we have to turn off the left light.
When turning right, the left light must be turned off.
Similarly, when turning left, the right light must be turned off.
We have to fix it.
We have to wait for it to finish.
Successfully.
Play.
When turning left, the left light turns on.
When turning right, the right light turns on.
At the same time, turn off the left light.
And it keeps repeating like that, right?
Essentially, the program runs from top to bottom.
And we need to take a close look at the script to see if it is running correctly.
This is a simple user guide.
We can do a lot of other things with this light.
However, we will implement it later.
Now we will move on to the next part, which is the coil.
As you can see on the screen, we have a coil here.
If we look at it like this, we won't be able to see the structure inside.
We will return to the physics of this coil.
Actually, there are quite a few different types of coils.
Here we will use a coil called DC.
There are two main types that you need to distinguish.
First, we need to distinguish between two types of coils.
One type is active, and the other type is passive.
What are the differences between these two types of coils?
I will return to the simulation software so you can imagine.
Both of these coils have the same leg structure.
There will be a diagonal leg and a horizontal leg like this.
The diagonal leg will be marked with a plus sign.
The horizontal leg is usually longer than the horizontal leg.
Now we will return to the simulation software to find out about these two types of coils.
I have prepared it here.
To get the coil, you need to press the P key.
The name of the coil is Burst.
As you can see, there are two Burst symbols.
The first one is the Generate Burst symbol.
The second one is the No Simulator Model symbol.
This means that this coil cannot run in simulation.
Let's look at the coil below.
It does not indicate that it can run in simulation.
The name of the coil is DC Operator Burst.
This means that this coil can run in simulation.
Output via Sound Card.
It will emit a simulated sound through the sound card of the computer.
I have already taken it out and plugged it in.
For the other coil, you can use a speaker.
Similarly, we will choose a speaker that can emit sound.
Note that the name of the coil is Output via Sound Card.
This means that we have to emit sound to hear the sound.
Let's plug it in.
What are the differences between these two types of coils?
I am testing the machine below.
This is the Active Coil.
This means that we just need to supply the source of sound to this coil.
It will emit sound.
This is the sound of this coil.
Let's test the passive coil.
This is the sound of the passive coil.
However, the advantage of this coil is that it is simple to use.
This is the sound of the passive coil.
Now let's run a Mario game.
To run this game, you may need to program.
At any time, we will emit a frequency to make this coil sound.
I have prepared a program for you.
You can download the program from my website.
Today, I will download the Mario Burns program.
This is the program.
You can download it from arduino IDE.
Open the program from arduino IDE.
Open the program in the IDE
I have opened the Arduino IDE
Arduino IDE is running
We will open the Arduino Mario file
I have also downloaded this screen
It will create a file like this
We only need to take the hex file, so you just need to click on the transcript here
Wait a minute
After the transcript is done, it will create a hex file
To see the process of the Arduino IDE transcript
You have to go here, go to the file
Normally it will not appear in the window below
You have to go to the file, select references
Then you have to type in the word compilation
Then it will appear
If the font is small, you can increase the font size
You can see the font is bigger
After you have typed, it will appear in this window
You can see there is a .hex file here
In the last part of the transcript
You have to drag it from top to bottom
If you are interested in the .hex file, you have to go here
Go to the .c file
Press Ctrl-C to copy
You have to copy a few times
Then you will run to the imitator
Press Ctrl-V
Then press OK
Let's see how the sound is
In this program, you can see that in the first part
It says pin 5
We have to connect this speaker to pin 5
Normally you connect it directly to pin 5
Let's see what happens
Press F12
Do you hear it?
Because of the remote control, we have to connect it directly to the speaker
So it's small
To make the sound louder, we need a transistor
You take any transistor
You connect the pin of the transistor to pin 5
And the output pin is pin E
The output pin is pin E
I don't know if there are many people here who play Mario
This is a 4-button game from the old days
I proved that this speaker has to emit a signal
Then it will run and it will run sounds like that
Now let's try with the same program
We plug the transistor into the bus
Let's see if it works
You can see that there is no sound at all
Each has its own advantages and disadvantages
This bus is called iStickBus
We only need to supply 1 volt
This speaker can emit single-note sounds
If you change the frequency, the sound will be different
It depends on how much frequency you want to change
I have prepared a frequency emitter to change
This is a frequency emitter
Instead of plugging it into the remote control
We emit a signal
Now let's press play
This is the emitter
I can change the frequency here
First, I choose the type of bus
Square bus, triangle bus
Square bus
ActiveBurst
For example, I will connect the pin of this speaker to pin 5.
I will not use this speaker anymore in our exercise.
We will perform a very simple exercise.
If our robot moves forward, we can run normally.
If we move backward, we need to warn the person behind us
by turning on the lights.
To do this exercise, we connect the pin of this speaker to pin 5.
The same as the previous exercise, we connect the motor to pin 3, 8, 6, 7.
The two lights are connected to pin 9 and 10.
If our robot moves forward, we can run normally.
If we move backward, we need to warn the person behind us by turning on the lights.
To do this exercise, we connect the motor to pin 5.
If our robot moves forward, we can run normally.
If our robot moves forward, we need to warn the person behind us by turning on the lights.
For the 5th step, we can only call Koi
Koi does not call, because we are fighting Koi with the 5th step, so the low level will not call
Go up, everything is off in 2 seconds
Back up, everything is reversed
Light and Koi call
And we also translate to the hack file
Click next to the program
Next to success
Now we have to get the hack file
This hack file is translated by the Kiskode software
It will be in the story hack
I put it in the Kiskode file
When you click Kiskode, you will see the story hack at the end
Kiskode sketch.ino.h
OK
12
Koi does not call
We need to check the connection
When the 5th step is green, Koi is also green
When the 5th step is off, Koi is also off
It seems to be connected
Check the connection
When the 5th step is green, Koi does not call
Let's try this Koi again
This Koi is very strong
If you hold it straight, it will definitely call
This Koi is very strong
Let's add a TransStore
Instead of holding it straight, we will hold it like this
Let the Koi flow through the TransStore
Let's try
When the 5th step is green, Koi does not call
I will give you a gift to encourage your class
You have learned how to hold Koi and Lantern in the robot system
