setting values and percentages


Closed Thread
Results 1 to 38 of 38

Hybrid View

  1. #1
    Join Date
    May 2013
    Location
    australia
    Posts
    2,666


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    with out the brackets you rely on the "operator precedence" order that the compiler will use , its often not what you really want . best bet is to always use brackets it eliminates the doubt

    ps I typed reply #6 wrong left the closing brackets after 100's out
    should be
    If ((maxbright * 100)/255 =0 ) or ( (maxbright * 100)/255 <10 ) then
    Last edited by richard; - 29th June 2014 at 11:34.

  2. #2
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: setting values and percentages

    Hi Guys and thanks for the input.

    As requested here is the complete brightness routine that works when using Darrels software PWM.

    Code:
    brightness:
     
    Lcdout $FE,2
    LCDOUT $FE,$80,"Set Max Brightness"
    IF H_butt = 0 THEN GOSUB up
    IF M_butt = 0 THEN GOSUB down
    If (maxbright * 100)/255 = 100 then
    LCDOUT $FE,$C0,"Channel 1 "
    LCDOut $FE,$D4,dec3 (maxbright *100)/255,"%"
    endif
    
    If (maxbright * 100)/255 =0 or (maxbright * 100)/255 <10 then
    LCDOUT$FE,$C0,"Channel 1 "
    LCDOut $FE,$D4,dec1 (maxbright *100)/255,"% "
    endif
    
    if (maxbright * 100)/255 >=10 and (maxbright * 100)/255 <100 then
    LCDOUT$FE,$C0,"Channel 1 "
    LCDOut $FE,$D4,dec2 (maxbright *100)/255,"%   "
    endif
        B_max = maxbright 
    write 8,b_max      
        
    If S_butt = 0 then
        pause 200 
        goto brightness2
    endif 
    goto brightness
    
    brightness2: 
     
    Lcdout $FE,2
    LCDOUT $FE,$80,"Set Max Brightness"
    IF H_butt = 0 THEN GOSUB up
    IF M_butt = 0 THEN GOSUB down
    If (maxbright * 100)/255 = 100 then
    LCDOUT $FE,$C0,"Channel 2 "
    LCDOut $FE,$D4,dec3 (maxbright *100)/255,"%"
    endif
    
    If (maxbright * 100)/255 =0 or (maxbright * 100)/255 <10 then
    LCDOUT$FE,$C0,"Channel 2 "
    LCDOut $FE,$D4,dec1 (maxbright *100)/255,"% "
    endif
    
    if (maxbright * 100)/255 >=10 and (maxbright * 100)/255 <100 then
    LCDOUT$FE,$C0,"Channel 2 "
    LCDOut $FE,$D4,dec2 (maxbright *100)/255,"%   "
    endif
        
        W_max = maxbright
    write 9,W_max 
    pause 200
    If S_butt = 0 then
        pause 200 
        LCDOUT $FE,1   
        goto mainmenu
    endif
    goto brightness2
    
    up:
        maxbright = maxbright + 1
        IF maxbright > 255 THEN maxbright = 0
        pause 50
    RETURN
    down:
        maxbright = maxbright - 1
        IF maxbright = 0 THEN maxbright = 255
        pause 50
    RETURN
    I can't argue with the brackets - all I know when I enter that menu option I can press the up and down buttons and the LCD displays 0% - 100%, and when checked using a diagnostics section which displays the variable value it correctly shows 0 - 255 and 127 for a 50% value - However I'm now using a PCA 9685 chip, which has a resolution of 4095 steps, so the progression is nice and smooth, and all I need is to repeat this but with 4095 steps, ie so 100% = 4095, 1%=40.95 (or 41 as it would need to be an integer) and 50% would equal 2047, but just can't seem to get my head round the calculation (never was any good at percentages at school all those years ago !

    Malcolm

Similar Threads

  1. POT part values
    By Michael in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 24th January 2009, 10:41
  2. Port Values
    By Pesticida in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 2nd January 2007, 20:44
  3. t in POT, c's values
    By selbstdual in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 24th August 2006, 23:30
  4. Numeric Values
    By Armando Herjim in forum General
    Replies: 8
    Last Post: - 28th June 2006, 01:54
  5. Wrong values with COSINE!
    By Eng4444 in forum mel PIC BASIC Pro
    Replies: 24
    Last Post: - 8th May 2006, 16:59

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