-
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
-
Re: Percentage
One way:
Code:
Percent = Ch1_PWM ** 1601
/Henrik.
-
Re: Percentage
Thanks Henrik, that works a treat.
Can you explain the maths behind the ** and 1601 ?
-
Re: Percentage
-
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.
-
Re: Percentage