1
00:00:00,180 --> 00:00:06,830
In the previous lecture, we implemented the task schedule so that we don't need to use any delay functions

2
00:00:06,840 --> 00:00:14,100
at all in our schedule, and that, as I said earlier, improves the capabilities of our inspectorate

3
00:00:14,100 --> 00:00:15,630
to sketch its efficiency.

4
00:00:15,900 --> 00:00:23,670
It also allows us to implement new functionalities that would be fairly hard and complicated to do without

5
00:00:23,670 --> 00:00:24,950
a task scheduler.

6
00:00:25,620 --> 00:00:33,780
What we'll do in this lecture is to implement a safety feature that involves getting the pump automatically

7
00:00:33,780 --> 00:00:36,390
turned off after five seconds of operation.

8
00:00:36,750 --> 00:00:42,060
And as you'll see in a moment, this is something very easy to do with the task scheduler.

9
00:00:42,600 --> 00:00:44,250
And at the same time, we will edit.

10
00:00:44,250 --> 00:00:50,820
I'm going to do a bit of refactoring and improve the organization of the sketch.

11
00:00:50,820 --> 00:00:59,250
And in particular, what I'm going to do is to make the voltage reporting functionality independent

12
00:00:59,250 --> 00:01:02,040
of the soil humidity reporting.

13
00:01:02,050 --> 00:01:08,340
Essentially, I'm going to put report for that use to be executed in its own task, in its own schedule.

14
00:01:09,240 --> 00:01:16,200
So to do that, I have implemented the changes in version five of the sketch.

15
00:01:17,430 --> 00:01:26,520
Let's have a look at it in the header of the sketch, here is the soil humidity core back and its task

16
00:01:26,520 --> 00:01:34,860
and I have added another two tasks and callbacks, the pump of Cool Back, which will ensure that the

17
00:01:34,860 --> 00:01:38,640
pump is turned off five seconds after it starts.

18
00:01:40,420 --> 00:01:46,550
And then also have to report to both the Chiefs quarterback, which will be independently reporting

19
00:01:46,550 --> 00:01:53,500
voltages every two and a half seconds, while humidity will be reported every once and again independently.

20
00:01:54,190 --> 00:01:56,950
And we still have the single runner.

21
00:01:57,010 --> 00:01:59,810
A single runner can control multiple tasks.

22
00:02:00,430 --> 00:02:03,850
So these are our quarterbacks then inside.

23
00:02:04,820 --> 00:02:06,590
The set up function.

24
00:02:07,630 --> 00:02:14,830
We initialize the runner, then we add the three tasks and we enable two of them, so I have enabled

25
00:02:14,830 --> 00:02:22,990
here the soil humidity task in the report voltages task, which I want these tasks to be enabled always.

26
00:02:22,990 --> 00:02:25,900
And therefore, I don't have to worry about turning them on and off.

27
00:02:25,900 --> 00:02:33,420
But the task scheduler gives me the ability to programmatically enable or disable a task.

28
00:02:33,430 --> 00:02:40,120
And when I enable a task, it's time I essentially start counting and when I disable it, it does not

29
00:02:40,810 --> 00:02:41,710
for the pump.

30
00:02:41,950 --> 00:02:49,360
It does not make sense to enable that at the beginning or in the setup of our sketch because I only

31
00:02:49,360 --> 00:02:53,500
wanted to count down if the pump is turned on.

32
00:02:53,980 --> 00:02:55,950
So that's when I will be enabling it.

33
00:02:55,960 --> 00:02:58,800
So we'll have a quick look at that next.

34
00:02:58,810 --> 00:03:01,500
Let's see, what else do we have here in terms of changes?

35
00:03:02,530 --> 00:03:04,480
There's the loop in inside the loop.

36
00:03:04,480 --> 00:03:08,590
We've got the execute function of the runner called every time we go through it.

37
00:03:09,100 --> 00:03:15,220
We no longer report the humidity inside the loop in this no more, no longer delay.

38
00:03:16,860 --> 00:03:17,630
Here's the report.

39
00:03:17,650 --> 00:03:22,650
Humidity core back, which you saw in the previous lecture, that's where we implemented it.

40
00:03:23,040 --> 00:03:31,200
And now you see that at the bottom of this function commented out the report voltages call to the public

41
00:03:31,740 --> 00:03:36,040
function because this is now happening by the scheduler.

42
00:03:36,060 --> 00:03:39,220
So let's put it out next.

43
00:03:40,560 --> 00:03:45,690
Now, here's the thing that I mentioned earlier about the pump control in control.

44
00:03:45,930 --> 00:03:53,430
The function, the code is exactly the same, except for line one hundred and forty six in line one

45
00:03:53,430 --> 00:03:54,570
hundred and forty six.

46
00:03:54,570 --> 00:04:04,110
I call the enable delayed function of the turn pump off task and a part of the value of 5000 the 5000

47
00:04:04,110 --> 00:04:13,110
milliseconds, which means that this function will count down to 5000 and then it's going to call each

48
00:04:13,110 --> 00:04:21,810
callback function or the tasks callback function, the turn off pump task callback function as we saw

49
00:04:22,080 --> 00:04:22,860
at the top.

50
00:04:24,510 --> 00:04:26,850
Is this pump of.

51
00:04:28,320 --> 00:04:35,880
So that is implemented right here and as you can see, what happens in that is to turn off the pump

52
00:04:36,690 --> 00:04:44,730
by sending a low signal to the pump pin and then we call the disable function of the task to turn it

53
00:04:44,730 --> 00:04:47,610
off and then it's going to be turned on again.

54
00:04:48,620 --> 00:04:59,640
Some point later when the pump is turned on again, and that's where the 5000 millisecond counter restarts.

55
00:05:02,030 --> 00:05:06,290
Another callback he can see right here is the report, which is called Back.

56
00:05:06,320 --> 00:05:11,180
This is called right now every two and a half seconds, I believe.

57
00:05:11,210 --> 00:05:11,780
Let's see.

58
00:05:12,770 --> 00:05:19,200
You know, every two and a half seconds, we call the report voltages to.

59
00:05:23,530 --> 00:05:29,620
Which then will just carry on taking measurements and then publishing them the code in this callback

60
00:05:29,620 --> 00:05:37,360
function is identical to the function called report voltages in previous versions of this sketch, and

61
00:05:37,360 --> 00:05:37,940
that's about it.

62
00:05:37,960 --> 00:05:44,500
So we've got a new function which will automatically turn off the pump when it's on.

63
00:05:44,630 --> 00:05:51,100
After five seconds of spinning, of the motor spinning and then of refactored are the part of the code

64
00:05:51,100 --> 00:05:58,120
so that the report voltages function happens autonomously from the soil humidity function in the last

65
00:05:58,120 --> 00:06:04,330
thing to do to upload the sketch and make sure that it is still working and that we haven't broken anything.

66
00:06:07,420 --> 00:06:15,250
OK, so the new sketches uploaded and turn on the power supply to do a bit of testing.

67
00:06:17,120 --> 00:06:24,410
So you've got the threshold at five hundred and twenty and you've got the soil humidity from the potential

68
00:06:24,650 --> 00:06:26,940
at 465 comi.

69
00:06:27,020 --> 00:06:30,440
Turn that up a bit 540.

70
00:06:30,470 --> 00:06:31,430
And that works.

71
00:06:34,270 --> 00:06:42,990
And the pump stopped automatically perfect, then go down again and trigger the pump one more time.

72
00:06:50,480 --> 00:06:51,800
Perfect, it's great.

73
00:06:54,760 --> 00:06:57,100
So the author of.

74
00:06:58,170 --> 00:06:59,430
Function is working.

75
00:07:01,760 --> 00:07:05,600
And everything else in my dashboard is working as well.

76
00:07:06,690 --> 00:07:07,070
OK?

77
00:07:08,890 --> 00:07:15,460
Except for the manual pump control, you can see the manual pump control does instruct the pump to turn

78
00:07:15,460 --> 00:07:23,950
on, but then the MCU itself, the switch that is running on the is pathetic to detect that the threshold

79
00:07:23,950 --> 00:07:29,380
for the humidity is below what I've said and it will turn off the pump automatically.

80
00:07:32,170 --> 00:07:32,520
All right.

81
00:07:33,680 --> 00:07:35,220
So I think that is acceptable.

82
00:07:35,600 --> 00:07:44,210
Of course, you can get your ISP heritage to allow you to override the pump state with the switch,

83
00:07:44,220 --> 00:07:49,790
here is something that you can do if you want, but I'm not going to bother with it at this point.
