filmov
tv
How to Organize Code
Показать описание
🤩 FREE Arduino Crash Course 👇👇
***Want to learn more? Check out our courses!***
***Get your Free Trial of Altium PCB design Software***
Arduino Sketch Build Process Website:
***Get the code, transcript, challenges, etc for this lesson on our website***
***We designed this circuit board for beginners!***
FOLLOW US ELSEWHERE
---------------------------------------------------
________________________________
If you are new to writing code with Arduino it can be confusing on how to organize the program. But once you know where stuff goes in an Arduino program it's actually pretty simple. In this lesson, you are gonna learn how to organize the key components of an Arduino sketch like includes, define, constants, global variables, functions, setup and loop. Let's dive in. All right, so here I am in the Arduino IDE and it doesn't matter which IDE you're using. You could be in the online, editor or maybe you're in the Arduino 2.0 IDE. It really doesn't matter or maybe you're in VS Code. It doesn't matter where you're programming this stuff. It's all gonna be the same as far as this organization goes. Okay, so we open up a new sketch and what Arduino does is it pre-populates two functions in here. It gives a setup and loop. We're gonna visit these later but right now I'm just gonna go ahead and delete that 'cause what I wanna do is start from just a blank slate. All right, so what I'm gonna do just in comments is kind of list out all the stuff in the order that we're gonna want it generally. All right, so here's the basic order, now of course every rule has exceptions and this is definitely a rule that has exceptions, but here's the rough order we wanna lay stuff out in an Arduino sketch. First you're gonna start off with including libraries. So if you have any libraries that you're using with your sketch, putting them at the very top is generally where you're gonna see them. So an easy way to include a library is just to go up to sketch, include library and then select the library you want to include. I'll use FastLED for this example and you'll see it just inserts this line include and then the name of the library right at the top. So I'll just go ahead and move this down to where I've got the comment. Of course, we could always just write this out on our own. The nice thing about using the shortcut up in sketch with the included library is that you know you're not gonna make any spelling errors. And as simple as that might be sometimes a spelling error can throw you for a loop for a little bit. All right, so you wanna include your libraries at the very top of the sketch. So the next thing you'll want after you include the libraries is to add your constants and any defines. And also you'll wanna have your global variables. Now you can have these intermingles, so you might have a constant and then you could hav
CONTINUED...
***About Us:***
This Arduino lesson was created by Programming Electronics Academy. We are an online education company who seeks to help people learn about electronics and programming through the ubiquitous Arduino development board.
***We have no affiliation whatsoever with Arduino LLC, other than we think they are cool.***
***Want to learn more? Check out our courses!***
***Get your Free Trial of Altium PCB design Software***
Arduino Sketch Build Process Website:
***Get the code, transcript, challenges, etc for this lesson on our website***
***We designed this circuit board for beginners!***
FOLLOW US ELSEWHERE
---------------------------------------------------
________________________________
If you are new to writing code with Arduino it can be confusing on how to organize the program. But once you know where stuff goes in an Arduino program it's actually pretty simple. In this lesson, you are gonna learn how to organize the key components of an Arduino sketch like includes, define, constants, global variables, functions, setup and loop. Let's dive in. All right, so here I am in the Arduino IDE and it doesn't matter which IDE you're using. You could be in the online, editor or maybe you're in the Arduino 2.0 IDE. It really doesn't matter or maybe you're in VS Code. It doesn't matter where you're programming this stuff. It's all gonna be the same as far as this organization goes. Okay, so we open up a new sketch and what Arduino does is it pre-populates two functions in here. It gives a setup and loop. We're gonna visit these later but right now I'm just gonna go ahead and delete that 'cause what I wanna do is start from just a blank slate. All right, so what I'm gonna do just in comments is kind of list out all the stuff in the order that we're gonna want it generally. All right, so here's the basic order, now of course every rule has exceptions and this is definitely a rule that has exceptions, but here's the rough order we wanna lay stuff out in an Arduino sketch. First you're gonna start off with including libraries. So if you have any libraries that you're using with your sketch, putting them at the very top is generally where you're gonna see them. So an easy way to include a library is just to go up to sketch, include library and then select the library you want to include. I'll use FastLED for this example and you'll see it just inserts this line include and then the name of the library right at the top. So I'll just go ahead and move this down to where I've got the comment. Of course, we could always just write this out on our own. The nice thing about using the shortcut up in sketch with the included library is that you know you're not gonna make any spelling errors. And as simple as that might be sometimes a spelling error can throw you for a loop for a little bit. All right, so you wanna include your libraries at the very top of the sketch. So the next thing you'll want after you include the libraries is to add your constants and any defines. And also you'll wanna have your global variables. Now you can have these intermingles, so you might have a constant and then you could hav
CONTINUED...
***About Us:***
This Arduino lesson was created by Programming Electronics Academy. We are an online education company who seeks to help people learn about electronics and programming through the ubiquitous Arduino development board.
***We have no affiliation whatsoever with Arduino LLC, other than we think they are cool.***
Комментарии