Backlight Percentage

Information and discussion regarding Firewing shields

Backlight Percentage

Postby AndrewB » Thu Jan 09, 2014 4:03 pm

Display backlight %
Why does this cmd shows 0 when the value drops below 1023?
Dogm.WriteAt(2,1,"PWM=",Str((Getbacklight/1023)*100),"%")
AndrewB
 
Posts: 94
Joined: Thu Jan 02, 2014 3:38 pm

Re: Backlight Percentage

Postby David John Barker » Thu Jan 09, 2014 4:58 pm

Code: Select all
(Getbacklight/1023)*100

performs integer division on the GetBacklight / 1023, which will equal 0. To force floating point, you use
Code: Select all
(Getbacklight/1023.0)*100

However, you really don't want to use floating point maths on something as simple as a percentage. Try
Code: Select all
Dogm.WriteAt(2,1,"PWM=",CStr(Getbacklight * 100 / 1023),"% ")

Note it will only only go up to 99% on the LCD+ demo. This is because
Code: Select all
Dogm.SetBacklight(Dogm.GetBacklight + 5)

will in some cases set the backlight to < 1023. To test your percent, use
Code: Select all
Dogm.SetBacklight(Dogm.GetBacklight + 1)
User avatar
David John Barker
 
Posts: 491
Joined: Thu Nov 08, 2012 12:21 pm


Return to Shields

Who is online

Users browsing this forum: No registered users and 1 guest

cron

x