User manual
DIMMING BACKLIGHT
The following experiment shows how we can automatically set the
LCD-lighting brighter or darker. By changing the PWM-value at pin
D9, the brightness of the backlighting is adjusted gradually. If
the PWM-value is chosen higher, the LED will be brighter. A lower
value will dim the lighting. By changing the PWM-value, we will
change the plus-pause ratio between activation and deactivation
duration of the 5-V-signal at D9. The following figure illustrates
this.
Transfer the program and observe the LED. This already looks
almost as if the display had been brought to life.
The experiment requires the LCD basic writing that you set up
in the function test.
001 // Integrating LCD-Library
002 #include <LiquidCrystal.h>
003
004 // Specifying LCD pins
005 // RS, E, D4, D5, D6, D7
006 LiquidCrystal lcd(11, 10, 2, 3, 4, 5);
007
008 #define Backlight 9
009
010 byte i = 0;
011 byte flag = 0;
012 unsigned long previousMillis = 0;
013 const long interval = 10;
014
015 void setup()
016 {
017 analogWrite(Backlight, 0);
018
019 lcd.begin(16, 2);
020 lcd.setCursor(0, 0);
021 lcd.print("**ARDUINO LCD**”);
022 }
023
024 void loop()
025 {
026 unsigned long currentMillis = millis();
027 if(currentMillis – previousMillis >= interval)
028 {