Using Arrays with For Loops

🤩 How much Arduino can you learn in 7 Days? 👇
bit.ly/7_Day_Arduino_Challenge
**Want to learn more? Check out our courses!**
bit.ly/3EMCjCy
**Get your Free Trial of Altium PCB design Software**
www.altium.com/yt/programming...
**Get the code, transcript, challenges, etc for this lesson on our website**
bit.ly/3ref0Nv
**We designed this circuit board for beginners!**
Kit-On-A-Shield: amzn.to/3lfWClU
FOLLOW US ELSEWHERE
---------------------------------------------------
Facebook: / programmingelectronics...
Twitter: / progelecacademy
Website: www.programmingelectronics.com/
________________________________
I would say that arrays are one of the most useful programming tools available. Every programming language that I'm familiar with, at least, has some form of an array. If you're trying to learn a new programming language, one of the things I would recommend is to get familiar with how to write and manipulate data in arrays. Like, if I was gonna learn a spoken language, like Russian, I'd want to prioritize learning the most common words and phrases first. Well, if I am learning a new programming language, I am gonna spend a ton of time learning how to use arrays in that language because they're just so fundamental. In this video, you're gonna learn how to go through, that is how to iterate through, an array in the Arduino programming language. If you can do it in the Arduino language, then you can also do it in the C and the C++ language. Knowing how to do this opens up a ton of useful possibilities for you as a programmer, and I'd argue, it's really an essential thing to learn about any programming language that you're interested in using. Stay tuned. Subscribe to our KZread channel to get more videos like this. All right, before I jump in, I just wanna say a huge shout out to Altium for sponsoring this video. If you check out the description, you can get our link to a free trial of their software. All right, so here we are in the Arduino IDE, and I'm gonna write a little bit of code, and then we're gonna talk about it. Basically, this is what I'm gonna do. I am gonna make an array and I'm gonna say, like, "you know what? This array is gonna be filled with sensor readings from some sensor," like maybe, maybe my device is getting a packet of information from some other device, right? And I have no control over that other device. I'm just getting a series of inputs from some other device, and so I'm gonna make an array that kind of, like, mocks out that input, and then what I'm gonna do is I'm gonna iterate through each one of those inputs, and then we'll print it out to the serial monitor. So let's do that. All right, so what have I got here? Well, the first thing I did is I created an array, and this is just like a mock-up array. It could be whatever, but this is an array that holds floating point values. The name is called sensorReadings and the size is four. That means it can hold a total of four values. It can never hold more than four. Like, the limit, the size, of this array is established when you first create it. So the size is four, and then I initialize it with four separate values. Now, you don't have to put in the values when you initialize it but in this case, I have. So I've got four floating point numbers that I initialized it with. Now, for this discussion, what's important for us is we understand, like, what the index of these numbers are. So let me just write that out above this, so we can get clearer. So the index value refers to the position of the element in the array. Now, if you're wondering like, "hey, what is this index thing?
CONTINUED...
bit.ly/3ref0Nv
**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.**

Пікірлер: 47

  • @Cor_Netto
    @Cor_Netto2 жыл бұрын

    Outstanding explanation!

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Glad it was helpful! Thank you!

  • @ChadKapper
    @ChadKapper2 жыл бұрын

    Every video is better than the previous! You do such a good job of helping me discover the value in the details.

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Thanks Chad! Much appreciated!

  • @warrenstaben6166
    @warrenstaben61662 жыл бұрын

    Thank you so much. Your videos are so well done and easy to understand!

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Thanks for watching - I am glad it's helpful!

  • @KW-ei3pi
    @KW-ei3pi2 ай бұрын

    Thanks! Very good tutorial. You went through the last part pretty quickly, and I couldn't figure out why "now" didn't print on the second and subsequent loops. It wasn't entirely clear that the INDEX values were in memory and could be overwritten by code to a new value. I get it now. Thanks. Regards.

  • @maggotdude667
    @maggotdude6672 жыл бұрын

    You break down information so well! I really appreciate these videos.

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Thanks so much for the note! Much appreciated! If there is any info in particular you are looking to learn about, please feel free to let us know and we'll try and make a video on it.

  • @maggotdude667

    @maggotdude667

    2 жыл бұрын

    @@programmingelectronicsPerhaps interrupts/timer interrupts?

  • @interlightstudio1645
    @interlightstudio16452 жыл бұрын

    Been watching your vids since 2019. I Truly like the way you provide information.thank you

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    I appreciate that! Thank you!

  • @IngeBall
    @IngeBall Жыл бұрын

    This is golden (as is the whole series) Subbed!

  • @programmingelectronics

    @programmingelectronics

    Жыл бұрын

    Glad you like it!

  • @thomashvnmusic
    @thomashvnmusic2 жыл бұрын

    This is really good, thanks!!!

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Thanks a ton for watching! I hope it was helpful!

  • @thomashvnmusic

    @thomashvnmusic

    2 жыл бұрын

    @@programmingelectronics Im probably one of the oldest fans on the channel. I followed your channel about 8 years now and i remember the first videos you posted when you were drawing and explaining the micro-controller pins on paper. Was a fan back then, still a fan.

  • @michaelcheich2481

    @michaelcheich2481

    2 жыл бұрын

    @@thomashvnmusic Thanks for sticking around!!!

  • @thomashvnmusic

    @thomashvnmusic

    2 жыл бұрын

    @@michaelcheich2481 Absolutely!

  • @warrenscorner
    @warrenscorner2 жыл бұрын

    That was a great tutorial of a for loop! 😂 Maybe part 2 can explain how to append an array or what types of variables can go into an array.

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Thanks for the note and recommendation Warren! In retrospect I can see this is more a "for loop video" than an "array video" We changed up the title and thumbnail to hopefully reflect that better.

  • @user-gw1pj7fh7q
    @user-gw1pj7fh7q5 ай бұрын

    Вы большой молодец , что делаете такие обучающие видео , спасибо большое !

  • @MarkATrombley
    @MarkATrombley2 жыл бұрын

    At 16:30 why is the first line of output messed up? It happened on the other examples too.

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Great question and nice observation Mark! I am sure some out there could explain this (and I would love to know as well), but I _think_ it has to do with the Serial Monitor reseting the Arduino when it is opened.

  • @joshuapitong899
    @joshuapitong899 Жыл бұрын

    Really helpful.🙌

  • @programmingelectronics

    @programmingelectronics

    Жыл бұрын

    Great to hear! Thank you!

  • @AbrarShaikh2741
    @AbrarShaikh27412 жыл бұрын

    Thanks for the video. However, it is more lf a FOR loop video then Array Video.

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    You are right! Title adjusted, and I think we'll change out to a more representative thumbnail. Thanks @Abrar!

  • @Bianchi77
    @Bianchi772 жыл бұрын

    Nice info, keep it up,thanks for sharing :)

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Thanks for the note!!

  • @syaduinotech3681
    @syaduinotech36812 жыл бұрын

    Thanks for the video, hope you can share the application of using this on the sensor as you mention in the beginning. Tq sir

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Thanks for watching!

  • @miroslavmikus6480
    @miroslavmikus64802 жыл бұрын

    If you don't need to know index i, you can use range based for loop: for (float val : sensorReadings) { } ; plus with another feature of c++11 "auto": for (auto val : sensorReadings) { Serial.println(val); } - less you have to write mans less bugs you can make

  • @joroxanborata3102
    @joroxanborata31022 жыл бұрын

    hi thanks you for the informative about arduino can you make a video to combine 3 sketch that have different doing. like relay lighting , automatic water, and a dht11 sensor

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Thanks for the note! I'll see what we can come up with for you!

  • @sagardebnath1102
    @sagardebnath11025 ай бұрын

    How to iterate array with millis() function or iterate through multiple arrays simultaneously

  • @ianclaproth3675
    @ianclaproth36756 ай бұрын

    An excellent explanation of how the for loop actually works when iterating arrays. Thank you.

  • @programmingelectronics

    @programmingelectronics

    6 ай бұрын

    Thanks so much for watching!

  • @TheStudpop
    @TheStudpop2 жыл бұрын

    Seems to me that i = 0 gets incremented before the next line, so the array’s index will never be 0 but rather 1,2,3.

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    I may have not explained it appropriately in the video, but when _entering_ a "for loop", the variable gets initialized and the condition is checked. The increment/decrement happens at the end of the for loop before the next check of the condition. 1st-> initialize var, check condition n...-> increment/decrement, check condition Hope this helps clarify!

  • @TheStudpop

    @TheStudpop

    2 жыл бұрын

    @@programmingelectronics You're the best! Thanks.

  • @LilGh02t

    @LilGh02t

    2 жыл бұрын

    The '++' operator increments the variable. If it's placed after (i++), the variable will be incremented after the code in the loop is executed, if the operator is placed before the variable (++i), the variable is incremented before entering the loop. Same rules applies to the '- -' operator.

  • @Mica_No
    @Mica_No2 жыл бұрын

    Its so entertaining listen to you

  • @programmingelectronics

    @programmingelectronics

    2 жыл бұрын

    Thanks so much for watching!

  • @j.w.8663
    @j.w.86637 ай бұрын

    👍🏻

  • @frankbaron1608
    @frankbaron1608 Жыл бұрын

    hip, hip, array

  • @flywittzbeats4008
    @flywittzbeats4008 Жыл бұрын

    char bestTeachers [][3] = {{“Programming Electronics Academy”}, {“Brocode”}, {“Paul McWhorter”}};