WEBVTT

00:00.080 --> 00:05.990
And it's time for a new activity so you can practice with the new Pir sensor you have added to your

00:05.990 --> 00:06.350
circuit.

00:06.350 --> 00:11.630
And this activity will, if you manage to successfully do the previous ones, this activity is going

00:11.630 --> 00:12.830
to be quite easy.

00:12.830 --> 00:13.910
So what do we want to do?

00:13.940 --> 00:17.510
We want to do an automatic lighting control.

00:17.540 --> 00:19.070
Or it could be an alarm system.

00:19.070 --> 00:23.720
Well basically we want to turn on the LED if there is movement.

00:23.720 --> 00:29.480
So the LED whichever LED for example the first one we're going to turn on that LED if a movement is

00:29.480 --> 00:33.350
detected and turned off if no movement is detected okay.

00:33.380 --> 00:35.360
So it should be quite easy.

00:35.390 --> 00:40.370
You will need to import the different modules, initialize the components, and then find a way to do

00:40.370 --> 00:40.670
that.

00:40.670 --> 00:41.720
And that's the first part.

00:41.750 --> 00:46.520
As the second part we're going to do an improvement with the code because I'm going to give you a new

00:46.520 --> 00:47.690
function okay.

00:47.720 --> 00:50.510
To use as a challenge to try to use this new function.

00:50.510 --> 00:55.820
So what you have seen for now is that let's say we have initialized a Pir variable here.

00:55.820 --> 01:00.020
You can do Pir dot motion detected.

01:00.410 --> 01:00.710
Okay.

01:00.740 --> 01:03.440
This is going to give you true or false.

01:03.440 --> 01:05.780
But then there is something else that you can do.

01:05.780 --> 01:12.040
So in the code if you remember with the button we had something like button dot when pressed.

01:12.070 --> 01:12.340
Okay.

01:12.370 --> 01:15.340
And you would register a callback function.

01:15.340 --> 01:24.460
Well you have the same thing for the pi you can do pi r dot when motion like this.

01:24.490 --> 01:28.420
And pi r dot when no motion.

01:28.450 --> 01:28.630
Okay.

01:28.630 --> 01:30.040
So quite explicit.

01:30.070 --> 01:34.600
If a motion is detected then you can register a callback function.

01:34.600 --> 01:40.330
If you are not sure about callback function, please go back to the section where we plug the plus button.

01:40.330 --> 01:41.620
And then we do the activities.

01:41.620 --> 01:43.780
I explained all that in those activities.

01:43.780 --> 01:48.430
So basically when motion is detected you can give a function.

01:48.430 --> 01:51.340
So my for example you have defined a function my function.

01:51.340 --> 01:55.060
And make sure to not put any parentheses okay.

01:55.060 --> 01:56.980
And you can do the same with no motion.

01:56.980 --> 02:02.830
So when you do this you will also need to pause the execution after because it's just going to register

02:02.860 --> 02:06.970
a function to call later when this is happening.

02:06.970 --> 02:09.220
So I don't give you any more information right now.

02:09.220 --> 02:13.360
It's your time to practice and I will see you in the next video for the solution.
