Arduino Code: Conditional Statements

  Рет қаралды 65,619

SparkFun Electronics

SparkFun Electronics

Күн бұрын

Пікірлер: 32
@haqnmaq
@haqnmaq 7 жыл бұрын
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 жыл бұрын
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 жыл бұрын
i really enjoy your videos and learning new codes everytime
@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.
@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
@ebrahimbahboodi3609
@ebrahimbahboodi3609 6 жыл бұрын
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
@thelazycat_
@thelazycat_ 3 жыл бұрын
I don't know why but my LED stays on, when I press the button it goes off
@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 жыл бұрын
yes, the value of B, is copied into the variable A. Just wasn't the best grammatically.
@rashaan64
@rashaan64 6 жыл бұрын
What about multiple if statements that do different things
@durgaramaniboddetti9882
@durgaramaniboddetti9882 5 жыл бұрын
s
@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.
@rbsinghadcocate3777
@rbsinghadcocate3777 4 жыл бұрын
Conditional statements cannot be used in Arduino programming. yes/no
@jessebro599
@jessebro599 3 жыл бұрын
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)
@lightsnsiren79
@lightsnsiren79 2 жыл бұрын
"Printing out yes or no answers as ones or zeros is great fun and all, but..." :D
@sylgonjaysanoy8890
@sylgonjaysanoy8890 Жыл бұрын
if ((msg [0] == 111) != (msg [0] == 222)) can you explain these?
@Viterlin
@Viterlin 5 жыл бұрын
Can you create a video of code for wifi vending machine please
@HappyHermitt
@HappyHermitt 2 жыл бұрын
Thank you sir
@attalaw36
@attalaw36 4 жыл бұрын
thank you
@atomsjosh8878
@atomsjosh8878 5 жыл бұрын
Happy Hacking! Me: WHAT!
@ahmetasantas7099
@ahmetasantas7099 7 жыл бұрын
great video!
Arduino Arithmetic Operators
8:51
SparkFun Electronics
Рет қаралды 46 М.
Level Up Your Arduino Code: External Interrupts
18:55
SparkFun Electronics
Рет қаралды 175 М.
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН
Arduino Tutorial 13: Understanding Arduino If Statements
36:51
Paul McWhorter
Рет қаралды 350 М.
How to Use Millis to Master Arduino Multi-tasking
50:17
Rachel De Barros
Рет қаралды 63 М.
Hacking a weird TV censoring device
20:59
Ben Eater
Рет қаралды 3,3 МЛН
Level Up Your Arduino Code: Registers
21:09
SparkFun Electronics
Рет қаралды 187 М.
Arduino Programming Syntax
9:15
SparkFun Electronics
Рет қаралды 242 М.
Arduino delay() and millis()  Functions: Tight Loops and Blocking Code
13:00
Programming Electronics Academy
Рет қаралды 104 М.
Arduino Lesson 5 - Boolean logic - OR & AND statements
13:17
Benduino
Рет қаралды 75 М.
When you have a very capricious child 😂😘👍
00:16
Like Asiya
Рет қаралды 18 МЛН