Using Arrays with For Loops

Поділитися
Вставка
  • Опубліковано 13 січ 2022
  • 🤩 FREE Arduino Crash Course 👇👇
    bit.ly/get_Arduino_skills
    **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 UA-cam 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.**

КОМЕНТАРІ • 50

  • @aaronfidelisrecine
    @aaronfidelisrecine 24 дні тому +1

    MANNNNNN I've been losing my damn MIND trying to understand for loops and arrays and WOW you make it so easy! THANK YOU!!!!

  • @warrenstaben6166
    @warrenstaben6166 2 роки тому +7

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

  • @ChadKapper
    @ChadKapper 2 роки тому +3

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

  • @Cor_Netto
    @Cor_Netto 2 роки тому +3

    Outstanding explanation!

  • @interlightstudio1645
    @interlightstudio1645 2 роки тому +2

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

  • @KW-ei3pi
    @KW-ei3pi 4 місяці тому

    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
    @maggotdude667 2 роки тому +2

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

    • @programmingelectronics
      @programmingelectronics  2 роки тому +1

      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?

  • @warrenscorner
    @warrenscorner 2 роки тому +5

    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 роки тому +1

      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.

  • @IngeBall
    @IngeBall Рік тому +1

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

  • @MarkATrombley
    @MarkATrombley 2 роки тому +3

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

    • @programmingelectronics
      @programmingelectronics  2 роки тому +1

      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.

  • @user-gw1pj7fh7q
    @user-gw1pj7fh7q 7 місяців тому

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

  • @joshuapitong899
    @joshuapitong899 2 роки тому +1

    Really helpful.🙌

  • @Bianchi77
    @Bianchi77 2 роки тому +1

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

  • @thomashvnmusic
    @thomashvnmusic 2 роки тому +2

    This is really good, thanks!!!

    • @programmingelectronics
      @programmingelectronics  2 роки тому

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

    • @thomashvnmusic
      @thomashvnmusic 2 роки тому +1

      @@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 роки тому +1

      @@thomashvnmusic Thanks for sticking around!!!

    • @thomashvnmusic
      @thomashvnmusic 2 роки тому +1

      @@michaelcheich2481 Absolutely!

  • @AbrarShaikh2741
    @AbrarShaikh2741 2 роки тому +5

    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!

  • @syaduinotech3681
    @syaduinotech3681 2 роки тому +1

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

  • @miroslavmikus6480
    @miroslavmikus6480 2 роки тому

    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
    @joroxanborata3102 2 роки тому +2

    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

  • @ianclaproth3675
    @ianclaproth3675 8 місяців тому +1

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

  • @Skyrime007
    @Skyrime007 7 місяців тому

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

  • @TheStudpop
    @TheStudpop 2 роки тому +3

    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 роки тому +3

      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 роки тому +3

      @@programmingelectronics You're the best! Thanks.

    • @LilGh02t
      @LilGh02t 2 роки тому +3

      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.

  • @user-ue7gi4eg8u
    @user-ue7gi4eg8u Місяць тому

    god bless you

  • @j.w.8663
    @j.w.8663 9 місяців тому

    👍🏻

  • @Mica_No
    @Mica_No 2 роки тому +2

    Its so entertaining listen to you

  • @frankbaron1608
    @frankbaron1608 Рік тому

    hip, hip, array

  • @flywittzbeats4008
    @flywittzbeats4008 Рік тому

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