Arduino Code: Conditional Statements

Поделиться
HTML-код
  • Опубликовано: 26 окт 2024

Комментарии • 32

  • @haqnmaq
    @haqnmaq 7 лет назад +8

    This is one of my favorite tutorial series! Most arduino tutorials aren't as in depth with the programming side of things. They usually only tell you what to write (i.e. pinMode (led,OUTPUT);) , but not the reason for writing it, which is crucial for actually learning something! Please keep making these!

    • @shawnhymel7647
      @shawnhymel7647 7 лет назад +3

      Glad you like it! The programming series don't seem to be as popular as the electronics ones, but I agree with you in that many "Arduino tutorials" out there just have you copy code without going in-depth into what's really going on. Once I get enough of them done, I'm hoping to turn it into a kind of course with homework problems and exercises.

  • @baldendoboriqua6391
    @baldendoboriqua6391 4 года назад

    the code for your challenge at the end.. lol i figured it out on my own :) kinda sorta, i did google "delay statement example" . but it was very satisfying knowing that i got it right considering im a beginner.. haha
    const int Buttonpin = 7;
    const int LedPin = 13;

    void setup() {
    pinMode(Buttonpin, INPUT_PULLUP);
    pinMode(LedPin, OUTPUT);

    }
    void loop() {
    if ( digitalRead(Buttonpin) == LOW){
    digitalWrite(13, HIGH);
    delay(500);
    digitalWrite(13, LOW);
    delay(500);

    }
    }

  • @shubhamgupta4237
    @shubhamgupta4237 6 лет назад +1

    i really enjoy your videos and learning new codes everytime

  • @jessebro599
    @jessebro599 3 года назад +1

    Good summary. However, you have a mistake. In your flow chart describing "do something if true" and "do something else if false", that is not the case. There is simply, "do something if true", and then it will continue along in the code. If the condition is false, then it will skip that code and do whatever is outside of the if. If you have a separate "else" after the "if", then it is a different matter.
    Don't worry though, this is a good video so don't beat yourself up about it.

    • @jessebro599
      @jessebro599 3 года назад

      At least, that's how it is in Python. Not sure about Arduino code (C++, I think)

  • @shaneferdz82
    @shaneferdz82 2 года назад

    Can I have a choice of two codes based on the push of a button. For eg button on runs a obstacle avoiding car code and button off switches it to a Bluetooth controlled car

  • @SanjaySharma-pw6ww
    @SanjaySharma-pw6ww Год назад

    sir pls suggest the codes i want to write a code if switch1 is followed by switch2 then increment the count and if switch2 is followed by switch1 decrement the count.

  • @thelazycat_
    @thelazycat_ 2 года назад

    I don't know why but my LED stays on, when I press the button it goes off

  • @HappyHermitt
    @HappyHermitt Год назад

    Thank you sir

  • @taranagnew436
    @taranagnew436 6 лет назад

    i have a LCD keypad shield and i want to be able to press the select button on the LCD keypad shield to be able to generate random numbers, the problem i have is when i upload the code to the arduino it says "error compiling" plz help

  • @tetsujin_144
    @tetsujin_144 7 лет назад

    Just in case the whole deal with "if (x = y)" wasn't confusing enough, the programming world has decided to compound the problem by introducing conventions like "if (3 == x)"... Which serves to make code more confusing (why would anyone need to ask what 3 is equal to?) and doesn't even solve the problem it was made to address (what happens if both terms are variables?)

    • @starcitizenmodding4436
      @starcitizenmodding4436 7 лет назад

      i see where your going with this. it was ok to have a double == but get confusing if you add a if statement to it lol.
      Confusing for a person that is. The computer dont see the problem with thinking the same thing twice but its a bit of a mind funk for us :D

    • @tetsujin_144
      @tetsujin_144 7 лет назад

      It doesn't solve the problem *except* in the case where one of the two is a constant. But if you're depending on a compilation failure to tell you whether you used assignment when you should have used comparison, you're screwed. Compiler can't save your ass if you ask it for "if (x = y)"....
      My real problem with it is that when you read it, it sounds totally backwards. "Is blue the sky?" "Is fat yo' momma?" It's like Yoda-speak, at least if you're starting from English. And "is 5 x?" is further from the real question than "is x 5?" - because 5 is never anything other than 5, while (x) is potentially unknown. It makes more sense to ask about the unknown than about the constant.
      I hate the whole idea of expressing all my tests *backwards* just because some amateur programmers found it helped them to navigate an inherently confusing aspect of C/C++ in their intro to programming class. That is a real dumb reason to enshrine a thing like that as a standard coding practice.

    • @tetsujin_144
      @tetsujin_144 7 лет назад

      The "problem" this is supposed to solve is the confusion between the assignment operator "=" and the comparison operator "=="
      How is that problem any less of a problem when neither of the operands is a constant? If you meant to write "if (x == y)" and you wrote "if (x = y)" then your test is wrong and the value of (x) is lost.
      What I want is not impossible. What I want is to point out that the only problem this (3 == x) convention solves is one that competent programmers shouldn't be affected by anyway - and if they are so affected, it just creates another pitfall: if you rely on a convention like this to keep you out of trouble, then you're in worse trouble when you come upon a situation where the convention doesn't apply.
      More broadly speaking, the underlying issue this backward-ass convention can be addressed in the language design (i.e. don't allow variable modification in conditional expressions) - but since we're already stuck with it in C++ the best we could do
      Personally, I'd say that if you've got side-effects in a "while()" condition, that's bad coding practice. Use a for-loop or something, that's what it's for.

  • @ebrahimbahboodi3609
    @ebrahimbahboodi3609 5 лет назад

    good day,
    kindly could help me in how can I interface arduino with 2 flame sensors and with 1 buzzer? and I need flame sensors check every 30 seconds when there’s fire did fire extinguish?
    In same time I need to put range for both sensors.
    Thank you

  • @rashaan64
    @rashaan64 6 лет назад

    What about multiple if statements that do different things

  • @rbsinghadcocate3777
    @rbsinghadcocate3777 3 года назад

    Conditional statements cannot be used in Arduino programming. yes/no

  • @lightsnsiren79
    @lightsnsiren79 2 года назад

    "Printing out yes or no answers as ones or zeros is great fun and all, but..." :D

  • @AviRotstein
    @AviRotstein 7 лет назад

    5:03 didn't you mean it assigns the value in a to b?

    • @starcitizenmodding4436
      @starcitizenmodding4436 7 лет назад

      He did. a equals b.

    • @tetsujin_144
      @tetsujin_144 7 лет назад

      No. The value comes from (b). That value is then assigned to (a). Thus, "It assigns the value in b to (the variable) a"
      To look at it another way, (b) is a variable. But if you're talking about "the value in b" - that's a number. You can't change or assign the value of a number. When speaking about an assignment involving a variable and a value, we know which one is changing.
      I get where you're coming from, though. To me Shawn's statement is perfectly clear and unambiguous. But I can see where it gets confusing. Grammatically I think "assign 3 to x" is probably correct but in my mind "assign x to 3" comes more naturally...

    • @starcitizenmodding4436
      @starcitizenmodding4436 7 лет назад

      Tetsujin lol! yea you are right :D. it just proves how it doesn't feel intuitive to think like a computer.
      Its good to realise the subtleties thanks. im a beginner in my defence ;)

    • @starcitizenmodding4436
      @starcitizenmodding4436 7 лет назад

      i can effectively use it... i just imagined in my head wrong.
      a is now the value of b.
      This is how i simply imagined it and it works for me.

    • @AviRotstein
      @AviRotstein 7 лет назад +1

      yes, the value of B, is copied into the variable A. Just wasn't the best grammatically.

  • @sylgonjaysanoy8890
    @sylgonjaysanoy8890 Год назад

    if ((msg [0] == 111) != (msg [0] == 222)) can you explain these?

  • @attalaw36
    @attalaw36 4 года назад

    thank you

  • @Viterlin
    @Viterlin 5 лет назад

    Can you create a video of code for wifi vending machine please

  • @ahmetasantas7099
    @ahmetasantas7099 7 лет назад

    great video!

  • @atomsjosh8878
    @atomsjosh8878 4 года назад

    Happy Hacking!
    Me: WHAT!