limiting to "no less than" zero


Results 1 to 31 of 31

Threaded View

  1. #3
    Join Date
    Oct 2009
    Location
    Utah, USA
    Posts
    427


    Did you find this post helpful? Yes | No

    Default Re: limiting to "no less than" zero

    This Should (untested as of yet) work...

    One thing about programming... there is always more than one way to do the exact same thing... some are more elegant than others... Mine usually falls into the "less elegant, but gets the job done" category

    The extra "IF" test should eliminate the need to test for below zero or the "max 0" test.

    Code:
    volume = 100        'set a default level
     step = 3            'This could be ANY NUMBER FROM 1 TO 9
    
     
     main:
    
     if buttonA  then volume = (volume + step) min 350     'this works fine to limit the top end to 350
     
     if buttonB and (volume < 3) then  
          volume = 0
          goto Skip1
          endif  
     
     if buttonB  then volume= (volume - step)         'but of course THIS fails, because it's hard to go lower than zero
    
    Skip1:
     LCDOUT $fe, $c0, dec volume
    
     pause 50
     goto main
    
     end
    Last edited by Heckler; - 17th September 2011 at 05:18.
    Dwight
    These PIC's are like intricate puzzles just waiting for one to discover their secrets and MASTER their capabilities.

Members who have read this thread : 0

You do not have permission to view the list of names.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts