Arduino MASTERCLASS | How to Use Control Structures PART 6

แชร์
ฝัง
  • เผยแพร่เมื่อ 20 ก.ย. 2024
  • 🤩 FREE Arduino Crash Course 👇👇
    bit.ly/get_Ard...
    **Want to have some fun programming your own electronics?**
    bit.ly/3OU3XDt
    **Get the code, transcript, challenges, etc for this lesson on our website**
    bit.ly/3zWxN5X
    **We designed this circuit board for beginners!**
    Kit-On-A-Shield: amzn.to/3lfWClU
    FOLLOW US ELSEWHERE
    ---------------------------------------------------
    Facebook: / programmingelectronics...
    Twitter: / progelecacademy
    Website: www.programmin...
    ________________________________
    Arduino is a great tool for controlling electronic stuff like sensors and motors. But if you wanna build logic into your Arduino program, then you need to understand how to use control structures in your code. In this lesson, we are gonna go rapid fire over several super useful control structures, probably the most important ones. By the end of this lesson, you're gonna have an understanding of how they work and how to use them. Let's go.
    Now this video is part of a series and where we left off was talking about variables. So if you haven't already, I highly recommend after you watch this video, going back and watching the previous lessons. So far, we've talked about how every Arduino program is laid out, then we talked about using variables we've gone over a little variable example. We sprinkled in a couple of these most important Arduino specific functions, namely pinMode and analogWrite. But now we're gonna start talking about these control structures. What is a control structure? A control structure allows you to adjust the flow of your code. If we go to the Arduino Reference page and we go to Structure, when I'm talking about control structures, I'm talking about these right here. So we have an if statement, fors, else, whiles, switch cases. These are the control structures that are going to allow you to have your code do different things depending on different circumstances. So let's go back to that code and we'll see we have this if statement, so this is some control code and notice it's followed by an opening and a closing parenthesis and inside this is called our condition. So if statements have a condition. If the condition evaluates to true, then the code inside the curly braces gets run. If the condition evaluates to false, then all the code in here just gets skipped over. So you only do the stuff inside the curly braces of an if statement if this is true. Now you might be looking at this and being like, "Wait, what is going on here?" Well, we've got two things going on. So this right here is actually an or symbol. So this condition is saying if the brightness variable is less than or equal to zero, or if the brightness variable is greater than or equal to 255, then do something. So, well, why don't we just evaluate? Let's pretend we're the Arduino and let's evaluate this. So what did we say? We said brightness was five. So if brightness is five, is five less than or equal to zero? Nope, it's not. Is five greater than or equal to 255? Nope, it's not. So that means we're just gonna skip over this line of code right here, the first time through the loop. So we've controlled our code flow, because we haven't used this based on a condition. So then we get to this next line of code and it says delay 30. Here's another one of those super important Arduino functions that you'll learn to love and hate. It's called delay and what it does is it stops the program in its tracks. No other code will run for the amount of time you put in here and this time is in milliseconds. So for 30 milliseconds, we're gonna say, "Stop. Don't do anything, Arduino board." And when we say, "Stop, don't do anything," what we're saying is, "Don't execute any more code," because what we did up here on line 13, when we PWM-ed pin nine to a value of zero, that means the LED was off, there's no brightness there and we're just gonna hold that position. So delay is like, "Hold it, hold it. Okay, go." That's what's going on here. So after the delay, we get to this final curly brace. Here's the end of this loop function and what do we do? We start back up at the top. So we're back at the top. We run into our friendly function, analogWrite, again, using the PWM feature of the microcontroller and what is brightness this time? Well, if you recall last time through, we changed brightness to five.
    CONTINUED...
    bit.ly/3zWxN5X
    **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.**

ความคิดเห็น • 43

  • @clems6989
    @clems6989 หลายเดือนก่อน +1

    This video is absolutely the best "overview" description of the Arduino operations that I have ever seen. Thank you so much for this excellent explanation !!

  • @briancampbell5685
    @briancampbell5685 2 ปีที่แล้ว +4

    Watch the episode "Variables" first as this episode is the follow on. After watching a few episodes from this Tutor I will be purchasing the complete course. The Tutor's way of teaching is so easy to follow, clear, concise and expert. Nothing on TH-cam has the equivalent of teaching in the right sequence of steps that is easy to understand. I found programming not only the Arduino but as an introduction to all programming languages this is the place to start. To learn how to logically program microcontrollers (Arduino and more) this is the only one of real value. Brian Campbell (Bsc)

  • @J.T323
    @J.T323 2 ปีที่แล้ว +6

    Best beginners Arduino video's by far,excellent explanations on what things mean and what are some alternatives that may be used...thank you

  • @KW-ei3pi
    @KW-ei3pi 6 หลายเดือนก่อน +1

    Good day. Your channel is excellent for teaching Arduino programing and has greatly helped me get started. I've been able to build a Master Control Panel for controlling three Stepper Motors with three potentiometers, Forward and Reverse switches, and three Rotary Encoders for a fine feed adjustment of one thousandth of an inch on an industrial milling machine. So thank you very much! That being said, I have found the organization of videos somewhat difficult to navigate. There are several Playlists which is helpful, but naming conventions and Thumbnail titles are often different and confusing. For example, this video popped up and I started watching it, then decided to watch the other parts of the MASTERCLASS series, but it took me several minutes to find it and I almost gave up. The MASTERCLASS playlist is named "Learn Arduino in 90 Minnutes" (misspelling included) and the Thumbnail is "What can Arduino do?". So it was extremely hard to find. I wish all your Arduino videos were either in one Playlist that advances from beginner videos to advanced instruction, or in three Playlists for Beginner, Intermediate, and Advanced. Though to avoid covering the same subjects multiple times, I would prefer ONE Playlist. I hope this is of some help to you. Regards.

  • @patdowling5
    @patdowling5 2 ปีที่แล้ว +1

    Thanks for this video, I really got a lot out of it and the previous one, has really hwlped my understanding here. You have a fantastic teaching style ! Greetings from Ireland

  • @joshuapitong899
    @joshuapitong899 2 ปีที่แล้ว +1

    Really really Great!🙌 A lot of thanks Programming Electronics Academy.❤🙏

  • @tb303wpf1
    @tb303wpf1 ปีที่แล้ว +1

    I'm having a bit of trouble using a switch case to do 2 functions based on one of 2 buttons being pressed. I see how you used it here with an analog input range. I'm just using whether one of the two buttons is pressed. Should I use the map command to create 2 values for 2 cases?
    I'm sure your a super busy guy so if you don't respond I won't take it personally.
    Overall thank you so much for this super useful information. You're a great instructor!

  • @chrisl2807
    @chrisl2807 9 หลายเดือนก่อน +1

    ust came across this. Great vid that explained a few things that seem to be assumed and get glossed over. Thanks

  • @joeclone2686
    @joeclone2686 2 ปีที่แล้ว +1

    Subscribed, building up to be a nice series. I'm just starting out learning simple arduino coding and just a massive mountain to climb with all the jumbled information on the net. Liking the way u present the info, thanks for the knowledge.

    • @programmingelectronics
      @programmingelectronics  2 ปีที่แล้ว

      Thanks so much Joe! You're right -it feels like a mountain starting out (and I don't think we ever get to the top) but after some work it's pretty fun what you can do with code and electronics. Best of luck!

  • @ianbertenshaw4350
    @ianbertenshaw4350 2 ปีที่แล้ว +1

    Yes Fantastic beginners video ! Ideally one would keep the global variables to a minimum so if you can move variables to the functions that will actually use them your code will be easier to read and more efficient .

  • @joeborovina4769
    @joeborovina4769 8 หลายเดือนก่อน

    excellent and need to watch again!

  • @AFacts0968
    @AFacts0968 ปีที่แล้ว

    Your videos are very nice and knowledgeable,, you explaining it well, thanks for making this kind of very informative videos you helping beginners a lot.

  • @diodeskies9087
    @diodeskies9087 2 ปีที่แล้ว +1

    That was an awesome explanation!

  • @LordPhobos6502
    @LordPhobos6502 2 ปีที่แล้ว +1

    Nice video :)
    Would love to see some more advanced stuff on how to make libraries as well 🙂❤

  • @ΜιλτιάδηςΠαντελαίος
    @ΜιλτιάδηςΠαντελαίος 2 ปีที่แล้ว +1

    The Programming Electronics Academy is the beter site for Arduino Programming Users in You Tube E V E R !!!

  • @Narendra_AI
    @Narendra_AI 3 หลายเดือนก่อน +1

    Ram ram Bhai Sare ane

  • @FourthWayRanch
    @FourthWayRanch ปีที่แล้ว +1

    what app is he using to make put the computer images onto video so clearly?

    • @programmingelectronics
      @programmingelectronics  ปีที่แล้ว

      Camtasia Studio

    • @FourthWayRanch
      @FourthWayRanch ปีที่แล้ว

      @@programmingelectronics LOL, YT won't even let me post a github link, the zensors have gone mad

  • @VirgilBruiners
    @VirgilBruiners ปีที่แล้ว

    Hi there ,I really like the video
    I need some help , I would like to run a few motors as well as sweep a servo using one push button from an Arduino Mega board. I have tried to make us of the if statement for when the button is down, and I have also tried making use if millis functions to separate the starting time of each component. If somebody could help me I would really appreciate it

  • @idlaw2k3
    @idlaw2k3 2 ปีที่แล้ว +1

    Excellent

  • @MrEnajiza
    @MrEnajiza 2 ปีที่แล้ว +1

  • @hussainabbas1341
    @hussainabbas1341 2 ปีที่แล้ว +1

    Thank You

  • @duller9430
    @duller9430 2 ปีที่แล้ว +1

    I found your book online do you think I should buy it I’ve been learning since February with elegoo super starter kit i did arduino stuff every day in February but I had to put Arduino aside the past few months due to school but did still stuff maybe every 1 week or 2 weeks i would do stuff but I have kind of forgotten how to right code now I understand the code I read but I can’t remember how to write stuff specifically so I have just been using the Arduino reference page and my old code I’ve written to help me write my code and have gotten on fine.What do u think I should do.
    Edit: Great work on series as well it’s really good

    • @programmingelectronics
      @programmingelectronics  2 ปีที่แล้ว +1

      Thanks Duller! I'd recommend checking out our courses at Programming Electronics Academy. If you sign up, you get the same ebook as part of the training program.
      Best of luck!

    • @duller9430
      @duller9430 2 ปีที่แล้ว +1

      @@programmingelectronics ok thanks

  • @AFacts0968
    @AFacts0968 ปีที่แล้ว

    Hai Can you make a video about a fingerprint Sensor with a voice module then it controlling something with a relay module 5volts. I you can make this I'm waiting, thank YOU, by the way I'm you fan from Philippines.

  • @Narendra_AI
    @Narendra_AI 3 หลายเดือนก่อน +1

    jai jagganath