It is a name like we might make up the name ‘x’ and we might give it an initial value. So this is a totally reasonable variable. The integer x that you can’t exactly see cause inintelligible x, equals 100 let’s. This is crazy. I’M totally out of sync here, but let’s make a variable. Now that has a type boolean ‘going’ equals false. This is the type of the variable. It is not a number, it is not a string, it is not other types of variables that you may or may not have learned about. It is a boolean.. That means it only has one possible two possible values, true or false. You could use an integer in many ways and have the integer either be 0 for false or 1 for true, but there are many other numbers that piece of data could be in this case. The piece of data can only be false or true, and if you remember, a conditional statement is an expression. If some expression evaluates to true execute some code, guess what a boolean variable evaluates to true or false right. This boolean ‘going’ is false, so ‘if going’ meaning it’s, not we’re, not going to execute this code because ‘going’ is false.. But if I change its value to true, then this code will become executed.. So let’s look at a way that we might use this in an example.. Here is a very simple example: it has a circle moving across the screen size background, an ellipse drawing at x, x, x, 2.
. What if I don’t want this circle to start until I click the mouse? Well, you might think I would do something like, ah, if mousePressed and then run this and now. Ah, the circle is not moving. If I click the mouse, it is moving. If I let go of the mouse it stopped, but what if I just want the event of clicking the mouse to trigger the circle, to move from now on and forever going forward. So to do that? What if I made up my own variable like ‘going’, and we say boolean – going – equals false and run this code it’s not moving. Now, if I change the value of ‘going’ to true it’s moving, because ‘going’ is true, so this code is being executed.. So now all you need to do is change the value of ‘going’ from false to true the moment that I want the circle start moving when I click the mouse., so in this case right here, let’s start with ‘going’ as false and then when in mousePressed. This is an event that’s triggered as soon as the user clicks, the mouse let’s set going true, and it bothers me that you can’t see all of the code here so I’m, just gon na make this fit here.. Now we can see. Ok going is false. So when we run it, it’s not moving it’s, not moving, because going is false, but now when I click the mouse going becomes true and it moves.
ah I’m gon na stop it click the mouse. Ah, no matter what, when I click the mouse now going, is true what, if want going to become false, here’s a neat little trick. We have time for this. You have time for this. I have somewhere. I need to be but I’m making this video anyway. So in mousePressed we are saying going equals true, but what if I want going to only become true if it wasn’t true and if going was already true, I want going now to be false. In other words, I want to say, if going …, then going equals false right. If going is true, then set going equal to false, otherwise set going equal to true. So if going is true set going to false, otherwise, if going is false, set it equal to true. let’s go implement that ok, so I’m down here and I’m going to implement this.. If going and by the way you could have written it like this. If going true, but that’s, really long, winded going is just true or false, and a boolean expression evaluates to true or false, so I can really just say if going true, I can just say if going by the way, if going false is the same as saying: If going that exclamation point is NOT is not going, my … a little bigger here, hopefully you can read this.. Ok, so remember. If it’s going then going should be false, otherwise let’s say going is true.
Let’S run this now right, so going is false right now. So when I click the mouse inintelligible now, if I click the mouse again going is true. Ah going is set to false. Oh, what a magical thing just happened, ready, start, …, stop … start …! Stop oh it’s gon na leave the screen.. Ok, but maybe you thought this was all there’s one more piece of this. This is fine and good and perfectly reasonable. It is rather long winded we as programmers. Sometimes our whole life is just trying to make things shorter, although that’s not really any point of that, you might also just make things longer: it’s good for things to be clear, readable but anyway, if we want to make this shorter let’s examine this statement going going. This seems like it must be some sort of illegal code that you could not possibly write and it’s self referential and circular in some way it’s not gon na work, but in fact this is exactly what we want in this particular case. Let’S. Think about this again. Let’S say x, y z, if we have a statement like this remember we evaluate this side of the equation and store the result over here. So we’re going to do the same thing here. We evaluate this side of the equation and store the result here. It’S kind of like how, when you say x, x, 1, this seems a little strange. It equals itself plus 1, but it’s not big deal if it were 5, then 5, 16 and now x equals to 6.
This is an operation that increments x over and over again 5 becomes 6 becomes 7 I’m. Talking way too fast in this video, but here let’s say going is true. What is not true, not true is false. Let’S say going is false. What is not false, true? So going equals not itself just takes the value of going if it’s true, it turns it into false if it’s false. It turns it into true. That might give you a little bit of a headache, but I think that, as you start to think about it and write it down and think about it again, it will start to make more and more sense. So let’s go back over here and let’s. Look at what he can write here now going equals not going. Ok going is currently false. So as soon as I click the mouse going is going to equal, not false, which is true, and when I click the mouse again going is going to equal, not true, which is false.. So this is just a little bit of an inkling of what it means to use a variable with a type of boolean it’s, just a little bit of a helper it’s kind of like we can store the value of a switch in our program. We can always know is that switch on, or is that switch off and at any point we could act upon that if the switch is on do this code, if it’s off do this other code.
and we can also change the value of that switch by turning It on setting it to true or turning it off, setting it to false., usually at the end of these videos. I give some sort of exercise, but I can’t think of one right now, but what you might do is find some program that you wrote and see where you might store a value of true or false and act upon that.. That could be something that you could do. I’ll. Think of something better later, maybe put it in the notes. Ok, I’m. Gon na stop this video and you’re going to enjoy the rest of your day I’m over here and I’m going now.. My going is true.
arduino boolean Video
arduino boolean news
Posted on Thursday May 09, 2019Stator Library Makes Your Arduino Code Easier To Read Hackaday … Continue Reading »
Posted on Thursday February 07, 2019Arduino Enters The Cloud Hackaday … Continue Reading »
Posted on Sunday February 17, 2019How To Program A Really Cheap Microcontroller Hackaday … Continue Reading »
arduino boolean Social
🔬 Now that you’ve gotten your feet wet, dive into the kit and enjoy all nine experiments. Order yours today: http://bit.ly/2MnQ7fr
Originally posted 2018-07-21 04:47:33.