Arduino The Delay Command

Pin 13, which Im going to emphasize pin 13 is actually the the tiny little LED on the board. Thats built in that doesnt require you to buy any extra parts to to run an LED. We will be going over that in a next video about putting some parts together to make an LED turn on and turn off, but this one is using just the built in LED thats on the board, and I will show you what that looks like. You will see it in action so to review. We have the programmer you with the program code, we wrote, we have we, I remember we were discussing the setup and the loop and then we have the pin mode and when you say the pin mode you its always going to ask which pin, which is 13, That is the the built in LED thats on the board, and then it has output which it sends it to. It, makes it become an output to make it right here, high or low, and this is how you send a command to that. Pin you send digital right, pin 13 low or pin 13 high okay, so right now we have it on low. So the way you send this code to the Arduino is you hit this arrow and it says upload as you notice what it says: upload right next to it so Im going to click that and youll see some messages down here: okay, Im going to okay Im Going to click upload – and you will see some messages down here – okay, so its sent it to the board and I have a camera on the board.

You will see that there is no LED thats on so in review. Im going to change this to high hig H and going to change that to high okay and then Im going to send that to the Arduino okay, and now you see on our board camera our board cam. You see that the LED is now on. Okay, now Im going to put it on low to turn it off and Im going to upload it, which means Im gon na, send this code to the Arduino board. I do that and now you notice on our board cam. The LED is off now theres. Something interesting we can add, lets add a little variation to this without any without adding extra any extra parts lets add a variation to it. Lets say we want a go lets say we want to turn it on for a certain amount of time and then turn it off for a certain amount of time. So we want it to almost like a flash. Okay, there was another command I want to introduce. You to which is called the delay command, so what we will do is were going to turn it on then a delay and then turn it off and then theres a delay. Now remember this is a loop, so this will go over and over and over again. Okay and well demonstrate this: when we run this youll see it on our Arduino board, cam. Okay, so lets say we turn the LED on which is which command? Yes, its the high command.

So we put, we turn that on high okay, then we put this neat little command called delay. Now delay is interesting. Its in thousands, so 1000 is actually one second, its in milliseconds and then Im to put a comment like I showed you here. This is a delay for one second, okay, now theres a delay, and I want to turn it off. So I type digital write, 13, comma. And what do we lose? What do we use to turn it off? We use thats right low and this it helps to capitalize the W there we go, so it changes color that that way we have the command right. So we have at hi theres a delay for one. Second, then it turns theres a delay. Then it turns off. Okay, now before it turns on again, I remember this is a loop. It goes over and over again lets do another delay, okay for one second, which is a thousand and Im going to put a note, delay to turn led on again okay. So we have the lets do this in order, because this is a loop okay. So we have, it turns on okay pin 13: it stays on for one second, then it turns off and then it waits for one. Second, then it goes back to here. Then it turns on again, okay program. Writing is like a set of instructions. If youve ever followed to make a recipe, you have to follow the steps.

The neat thing about programming well the same with a recipe when at the bottom of the recipe is has repeat for to make more cupcakes. You repeat the same process same with programming, you use the word loop so remember. I said in the last video in between these braces all this code will, over and over and over again forever as long as you power that Arduino. So the first part is digital right, pin 13 hi a delay for one. Second, then, digital right, the same pan low, which is off Im, actually gon na put some comments here. This is good practice, turn off pinned there team, which is the LED okay and then it will delay. Then it goes back to the top again in a review. You have to set the pin mode 13 to an output, okay, so lets this is the exciting part lets send this code to the Arduino so Im going to hit this arrow, where it sit and youll see the thing that says upload, and then we have our Arduino board cam on so Im sending that over and look at that. One second see you have a flashing LED. Okay lets do a change to this. This is really fun. What you can do with this lets. Try a two second delay, so everything, like I said, is in thousands the trick to this. I always read when Im debugging coda was whenever I see delay. I look at that.

First number thats going to be two seconds because everything like I said its in milliseconds. Okay, so Im going to send this code to the Arduino and youll see a difference in the delay now youll see it stay on longer, so at two seconds: okay and then youre thinking how to do a half second well, remember we had 1000 for both of These Im going to set them back, okay, that was for one second, just dividing in half 500 thats, half a second okay. There we go so we have 500 lets, send this to the Arduino and you can look at it on the we know cam. Here we go now wait. A half second lets go even smaller. Well set this well keep doing these by half 250. Ok! So Im going to send this to the Arduino there we go its starting to flash faster and faster, as you notice now Im going to set this at 100 whoops. There we go so now. You understand the simple thing about delays. Ok, so Im going to upload this or send it to the chip there we go see now its blinking really fast. So now you understand this basic idea of a new command called the the delay function and in review this turns this tells the pin that is going to be an output. This is the pin 13 youre saying digital right, which means telling pin 13 to go on or high a delay.

I can set this back to a thousand for our original code, so it delays for one. Second, then, it tells pin 13 to turn off to go to low, and then it goes back to a delay. Now before we go Im going to send us back to the adrenal board and there we go now were back to 1 second delay. I will be posting more videos. We will be covering a lot of Arduino and Raspberry Pi, also on simple programming, and I also want to introduce you to how to hook up parts to the Arduino board, so we can run multiple LEDs. Its a lot of fun. Remember to click on the subscribe button and have fun. Definitely Arduino is a lot of fun. These are all very, very fun and very, very good.

Share.
Exit mobile version