Selaa lähdekoodia

Merge branch 'master' of https://gogs.es-lab.de/HS-Anhalt/LCD-Shield

Tobias Müller 3 vuotta sitten
vanhempi
commit
3b8f20ef15
2 muutettua tiedostoa jossa 61 lisäystä ja 2 poistoa
  1. 49 2
      HSA_LCD_Shield.cpp
  2. 12 0
      HSA_LCD_Shield.h

+ 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              ////////////////////
 
 /**