if else statement | switch case statement in Arduino Programming

Поділитися
Вставка
  • Опубліковано 1 гру 2024

КОМЕНТАРІ •

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

    Thanks, great tutorial 🙏 just wondering if you would give a private lesson (online) I’m more than happy to pay, just need some help with something I’m stuck on

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

    Great tutorial thanks… would you give a private lesson (online)? More than happy to pay… just need some help with a code, cheers

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

    I have a question! I tried putting a “delay” in one of my cases. “Case 3: LED1 HIGH delay LED2 HIGH” and it kept looping that one case. The LED stopped reacting to the button I was using. So once I got to that case it kept going LED1 high LED2 high LED1 high LED2 high…. And so on. Can you help me?

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

    👍👍👍👍👍

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

    There is no reason to set Led_Counter to 0 in your default case or the final else statement. You do that at the start of the loop, so this is redundant code. Also, this code does not match your flow diagram. The flow diagram specifies a check for Led_Counter = 3, and only if not then turn off the leds. A niggling point, I grant you, but software development is about precision. Not writing code to match the specs leads to design flaws and less manageable code. Other than that, nice explanation of if/else vs switch.

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

      Hello Michael, I really appreciate your both points you have noticed in this video. The first point to set Led_Counter to 0 in default case or the final else statement is needed. Reason for that is Led_Counter is a static variable, that means it just initializes once with 0 at the start of the loop and then never reinitializes during the runtime. Which means it is needed to reinitialize somewhere in the code at proper place. The second point I agree with you that in the code I specified a check for Led_Counter = 3 but I have used only else instead. The reason for that it is always recommended to use an else case when using if...else if structure. If I would have use else if (Led_Counter == 3) instead then else statement would have been empty with no code inside. Just to avoid this I have used else instead of comparing Led_Counter with 3 :)

  • @harikrishnanelec
    @harikrishnanelec 6 місяців тому

    Confusing

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

    I have a question! I tried putting a “delay” in one of my cases. “Case 3: LED1 HIGH delay LED2 HIGH” and it kept looping that one case. The LED stopped reacting to the button I was using. So once I got to that case it kept going LED1 high LED2 high LED1 high LED2 high…. And so on. Can you help me?

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

      It looks like switch cases are not getting changed. That means when Case 3 is active then it is not switching to Case 1, Case 2, or default if available. When you don't see any reaction of button, I guess you are using delay inside your Case 3 and if you press the button within this delay then it will not get detected. That mostly happens because software is blocked by the delay API and at that time button press would not be detected at all.
      If you send me your code, maybe I can help you bit more. All of my answers are totally depending on my assumptions and the problems that I have experienced in programming. Best of luck.

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

      @@learnembedded4future532 Thank you! I'd love to send you my code. How do I do that?
      My project is for a theatre play that goes in premiere this weekend, so I'd love to get your help

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

      @@learnembedded4future532 can I mail you perhaps?

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

      Yes please do that

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

      @@learnembedded4future532 what mailadres can I use?