You are welcome. I'm glad you got it working.
Type: Posts; User: Norm
You are welcome. I'm glad you got it working.
That does not make any sense. count >.99 is always > .1
My pseudo code did NOT test for both boundaries at the same time.
While incrementing >> check for the upper boundary
while...
Yes, that is one of the problems with floating point numbers. Look at the printed values.
Instead of using == 0 use >= with a value very close to 0.
So when the value goes below...
Where is the code that worked for 0 up to 1 to then down (but went too far)?
The fix was to use .9 vs 1 to stop going the incrementing.
You need to work with that code to have it stop when it gets...
Remember that floating point numbers are not always exactly equal to integer values.
That code doesn't do what I suggested in my last post.
That code is like this:
if count != 0 then do...
How about something like this:
if count not at boundary
then decrement count
else leave count where it is - stop changing its value
Use an if statement to prevent the value from going below the lower boundary.
You should not need a new boolean. The value of incrementCount would be false while count is being decremented.
...
So it looks like the code increments count past the value of 1 before testing if count's value is greater than 1.
You need to notice how floating point numbers work. The value of count is never...
What value is in count when the exception happens?
For debugging, add some print statements that print the value of count and incrementCount as the loop iterates.
You need to look at the compiler's warning statements when you compile the code.
Here is the warning I get when I compile your code:
LEDBrightness.java:35: warning: [empty] empty statement...
The variable: incrementCount is set to false the first time through the loop. It should only be set false when the count has reached the boundary.
The if statements need to be more complicated so...
Yes, that sounds about right. Now try writing the code for that part of it.
You would use the value in the boolean to decide if count was to be incremented or to be decremented.
For example
if(incrementCount) {
count += 1;
}else {
count -= 1;
}
Sounds like you need a boolean variable that says that count is either to be incremented or to be decremented.
And then a test for when the value of count has hit one of the boundaries.
Please...