This is the solution of the previous activity where you have to make the fade in and fade out so we
can actually separate this project into two parts.
First, we need to make sure that we have the index going from zero to 255 and then 255 to zero, and
then we need to set up the idea and use the analog right function.
So I'm going to work first on the two for loops.
We need to do that and make sure we have the correct values using the same monitor for debugging.
And then I'm going to write another great function.
I'm going to remove all of the comments.
And start with the first full loop so far, and then we create an index, it is equal to zero, so we
start at zero and then what is the maximum value we want?
The maximum value we want is 255.
So I is lower are equal than two hundred fifty five.
We could also use a strictly lower than two hundred fifty six and then I placeless.
So the follow up we go from zero to two hundred fifty five increasing by one every time.
OK, that is the first the second for Luke.
So I'd like to get into space.
We're going to start from two hundred fifty five, OK, and we're going to stop at zero, so while I
still greater or equal than zero, we continue.
OK, you can read this as while this is true, we continue.
And then I'm minus minus, which means that we are going to decrements this index every time.
OK, I know the full ups are complete because here you can see we start at zero.
We go to 255 in this one, and then from 255 to zero.
And once we have finished those two follow ups, well, we go out of the void Leupen.
We go in again and we start again at zero.
So there is a continuity with the index here.
I know what I'm going to do is simply print to be sure that we have the correct values.
So surreal that begin.
OK, don't forget that we have nine thousand six hundred but right in the center function and here I'm
going to do say I've got.
Print and then we've I.
And also, there are those prints, Ellen.
We are as well, and as you can see here, we use the same name because this is a different scope.
OK, here the eye viable is local to the folk.
So basically it is contained between those two curly brackets looking this scope and this is in that
scope.
OK, so two different scopes and know what I'm going to do.
I'm going to add delay five.
OK, I'm going to add the delay because if we don't add the delay, it will print very, very fast and
it's not that reliable.
And well, let's try this first round.
So I'm going to compile the code as.
Activity to.
Let's see if we have any.
There are no darn campaigning, so no tools, ball and polls are correct, actually.
Well, just for printing, I'm going to increase this delay a little bit because that's going to be
a little bit too fast just for us to read the value.
So a delay of 15 milliseconds will be good.
I'm going to upload the code now.
Loading.
I'm going to say a monitor and you can see we go from zero.
OK, it's increasing.
A 150, 200 and then 200, you will see 255 and then we decrease the value.
OK, so 100 year we go down and we are approaching zero and you will see here zero.
And then we go up again.
So now we are sure that the index here, the high value that we need for analysis, right.
As the correct behavior.
OK, so wait, we can do now is actually to set up the entity to define energy in 11 in the set of function,
we are going to do in mode with energy in and output.
And in the void now, instead of printing and so we can remove, that's actually going to come and it.
Instead of printing, I we can directly do analog.
Right, we've been and the venue, which we know is going from zero to fifty five here, is going to
get back to Delate five milliseconds and then on the other phone.
Analogue, right?
The.
Dean, I as well could use the same code, but he and I is going from two hundred fifty five to zero
and also the delay pipe and let's run that code.
So now we don't take the same way we directly the energy.
And as you can see, the energy is fading and fading out just like we want it.
So as you could see on this program, sometimes it's easier to break the program, break the project
into different steps and try to validate each step one by one.
Once you validate one step, like we hear with the index, we can go to the next step.
And this way, creating product will be much easier for you and you will make much less errors.
All right, congratulations.
You have just finished this activity and now we are going to look at digital input.
Beenz.