And this is the solution to a previous activity where you need to set the brightness of the energy directly
from the potential emitter.
So let's begin by the beginning and let's first create a defined for the energy bill and for the potential.
So everything is still being driven and then define what an shmita.
Which is number eight to all right in the center.
So what do we need to set up?
We need to set up the area for sure demoed because this is a digital thing.
So and we need to set it as an output.
OK, so that wait, no, know, not the potential amount of pain is an analog input means that we don't
need to use B mode.
It's already input B also.
We don't need to yell here.
So we are not going to and should I say also that's it for a setup function.
We have our Thain's.
Everything is set up now in the loop, we can start the main program, so what we are going to do,
we are going to read the value from the pot on Shimano and provide this value to the entity that with
this modification here where we need to scale down the value from the analog rate.
So what I'm going to do first is to create a viable integer viable.
OK, but on Schmitter.
Value, which will store the value from the analog read function, so analog read and we provide the
production with a peno.
All right, so when we do that, this will return a value between zero and one thousand twenty three,
which we store into that value.
And I'm going to create that's another variable which will be added brightness.
And this will be what I'm Schmitter.
Value divided by four, I compute this.
OK, so this will basically scale this down to zero and 255 to approximately.
OK, we don't need to be super precise here that we divide the value by four.
And then what we do is analog.
Right before, right, we need to provide two parameters.
First is the bin.
And then the value.
So the value is any brightness.
And said, well, we don't really need to delay, we can just do that at full speed.
OK, that's not really a problem.
So to recap, first we define the beans as always.
We set up the mode for the LDP as an output pin.
OK, we read the value from the pot on Schmitter.
We cannot agree to function these returns a value between zero and one thousand twenty three.
We still add value and then we create another valuable to store the new value for the which is the punishment
of a divided by four.
So we take down the value and then we analog write.
We can write on the digital bin for the entity and provide a policy in and duty cycle of the period.
Um, is the any brightness between zero and two hundred twenty five.
So again, make sure I agreed to read an analog input being an analog.
Right.
This is to write on a digital bin with the living functionality of it.
Don't make the confusion between them.
All right, so let's just compile a code to see if it's just working activity.
It's done complaining, so we don't have any error, if you have an error here, then you fix the problem
and you try to combine again.
And no, that's the code.
Right, the court is applauded and as you can see, so the energy is boiled on here because simply the
put on trimethyl is at some point between the minimum and maximum and the minimum.
So we have this energy here with this brightness.
And no, I'm going to move the matter here back to the minimum and you can see the energy just fade
out.
I'm going to turn.
Increase the value and you can see the aid now is becoming more and more bright and more intensity,
and then I turn it back low intensity so I can just that the brightness I want directly from the bottom
of it.
And as you can see, it's currently walking.
And you can see here also the results on tinkered with the simulation, so I have just the exact same
code we used for the activity and studied the simulation.
Now, here's the potential, a look at the energy here.
So the conundrum is at the minimum.
Now I'm going to turn it all the way up and you can see the energy, the in and the energy laid out.
So it's working just as with the real secrets and.
Well, congratulations.
That is the end of the activity.