Hi and welcome to a new section in this course in this lecture.
I'm going to talk about timers, in particular the hardware timers that are available to you via Micro
Python, and they are implemented in hardware in the E.S.P 32 later in this section.
And what we're going to talk about other capabilities that are embedded in the HP 32 and you can use
them through micro python, such as, for example, the ability to control the C.P.U clock of your E.S.P
32 to access the integrated whole effect sensor and the raw temperature sensor that gives you information
about how hot your is.
B 32 is running how to put your ESB 32 into deep sleep, which is great if you're building a battery
powered gadget and things of that sort.
In this first lecture of this section, as I mentioned already, I'm going to demonstrate how you can
use the hardware timers that are integrated into your E.S.P to every scene.
How to use at least one of those times in previous lectures has assured you, for example, how to control
in ality using a timer instead of using an infinite loop or other types of loops just to begin with.
You can have a look at the documentation right here in the macro Python website.
And I'm looking at quick reference for the E.S.P 32.
And the time is that's where you learn that the E.S.P 32 comes with four hardware.
Time is integrated and the way to use them is to import the time a module from the machine module and
then set them up like this.
You indicate through the perimeter here of the time a module which time it is that you want to use in
a to in a day from zero to three, and then you initialize the time you need to indicate the period
and then the type of mode that you want to set the timer for.
So either a one short time.
So this is going to fire once or periodic in this case.
This time it's going to fire every 2000 milliseconds, every two seconds.
And then what is it that you want to do in particular?
What kind of functions would you like it to call once the time expires?
You can either use a lambda lambda is simply a tiny function that you can embed into the parameter itself,
or alternatively, you want to go for something more traditional and classic.
You can set a interrupt service routine like I've done here, which is just a regular function that
is being called when the timer expires.
So as I said, you can use up the full timers in my example.
So what I do wish to use and IGB ality, which contains three component abilities in the same package,
red, green and blue.
And you see, I've set that up on my breadboard.
I've got the red segment connected to Tapio 21, the blue segment connected to Jhpiego 22 and the green
connected to your twenty one a23 sorry.
And I have set up three hardware timers, each one set up to have a slightly different period.
So you can see that the first one here I did zero time sensitive period of 250 milliseconds and when
that expires it will call the red blink itself, which is this method right here or this function right
here.
Then time, although the a slightly different period, 350 milliseconds that's going to call the blue
blink ISO, which is right here.
And finally, the last one is timer with ID Editta.
It's got a period of four hundred and fifty milliseconds and that's going to call the green blink guess
which is right here.
And those will just simply turn the lights on and off.
And because the period is slightly off compared to each other, I'm getting some interesting effects
that I think make the end result quite interesting.
But the point here is that I've got three independent timers and each one, when it expires, it will
call its own interrupt service routine and it will control your independently of all the others.
You could add one more here.
They could have a total of four hundred titles.