Selaa lähdekoodia

Display Helligkeitssteuerung hinzugefügt

Tobias Müller 5 vuotta sitten
vanhempi
commit
96d0448362
4 muutettua tiedostoa jossa 66 lisäystä ja 4 poistoa
  1. 49 2
      HSA_LCD_Shield.cpp
  2. 12 0
      HSA_LCD_Shield.h
  3. 5 2
      README.md
  4. BIN
      README.pdf

+ 49 - 2
HSA_LCD_Shield.cpp

@@ -116,6 +116,9 @@ bool HSA_LCD_Shield::__gpioConfig(void) {
     // Setup LCD-Backlight
     pinMode(this->__lcdBacklight,OUTPUT);
 
+    // Setup initial LCD-Brightness
+    this->__lcdBrightess = 255;
+
     // Initialize I²C as Master
     Wire.begin();
 
@@ -279,11 +282,55 @@ bool HSA_LCD_Shield::begin(byte address) {
 
 bool HSA_LCD_Shield::lcdBacklight(bool value) {
 
+  // check, whether LCD is configured
+  if(this->__lcd == false) return false; 
+
+   // Turning on/off LCD-Backlight, depending of LCD-Version
+  if(this->__version > LCD_VERSION_5) {
+
+    // Turning on/off LCD-Backlight
+    if(value) analogWrite(this->__lcdBacklight,this->__lcdBrightess);
+    else analogWrite(this->__lcdBacklight,value);
+
+  }
+
+  else {
+
+    // Turning on/off LCD-Backlight
+    digitalWrite(this->__lcdBacklight,value);
+
+  }
+  // Exit function
+  return true;
+
+}
+
+bool HSA_LCD_Shield::lcdBacklight(bool value, char brightness) {
+
   // check, whether LCD is configured
   if(this->__lcd == false) return false;
 
-  // Turning on/off LCD-Backlight
-  digitalWrite(this->__lcdBacklight,value);
+  // Turning on/off LCD-Backlight, depending of LCD-Version
+  if(this->__version > LCD_VERSION_5) {
+
+    // check, whether brightness value is between 0 and 100
+    if(brightness < 0 || brightness > 100) return false;
+
+    // store new brightness value
+    this->__lcdBrightess = map(brightness,0,100,0,255);
+
+    // Turning on/off LCD-Backlight
+    if(value) analogWrite(this->__lcdBacklight,this->__lcdBrightess);
+    else analogWrite(this->__lcdBacklight,value);
+
+  }
+
+  else {
+
+    // Turning on/off LCD-Backlight
+    digitalWrite(this->__lcdBacklight,value);
+
+  }
 
   // Exit function
   return true;

+ 12 - 0
HSA_LCD_Shield.h

@@ -355,6 +355,7 @@ byte __ledGreen;    //! @brief Store address of LED green
 byte __ledRed;      //! @brief Store address of LED red
 
 byte __lcdBacklight;//! @brief Store address of LCD-Backlight
+byte __lcdBrightess;//! @brief Store the Brightness of LCD-Backlight
 
 ////////////////////           GPIO Configuration           ////////////////////
 
@@ -456,6 +457,17 @@ bool begin(byte address);
  */
 bool lcdBacklight(bool value);
 
+/**
+ * @brief Control the brightness of the LCD-Backlight
+ * 
+ * @param value Boolean value for turning on/off the LCD-Backlight
+ * @param value char value for brightness control of the LCD-Backlight(0-100%)
+ * 
+ * @return true control LCD_Backlight successful
+ * @return false LCD_Backlight was not configured
+ */
+bool lcdBacklight(bool value, char brightness);
+
 ////////////////////             Clear Display              ////////////////////
 
 /**

+ 5 - 2
README.md

@@ -490,12 +490,12 @@ zur Verfügung.
     <u>Definition:</u>
 
     ```arduino
-    bool HSA_LCD_Shield.lcdBacklight(bool <state>);
+    bool HSA_LCD_Shield.lcdBacklight(bool <state>, char <brightness>);
     ```
 
     <u>Beschreibung:</u>
 
-    Mit dieser Methode lässt sich die LCD-Hintergrundbeleuchtung ein- oder ausschalten. Methode `HSA_LCD_Shield.begin()` muss erfolgreich ausgeführt worden sein. 
+    Mit dieser Methode lässt sich die LCD-Hintergrundbeleuchtung ein- oder ausschalten. Ab Shield-Version 6 lässt sich die Displayhelligkeit einstellen. Methode `HSA_LCD_Shield.begin()` muss erfolgreich ausgeführt worden sein. 
 
     <u>Parameter:</u>
 
@@ -504,6 +504,9 @@ zur Verfügung.
     * `HIGH` oder `true`: schaltet die LCD-Hintergrundbeleuchtung ein
     * `LOW` oder `false`: schaltet die LCD-Hintergrundbeleuchtung aus
 
+    `<brightness>` *(optional)*: steuert die Helligkeit der LCD-hintergrungbeleuchtung in Prozent (Wert von `0`-`100`)
+
+
     <u>Rückgabewert</u>
 
     `bool`:

BIN
README.pdf