Now, let us start writing the code, click on code right here, go to blocks and choose text, click
on Continue.
And this is your basic sketch.
Let's delete everything in the setup and everything in the loop, and we are going to let the set up
and the loop stay.
So.
What are we going to write in this set of.
We need to configure the things that we have, how many pins we have, we have been number three to
and PIN number eight that need to be.
Check.
So in order to do that and said the mode of the then to be either input output or input pullup, we
need to do the following.
We need to call the function bin mode.
And then you are going to write the name of the pen.
Let's start with number two, which is connected to the start button.
And we're going to set it as input, Paul.
OK.
Great.
So now input number two has an internal pull up resistor, as we have learned now we need to copy this
two times.
This is one and this is two.
So PIN number three, you need also to be an input pullup, so far, so good.
Now, how about PIN number eight?
Well, the PIN number eight is actually an output that is connected to the motor, right.
So this is an output because it's connected to something that need to be activated.
OK.
And by that, we are done with the set up and we have configured our motor.
That's great.
Now let's get to the actual killer.
What will this actual code do?
It's going to attempt to read this input and then it will attempt to read this output.
Now, what are we going to put in our main program?
We're going to read beento and PIN number three and take an action accordingly.
So how do we read a pen?
We read it by saying digital read and then by saying, which are we going to read?
So let's say we are reading PIN number two.
And what are we going to do with digital print?
Are we going to compare?
What are we going to store it in a variable?
What are we going to do exactly?
Well, let's use it directly.
Now, this is not the most efficient way to write a code, but it's a good first start.
So let's say if open a parenthesis, digital read two equals equals.
Low, I'm going to do something so this function is reading.
Number two, if this PIN number two is low, meaning that it's suppressed because when you press it,
we get the low of the GENNDY connected to the pin and going directly to the PIN number two.
So if we read low, meaning that it's suppressed, right, what are we going to do?
We're going to take some action.
We will get back to it later.
Now, what action are we going to take?
Well, I wanna start the motor.
How do we start a motor by writing a value of PI or five volt to this eight?
Then how do we do that?
We going to say digital, right?
What are we going to write here?
PIN number eight with a value of high.
It's like sending five volt through that pen.
OK, and that's it.
Now, if I press this button, pin number eight is going to send me five or no else.
If so, if this button is not pressed, I want to do something else else.
Now let us try to read the second button.
So if digital read PIN number three is activated, so it equals equals low.
It means that this button is a breast, not this one, so the GENNDY signal or the zero volt is going
to come all the way to the bottom to pin number three.
What are we going to do in this case?
Well, I want to turn off the motor, so I'm going to say digital, right?
PIN number eight with low.
What does this mean, I am sending a zero volt through PIN number eight, meaning that zero volt will
come here and this motor will stop.
Now, let us let this go and see if it works.
So let's start simulation.
Let me zoom in a bit, using the my mouth will now, if I for a start, as you can see, the motor is
rotating at 51 R.P.M. That's wonderful.
Now, if I stop, the motor will stop.
So, again, if I start, what's happening is this line of code is executing because I read this, it's
slow and I am sitting in no way to hide.
Now, this function is looping over and over and over again.
It's saying it's digital height equals low.
No.
So it's not executing this line.
Now it's saying it's digital.
Read the three equals low.
Meaning is is the button connected to PIN number three connected or pressed.
It's not so it's not doing anything.
So now this loop is executing forever, but none of these conditions is satisfied.
This is why the last value of the motor was high, right?
Because we press the button.
We were inside this.
If it got executed, we release the button.
Now, we are not inside any statement and it's looping, waiting for a comment.
Now, let's say I press this button, then this line will be executed because digital with three now
is equals low meaning the stop button is pressed.
It means that I'm going to execute digital right low.
So the last executed action was low, meaning I'm sending low or zero volt to the motor.
It's a stopped and now we are looping forever again, waiting for a comment for a start.
This line is executed, this line for stop, this condition is satisfied, and the second line here
is executed.
OK, that's wonderful.
No, how about we start writing some statuses?
Like I want to write the status is that this murder is turned on and I want to write the status that
this model was turned off.
And I want to see it in the serial monitor right here how to do that.
Do you remember Serial that we have talked about?
We're going to use it now.
So stop simulation first and get ready to initialize some serial and we're going to do that in the next
lecture.