Search:

Type: Posts; User: Norm

Search: Search took 0.11 seconds.

  1. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    You are welcome. I'm glad you got it working.
  2. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    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...
  3. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    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...
  4. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    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...
  5. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    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...
  6. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    How about something like this:
    if count not at boundary
    then decrement count
    else leave count where it is - stop changing its value
  7. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    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.

    ...
  8. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    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...
  9. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    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.
  10. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    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...
  11. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    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...
  12. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    Yes, that sounds about right. Now try writing the code for that part of it.
  13. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: Need logic help

    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;
    }
  14. Thread: Need logic help

    by Norm
    Replies
    27
    Views
    1,422

    Re: I need help to write code where i want the count in redLED.setDutyCycle(count); to start at 0 and go up by.1 and when it reaches 1 go down by .1 then stay at zero

    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...
Results 1 to 14 of 14