LCDBacklightControl


This is a simple example on how you could control the LCD Plus shield backlight using the light sensor. The first example reads the value from the light sensor and sets it straight into the Backlight, the second example shows how we could control the backlight in the same sort of manner but this time we are using a Select Case statement.

Make sure that you uncomment the #option line if you are using a 3 line LCD.

Example One:

' enable this line if using a 3 line LCD
' #option LCD_DOGM = DOGM_163

' Imports section...
imports LCDDogm                      ' import DOGM LCD library


Sub Main()

   ' clear LCD and set backlight/contrast defaults        
   Dogm.Clear  
   Dogm.SetBacklight(160)        
   Dogm.SetContrast(7)

   ' loop forever...
   while true      

         ' get light value
         dim sensor as ushort = Adc.Read(A1)

         ' get/set backlight brightness
         Dogm.SetBacklight(sensor)

         ' update lcd
         Dogm.WriteAt(1,1,"Sensor = ", str(sensor,4))
         Dogm.writeAt(2,1,"Backlight = ",str(Dogm.GetBacklight,4))

   end while
End Sub

Example Two:

' enable this line if using a 3 line LCD
' #option LCD_DOGM = DOGM_163

' Imports section...
imports LCDDogm                      ' import DOGM LCD library

Sub Main()

   ' clear LCD and set backlight/contrast defaults        
   Dogm.Clear  
   Dogm.SetBacklight(160)        
   Dogm.SetContrast(7)

   ' loop forever...
   while true                   

         ' get light value
         dim sensor as ushort = Adc.Read(A1)

         ' update backlight brightness
         select sensor
            case <= 102 : Dogm.SetBacklight(0)
            case 103 to 205 : Dogm.SetBacklight(100)
            case 206 to 308 : Dogm.SetBacklight(250)
            case 309 to 501 : Dogm.SetBacklight(420)
            case 502 to 604 : Dogm.SetBacklight(570)
            case 605 to 707 : Dogm.SetBacklight(750)
            case 708 to 810 : Dogm.SetBacklight(880)
            case >= 811 : Dogm.SetBacklight(1023)
         end select

         ' update lcd
         Dogm.WriteAt(1,1,"Sensor = ", str(sensor,4))
         Dogm.writeAt(2,1,"Backlight = ",str(Dogm.GetBacklight,4))

   end while
End Sub