In this activity, we are actually going to start from the code, from the previous activity, so I
have here created a new file and I just took the entire code from the previous HDD, which already works.
And the goal of this activity is to practice with functions, arrays and folders.
So we are going to improve that program.
OK, we're going to keep the exact same functionality, but improve that program.
So what are you going to do here?
Well, first, you can see we have three entities and we handle you can see here we do promote multimode
digital.
Right, right.
Right.
So this is quite a lot of repetition in the code.
So what you do is you will create an array to contain the things for the entities.
And then let's say here for all the modes you are going to instead of writing code three times, you
are going to create a follow up, go through all the pins and set all the pins to.
The same goes for the initialization return of all it is you are going to create here a or.
And then as a second step, what you are going to do is put this into a function, so to set the mood
for the things and then this into another function, to turn off all the attendees and then this cue
this block of code.
Where you toggle the state, you are also going to put it inside a function that DNA will have one,
two and three functions, so the void setup and the void loop functions will be much more later.
And just going to give you a few tips to get started.
So let's actually create the array.
So just continue here in the global scope.
The first you need to give a type.
And what is the type of this?
Well, the type of this, the type of the pins here is actually not exactly inert, but instead bite.
OK, what is Bayt?
Is it the first time we use bite?
You have heard previously that, for example, I said integer is stored on two bytes and along is stored
on four bytes case or that is simply that I type which contains wrong numbers from zero to two hundred
and fifty five.
If you remember from what we did with the analog right.
Function with repeatably when.
Well that's exactly disarranged a bit a brain function.
Actually the parameter that you sent to it in the right was about nothing really complicated about is
simply an integer but smaller just on one byte.
So zero to two hundred fifty five.
So the name for the array will be in the right it.
So you can choose this name and then you need to give.
The site is the site would be three, but actually instead of help getting the site, we can maybe create.
Another defining entity in the right.
It's a.
This is quite explicit.
It's been a recital three.
And then we simply do this.
Right here.
All right, so this is better because if we want, for example, to add a new entity, we simply add
a new entity, we simply increase by one year and let's initialize the area that we are simply going
to give into the three brackets.
And the one being.
And then energy to pin.
And then at three know.
And use a semicolon and as you can see here, we have a quite long line, OK, and it's quite recommended
when you program to keep lines quite short.
OK, so here in my program, I have found 18 and to make it more readable, what I can do is simply
after the equals sign here, I'm going to press enter and this price tag puts a few times doesn't really
matter.
And just put this on a new line if you have this, but equal sign and then something on the new line.
Well, this is the following of the statements.
So is just like it was one line, but it's much more reliable.
OK, have the time, array the size and then you see the values here.
All right.
So you have the array and then you can use this right to actually that's the pin mode that the digital
right initialize the any and the function.
So here just going to give you the name of the function.
So this would be a void function mode and you can name it, for example, said LTT.
Incommode.
And here you can, for example, it.
Then of all these.
OK, so you trade to function here on the top of the program after the initialization of the valuables
and constant and insider function, use a follow up to go through all of the ends of the.
And then for this, but you can use a function, let's say.
Which name is Pogo, and it is.
All right, so now you have enough information to work on and I will see you in the next listen for
the solution.