![]() ![]() We’ll start our if statement with a ‘hashtag’ or ‘octothorp’. The preprocessor directive we’ll be talking about is the “if statement”. And you can run some directives that allow some of the code to be included and some of it not to be included. A preprocessor is something that runs on your program, on your sketch, before it actually gets compiled. Now, there’s also a third way to comment out multiple lines of code using a preprocessor directive. Important note: we cannot use the keyboard shortcut to comment out multi-line comments. Now, there is another way to comment out several lines of code, and that’s to use a multi-line comment.īy using both a forward slash & asterisk between any amount of code, we can comment out anything in between. To uncomment the selected lines, simply press it again and it will toggle back off. After placing your cursor at the beginning of the desired line, press Control + Forward Slash on a PC, and it’s Command + Forward Slash on a Mac. There is also a keyboard shortcut for doing this. You can also select an entire code block and go up to Edit, Comment/Uncomment. Now, another way to add the same forward slash is to first put your cursor where you want to comment out some code, go up to Edit, and then click Comment/Uncomment. So this is effectively a way to turn off a line of code. And what this means is that this line of code is not gonna be verified when we verify it, or it’s not gonna get included when we upload it either. These two forward slashes are called a comment, and you’ll notice all of the text, all the code after that line get grayed out. What do we do? Well, I just put two forward slashes in front of the line. We simply want to temporarily turn off a line of code. So let’s say we have a line of code that we don’t want included in the program when it gets uploaded. This sketch will help demonstrate what it means to comment out different blocks of code. The program is walking through an array of pin numbers, and then it is turning on each of the LEDs attached to those pin numbers, in a back-and-forth method. So we have a sketch up in Arduino IDE and we’re using the kit-on-a-shield to light up some LEDs. By the end of this lesson, you’ll be equipped to comment out code in three different ways. They’re all super easy, and you’re gonna have them down pat, in no time. In this lesson, we’re gonna cover three different ways to comment out code in your Arduino programs. That’s when you selectively turn off some of the code in your program. What does that mean exactly? Now, I’m not talking about ‘ commenting code‘. See below for a lesson and video explanation of 3 quick and helpful ways to comment OUT code in the Arduino IDE.Ĭommenting out code. ![]()
0 Comments
Leave a Reply. |