Percentage


Closed Thread
Results 1 to 6 of 6

Thread: Percentage

  1. #1
    Join Date
    Oct 2009
    Posts
    583

    Default Percentage

    Guys, I'm having a brain fart and for the life of me can't get an LCD to display the value of a word variable as a percentage.

    The word variable is CH1_PWM and ranges from 0 to 4095

    I tried this

    Code:
    If (CH1_PWM * 100)/4095 >= 100 then
    lcdout $FE,$80,"CH1 ",$FE,$80+4,dec3 (CH1_PWM *100)/4095,"%"
    endif
    
    If (CH1_PWM * 100)/4095 <=0 or (CH1_PWM * 100)/4095 <10 then
    lcdout $FE,$80,"CH1 ",$FE,$80+4,dec1 (CH1_PWM *100)/4095,"% "
    endif
    
    if (CH1_PWM * 100)/4095 >=10 and (CH1_PWM * 100)/4095 <100 then
    lcdout $FE,$80,"CH1 ",$FE,$80+4,dec2 (CH1_PWM *10)/4095,"%  "
    endif
    I know there must be a simple way of doing this, but it's been a long day and my brain just refuses to think straight !! I have a menu option that kind of works in reverse as it it uses a byte variable (maxbright) that ranges from 0 to 100 and it is used to set a word variable (in this case CH1_Max)
    Code:
     CH1_Max = maxbright */ 10484
    But not sure how to compliment it the other way into the LCD display.

    Malc

  2. #2
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: Percentage

    One way:
    Code:
    Percent = Ch1_PWM ** 1601
    /Henrik.

  3. #3
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Percentage

    Thanks Henrik, that works a treat.

    Can you explain the maths behind the ** and 1601 ?

  4. #4
    Join Date
    May 2013
    Location
    australia
    Posts
    2,386


    Did you find this post helpful? Yes | No

    Default Re: Percentage

    Warning I'm not a teacher

  5. #5
    Join Date
    Oct 2005
    Location
    Sweden
    Posts
    3,519


    Did you find this post helpful? Yes | No

    Default Re: Percentage

    The deja vu feeling is overwhelming, thanks Richard for digging up that thread :-)
    The */ and ** operators have been covered many many times so yeah, read up on your own previous thread that Richard pointed to and I'll explain it there(post #11) :-)

    /Henrik.

  6. #6
    Join Date
    Oct 2009
    Posts
    583


    Did you find this post helpful? Yes | No

    Default Re: Percentage



    Sorry guys....

Similar Threads

  1. Displaying a percentage
    By Scampy in forum mel PIC BASIC Pro
    Replies: 11
    Last Post: - 15th August 2016, 23:14

Members who have read this thread : 1

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