1
00:00:00,750 --> 00:00:01,650
Hello and welcome.

2
00:00:03,270 --> 00:00:08,820
In this lesson, we are going to take on the P.W. ambitions of the sport.

3
00:00:09,900 --> 00:00:18,060
All 36 of the 32 general purpose Input-Output Benz has a P.W. arm capability.

4
00:00:19,200 --> 00:00:20,730
This is a really great thing.

5
00:00:21,840 --> 00:00:27,570
But we must use more complex code to reach the same result on other pins.

6
00:00:29,300 --> 00:00:35,840
So let's put it on one of the general purpose, Input-Output with appreciable output signal.

7
00:00:36,740 --> 00:00:46,390
Now if you went to this schematic all this pin out for these people, you can see that all of these

8
00:00:46,400 --> 00:00:50,420
pins can be used to generate P.W. arm signals.

9
00:00:51,350 --> 00:00:59,300
The first thing that you need to think about when programming a P.W. on the signal is its frequency.

10
00:00:59,870 --> 00:01:04,160
You need to retrieve that signal at a certain or a specific frequency.

11
00:01:04,670 --> 00:01:07,730
We would use a value of 5000 hertz.

12
00:01:08,480 --> 00:01:10,580
That works fine with our lead.

13
00:01:11,210 --> 00:01:20,090
We must also specify that it P.W. Omni channel and the resolution of the BW and duty cycle I want.

14
00:01:21,410 --> 00:01:28,580
Explain that BWR, because you must have some basic knowledge about BW signals, but what it takes is

15
00:01:28,580 --> 00:01:32,720
a resolution, a channel and a frequency.

16
00:01:33,500 --> 00:01:42,500
So after specifying that you cycle using the resolution and the frequency on the channel, we can start

17
00:01:42,500 --> 00:01:43,100
programming.

18
00:01:43,670 --> 00:01:49,790
We can choose a channel from zero to 15 and a resolution between one and 16 bits.

19
00:01:50,510 --> 00:01:54,710
We will use Channel zero and the resolution of eight bits.

20
00:01:55,130 --> 00:01:57,410
So let's get started.

21
00:01:57,510 --> 00:01:59,990
That's good, according to your thumbnail sketch.

22
00:02:01,250 --> 00:02:02,990
And here's another sketch.

23
00:02:03,050 --> 00:02:05,060
Let's define some variables.

24
00:02:05,450 --> 00:02:09,950
First, we need to define that frequency and frequency.

25
00:02:10,730 --> 00:02:12,440
And let's make it 5000.

26
00:02:14,330 --> 00:02:15,860
Then we need the left channel.

27
00:02:18,410 --> 00:02:22,880
Let's make it zero and we need the resolution.

28
00:02:25,830 --> 00:02:27,620
And let's make it eight.

29
00:02:28,880 --> 00:02:32,930
Now let's use the general purpose input output one.

30
00:02:33,530 --> 00:02:38,570
Number two where we have our lead on our external LED, connected or attached.

31
00:02:38,900 --> 00:02:41,840
It's it also has a built in lid that can be used.

32
00:02:42,440 --> 00:02:48,830
So these parameters must be defined inside the setup function.

33
00:02:49,190 --> 00:02:52,340
So let's go and hide this code.

34
00:02:53,360 --> 00:03:01,190
Now what we are going to write in inside the setup function won't be something we are used to while

35
00:03:01,190 --> 00:03:01,840
going to light.

36
00:03:01,850 --> 00:03:05,540
Let's see a dustbin and lid see setup.

37
00:03:06,230 --> 00:03:09,310
Now the Let's See attachment and let's use it up.

38
00:03:09,320 --> 00:03:13,820
There are basically functions for the BW arm configuration.

39
00:03:14,300 --> 00:03:17,840
They are very similar to another great functional Arduino.

40
00:03:18,650 --> 00:03:21,620
So now that USP.

41
00:03:22,680 --> 00:03:29,000
Doesn't support another great function, but it does support a much better one, which is the one that

42
00:03:29,010 --> 00:03:29,970
we already mentioned.

43
00:03:30,300 --> 00:03:32,460
Let's see right there.

44
00:03:32,460 --> 00:03:32,780
Let's see.

45
00:03:32,790 --> 00:03:35,490
Light function is very similar to an outlook, right?

46
00:03:35,580 --> 00:03:45,150
It also requires two parameters that BW channel that we want to write about Utah and the BW value.

47
00:03:45,180 --> 00:03:48,060
We want to write to the selected channel.

48
00:03:49,050 --> 00:03:52,560
Now, let's first finish the setup function.

49
00:03:53,460 --> 00:03:56,790
Now the let's see setup function.

50
00:04:00,270 --> 00:04:01,710
Will take three parameters.

51
00:04:01,900 --> 00:04:03,690
The first one will be valid channel.

52
00:04:06,880 --> 00:04:10,090
The second one will be the frequency.

53
00:04:10,670 --> 00:04:14,590
The third one will be the resolution, which we already defined up there.

54
00:04:19,550 --> 00:04:26,120
Next, we are going to assign a lead to that channel, so let see a dash pin.

55
00:04:28,400 --> 00:04:38,630
Now the lid pin we already chose is two and we want to attach it to the lid channel that we have chosen.

56
00:04:40,520 --> 00:04:41,130
This is it.

57
00:04:41,150 --> 00:04:49,580
This is how you finish sitting that BW, um, frequency resolution and channel and how you can attach

58
00:04:49,580 --> 00:04:51,770
it to any output pin.

59
00:04:53,710 --> 00:05:01,870
Now, to tear down the lid, which is connected to PIN number two using the lid channel output from

60
00:05:01,870 --> 00:05:03,110
the BW, I'm signal.

61
00:05:03,910 --> 00:05:09,880
We need to set a specific brightness now to turn it on or off.

62
00:05:09,970 --> 00:05:12,070
We must define the duty cycle.

63
00:05:12,490 --> 00:05:19,750
For example, the turn of the lid that each cycle must be zero on the function lid see right that we

64
00:05:19,750 --> 00:05:25,810
already mentioned can be used inside the loop to set the brightness to zero.

65
00:05:26,250 --> 00:05:26,710
Now.

66
00:05:28,510 --> 00:05:31,130
We can use that function right now, that's right.

67
00:05:31,150 --> 00:05:31,670
Let's see.

68
00:05:31,880 --> 00:05:32,320
Right.

69
00:05:34,900 --> 00:05:37,020
It's exactly like analog, right?

70
00:05:37,030 --> 00:05:38,650
And it takes two parameters.

71
00:05:38,650 --> 00:05:42,760
The first one is the lead channel, which is this variable.

72
00:05:43,700 --> 00:05:47,530
And the second one is the duty cycle.

73
00:05:49,540 --> 00:05:56,500
Now you can add in duty cycle here and add zero.

74
00:05:56,650 --> 00:06:01,390
This will turn off valid because we have since zero.

75
00:06:02,510 --> 00:06:08,450
To the left channel, which has been number two, and it will set the protest to zero.

76
00:06:09,290 --> 00:06:12,230
Now different values of the duty cycle.

77
00:06:13,400 --> 00:06:15,950
Will turn on the lead with different priorities.

78
00:06:17,030 --> 00:06:25,430
Now this variable can be from zero up to 255 once that resolution used is eight bits.

79
00:06:25,970 --> 00:06:35,240
If we used 18 bit resolution, it can go from zero up to 1024 or 1023 and so on.

80
00:06:35,450 --> 00:06:41,770
We already mentioned that you can choose a resolution between one and up to 16.

81
00:06:42,560 --> 00:06:50,150
So the choice is yours, but you need to make sure that you are choosing a duty cycle that matches your

82
00:06:50,150 --> 00:06:50,780
resolution.

83
00:06:51,800 --> 00:06:58,660
So an eight bit resolution, that cycle would be between zero and 125 to 155.

84
00:06:59,330 --> 00:07:09,680
OK, now that we are done with this, we can use that potential meter connected to the analog pen from

85
00:07:09,680 --> 00:07:17,270
the previous lesson to control the brightness of that lid, or we can simply send values.

86
00:07:17,510 --> 00:07:21,440
Now, to test this out, let's complete the code.

87
00:07:22,400 --> 00:07:35,540
Let's first and the setup menu add cereal to begin and choose a moderate one hundred fifteen thousand

88
00:07:35,540 --> 00:07:43,040
two hundred, then other delay as usual for one second

89
00:07:45,770 --> 00:07:46,700
after the delay.

90
00:07:46,880 --> 00:07:51,320
Let's write a sentence to make sure that everything is working correctly.

91
00:07:51,800 --> 00:07:54,720
Trend line.

92
00:07:56,930 --> 00:08:01,560
And let's name this thing on.

93
00:08:03,230 --> 00:08:14,930
OK, now we have the lid setup on the lid see at dustbin and we can use the lid see right up here.

94
00:08:16,610 --> 00:08:20,630
And the first value that will be written is zero so that it will be off.

95
00:08:21,650 --> 00:08:25,940
Now, inside the void loop, we can send other values.

96
00:08:27,290 --> 00:08:28,250
We can't send.

97
00:08:30,770 --> 00:08:33,230
Duty cycle, let's define duty cycle here.

98
00:08:35,600 --> 00:08:36,080
Plus.

99
00:08:38,380 --> 00:08:41,350
Equal +1, and let's add.

100
00:08:47,480 --> 00:08:56,330
It's make it 15 milliseconds, okay, now, uh, let's walk this line down here.

101
00:08:57,130 --> 00:08:58,450
It will start with zero.

102
00:08:58,690 --> 00:09:08,580
Then it will be +1 or let's make +10 and we'll keep moving until it reaches 235.

103
00:09:08,650 --> 00:09:12,580
We kind of had an if statement, but this this this called out.

104
00:09:15,680 --> 00:09:19,790
Let's first upload or verify it to make sure it doesn't have any errors.

105
00:09:20,990 --> 00:09:21,980
Let's save it.

106
00:09:25,090 --> 00:09:26,880
BW on this thing.

107
00:09:38,430 --> 00:09:40,860
OK, then combining now, let's upload the code.

108
00:09:47,710 --> 00:09:53,980
We should we should add a line to make sure that we will pretend that it's cycle.

109
00:10:01,970 --> 00:10:04,760
We want to combine the cold, but for now.

110
00:10:11,560 --> 00:10:16,900
Let's put it, compile it so that we can get that just like in here now.

111
00:10:18,460 --> 00:10:22,150
Let's recompile the code for the fight again.

112
00:10:30,570 --> 00:10:31,740
Now it's loaded.

113
00:11:13,030 --> 00:11:14,050
OK, now.

114
00:11:15,140 --> 00:11:23,510
As you can see, it went above to 155 very fast, so we need to control this once the duty cycle reaches

115
00:11:26,120 --> 00:11:29,840
its cycle is of equal to 125.

116
00:11:30,470 --> 00:11:33,680
We needed to reset to zero.

117
00:11:36,290 --> 00:11:38,030
Now let's combine it again.

118
00:11:40,590 --> 00:11:41,670
Now, let's upload it.

119
00:12:00,050 --> 00:12:00,430
OK.

120
00:12:00,620 --> 00:12:01,070
Done.

121
00:12:01,310 --> 00:12:12,110
Now, as you can see, once it reaches 255 intercepts to zero and from your ISP board, you can see

122
00:12:12,110 --> 00:12:19,790
that the built in led all of accelerate that you are connecting is fading in and out using this very

123
00:12:19,790 --> 00:12:20,540
simple chord.

124
00:12:21,690 --> 00:12:26,700
Now, now let's summarize what we did this last one.

125
00:12:26,880 --> 00:12:29,580
We have saved the frequency to five thousand.

126
00:12:30,090 --> 00:12:36,630
We have choose the channel to be zero and we have chosen the resolution to be eight, which means that

127
00:12:36,630 --> 00:12:39,690
we have to cycle between zero and 255.

128
00:12:40,530 --> 00:12:45,750
We started with a duty cycle of zero and he shell out of the theater communication.

129
00:12:46,170 --> 00:12:47,950
Here we used new functions.

130
00:12:47,970 --> 00:12:54,270
Let's use it up to set up the BW frequency channel and resolution.

131
00:12:54,780 --> 00:13:03,210
And this lets you attach pin to attach the function to us to a specific pin, which has been number

132
00:13:03,210 --> 00:13:03,690
two here.

133
00:13:05,460 --> 00:13:08,310
And the LCD right is basically like analog, right?

134
00:13:08,340 --> 00:13:15,240
It takes a channel and the duty cycle and to try its value to that channel.

135
00:13:16,520 --> 00:13:24,490
Now in this photo, we have used the LED channel, which was proudly attached here to pick number two

136
00:13:25,160 --> 00:13:26,240
and the new Typekit.

137
00:13:26,420 --> 00:13:29,060
And we kept increasing the cycle by 10.

138
00:13:30,500 --> 00:13:32,330
And printed on the Tehran monitor.

139
00:13:32,810 --> 00:13:39,470
Now, once that U.S.A. reaches 255, which is the limit here, we did that.

140
00:13:39,470 --> 00:13:40,970
I said the cycle to zero.

141
00:13:41,150 --> 00:13:42,620
To repeat the process again.

142
00:13:43,700 --> 00:13:49,630
And that is how you can fade added using P.W. Signal.

143
00:13:49,760 --> 00:13:51,740
You can apply this to any other thing.

144
00:13:52,310 --> 00:13:59,540
You can choose 10 bit resolution in that case, if you did choose 10 bit resolution.

145
00:14:01,130 --> 00:14:06,740
You will get values between zero and one thousand twenty three.

146
00:14:07,070 --> 00:14:14,060
So in that case, this if statement will be 1023 instead of a set of 255.

147
00:14:14,840 --> 00:14:15,540
That's it.

148
00:14:15,560 --> 00:14:22,850
I know that this was a long glass on, but I wanted to explain, Uh, I'm using an example.

149
00:14:23,180 --> 00:14:27,440
I hope that everything is now well explained to you.

150
00:14:27,470 --> 00:14:30,450
If you have any question regarding anything, you can ask.

151
00:14:30,470 --> 00:14:31,280
This is Ashraf.

152
00:14:31,970 --> 00:14:32,930
See you next lesson.

153
00:14:32,960 --> 00:14:33,710
Happy ending.

154
00:14:35,620 --> 00:14:37,540
This is educational engineering team.
