Code:if buttonB then if volume - Vstep >= vstep then volume = volume - Vstep else volume = 0 endif endif
Code:if buttonB then if volume - Vstep >= vstep then volume = volume - Vstep else volume = 0 endif endif
"If the Earth were a single state, Istanbul would be its capital." Napoleon Bonaparte
Straying a little off...
I'm never more than a couple of threads away from having it underlined that I'm still woefully underskilled in this programming melarkey - where's the condition here...
to my n00b eyes, I'd have thought there should be a condition like "if buttonB = 0 then" or "if buttonB = 1 then"Code:if buttonB then
??
If buttonB means If buttonB=1.
Is a default.
A pure boolean logic.
Darrel gets the most elegant so far coding
Ioannis
I'd figured as much (on account everyone was doing it!)....can the default be changed to 0? (I'd imagine that switches get used with weak pullups or external pullups ....so the switch pressed condition would be a 0).
Re Darrel's entry..
how does bit 15 of 'volume' being a '1' indicate negative? Can someone shine a little more light on this one please?Code:if volume.15 then volume = 0 ; zero if it went negative
Last edited by HankMcSpank; - 17th September 2011 at 13:37.
Related to the "default" just use the ! before your variable:
If !buttonB then.... meaning If buttonB=0 then...
The 15th bit is the sign bit in two's complement. When the most significant bit is 1, it indicates a negative sign. Just Binary maths...
But is relative. If you use 8-bits then the 8th (most significant bit) is considered the sign bit. As long as you are thinking of positive and negative numbers. So at the end you have from -128 to +127 (1000 0000 to 0111 1111).
http://en.wikipedia.org/wiki/Two's_complement
Ioannis
Last edited by Ioannis; - 17th September 2011 at 14:06.
Thanks guys!
Well... I guess the answer to my question is that there isn't really a way that's as easy as using "min" to limit the upper end.
The method that Charles posted is what I've been using. But I was hoping for something that was... simpler.
I guess I'd hoped there was some way as clean and easy as "MAX" but that worked all the way down to zero.
Darrels method using volume.15 is great, but it "wastes" half of a variable.
Most of the variables that I need to limit are declared as bytes, and I need the full 255 step range for some of them.
I *can* use it for my temperature setpoint because that needs a word anyway and I can afford to "lose" part of it.
I'm starting to run low on code space on this project so hoping to find more efficient ways to do a few things...
Thanks for the input!
Steve
Bookmarks