|
@@ -111,58 +111,86 @@ HSA_LCD_Shield::~HSA_LCD_Shield(void) {}
|
|
|
|
|
|
bool HSA_LCD_Shield::begin(void) {
|
|
|
|
|
|
-// Check config-value and setup the Buttons and LEDs, depending of config-value
|
|
|
-if(strcmp(this->__config,CONFIG_L1B0) == 0 ||
|
|
|
- strcmp(this->__config,CONFIG_L1B1) == 0) {
|
|
|
-
|
|
|
- // Setup LEDs
|
|
|
- pinMode(LED_GREEN,OUTPUT);
|
|
|
- pinMode(LED_RED,OUTPUT);
|
|
|
- digitalWrite(LED_GREEN,HIGH);
|
|
|
- digitalWrite(LED_RED,HIGH);
|
|
|
-
|
|
|
-}
|
|
|
-if(strcmp(this->__config,CONFIG_L0B1) == 0 ||
|
|
|
- strcmp(this->__config,CONFIG_L1B1) == 0) {
|
|
|
-
|
|
|
- // Setup Buttons
|
|
|
- pinMode(BUTTON_UP,INPUT);
|
|
|
- pinMode(BUTTON_RIGHT,INPUT);
|
|
|
- pinMode(BUTTON_DOWN,INPUT);
|
|
|
- pinMode(BUTTON_LEFT,INPUT);
|
|
|
-
|
|
|
-}
|
|
|
-if(strcmp(this->__config,CONFIG_L1B1) != 0 &&
|
|
|
- strcmp(this->__config,CONFIG_L0B1) != 0 &&
|
|
|
- strcmp(this->__config,CONFIG_L1B0) != 0 &&
|
|
|
- strcmp(this->__config,CONFIG_L0B0) != 0) {
|
|
|
-
|
|
|
- // If config-value unknown, exit function with negative feedback
|
|
|
- return false;
|
|
|
-
|
|
|
-}
|
|
|
-
|
|
|
-// Define an array of Bytes for configure the Display
|
|
|
-byte buffer[] = {CONTROL_BYTE_CB,
|
|
|
- LCD_PARA_FUNC1,
|
|
|
- LCD_PARA_EXT_FUNC,
|
|
|
- LCD_PARA_ENTRY_MODE,
|
|
|
- LCD_PARA_BIAS_SET,
|
|
|
- LCD_PARA_FUNC2,
|
|
|
- LCD_PARA_INT_OSC,
|
|
|
- LCD_PARA_FOL_CON,
|
|
|
- LCD_PARA_POW_CON,
|
|
|
- LCD_PARA_CONTRAST,
|
|
|
- LCD_PARA_FUNC3,
|
|
|
- LCD_PARA_DIS_CON,
|
|
|
- LCD_PARA_CLR_DIS};
|
|
|
-
|
|
|
-// Send array of bytes
|
|
|
-_sendMessage(buffer, sizeof(buffer));
|
|
|
-
|
|
|
-// Exit function with positive feedback
|
|
|
-return true;
|
|
|
-
|
|
|
+ // Check config-value and setup the LEDs, depending of config-value
|
|
|
+ if(strcmp(this->__config,CONFIG_L1B0) == 0 ||
|
|
|
+ strcmp(this->__config,CONFIG_L1B1) == 0) {
|
|
|
+
|
|
|
+ // Setup LEDs
|
|
|
+ pinMode(LED_GREEN,OUTPUT);
|
|
|
+ pinMode(LED_RED,OUTPUT);
|
|
|
+ digitalWrite(LED_GREEN,HIGH);
|
|
|
+ digitalWrite(LED_RED,HIGH);
|
|
|
+
|
|
|
+ // Store the value "true", if LEDs are configured
|
|
|
+ this->__leds = true;
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ // Store the value "false", if LEDs are not configured
|
|
|
+ this->__leds = false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // Check config-value and setup the Buttons depending of config-value
|
|
|
+ if(strcmp(this->__config,CONFIG_L0B1) == 0 ||
|
|
|
+ strcmp(this->__config,CONFIG_L1B1) == 0) {
|
|
|
+
|
|
|
+ // Setup Buttons
|
|
|
+ pinMode(BUTTON_UP,INPUT);
|
|
|
+ pinMode(BUTTON_RIGHT,INPUT);
|
|
|
+ pinMode(BUTTON_DOWN,INPUT);
|
|
|
+ pinMode(BUTTON_LEFT,INPUT);
|
|
|
+
|
|
|
+ // Store the value "true", if buttons are configured
|
|
|
+ this->__buttons = true;
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ // Store the value "false", if buttons are not configured
|
|
|
+ this->__buttons = false;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ // If config-value is unknown, quit configuration, otherwise configure I²C
|
|
|
+ if(strcmp(this->__config,CONFIG_L1B1) != 0 &&
|
|
|
+ strcmp(this->__config,CONFIG_L0B1) != 0 &&
|
|
|
+ strcmp(this->__config,CONFIG_L1B0) != 0 &&
|
|
|
+ strcmp(this->__config,CONFIG_L0B0) != 0) {
|
|
|
+
|
|
|
+ // Store the value false for buttons and LEDs are not configured
|
|
|
+ this->__buttons = false;
|
|
|
+ this->__leds = false;
|
|
|
+
|
|
|
+ // If config-value unknown, exit function with negative feedback
|
|
|
+ return false;
|
|
|
+
|
|
|
+ }
|
|
|
+ else {
|
|
|
+
|
|
|
+ // Define an array of Bytes for configure the Display
|
|
|
+ byte buffer[] = {CONTROL_BYTE_CB,
|
|
|
+ LCD_PARA_FUNC1,
|
|
|
+ LCD_PARA_EXT_FUNC,
|
|
|
+ LCD_PARA_ENTRY_MODE,
|
|
|
+ LCD_PARA_BIAS_SET,
|
|
|
+ LCD_PARA_FUNC2,
|
|
|
+ LCD_PARA_INT_OSC,
|
|
|
+ LCD_PARA_FOL_CON,
|
|
|
+ LCD_PARA_POW_CON,
|
|
|
+ LCD_PARA_CONTRAST,
|
|
|
+ LCD_PARA_FUNC3,
|
|
|
+ LCD_PARA_DIS_CON,
|
|
|
+ LCD_PARA_CLR_DIS};
|
|
|
+
|
|
|
+ // Send array of bytes
|
|
|
+ _sendMessage(buffer, sizeof(buffer));
|
|
|
+
|
|
|
+ // Exit function with positive feedback
|
|
|
+ return true;
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
//////////////////// LCD-Backlight ////////////////////
|
|
@@ -198,14 +226,72 @@ void HSA_LCD_Shield::clearDisplay(void) {
|
|
|
|
|
|
char* HSA_LCD_Shield::returnConfig(void) {
|
|
|
|
|
|
- // return the configuration value
|
|
|
+ // Exit function and return the configuration value
|
|
|
return this->__config;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
//////////////////// Return I²C-Address ////////////////////
|
|
|
|
|
|
char HSA_LCD_Shield::returnAddress(void){
|
|
|
|
|
|
- // return the value of the I²C-Address
|
|
|
+ // Exit function and return the value of the I²C-Address
|
|
|
return this->__i2cAddress;
|
|
|
-}
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//////////////////// Control LEDs ////////////////////
|
|
|
+
|
|
|
+void HSA_LCD_Shield::controlLed(char ledPin, bool state) {
|
|
|
+
|
|
|
+ // Change state of a LED, if they are configured
|
|
|
+ if(this->__leds) digitalWrite(ledPin,!state);
|
|
|
+
|
|
|
+ // Exit function
|
|
|
+ return;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//////////////////// Get the pressed Button ////////////////////
|
|
|
+
|
|
|
+char HSA_LCD_Shield::getButton() {
|
|
|
+
|
|
|
+ // return 1, if only button "Up" is pressed and configured
|
|
|
+ if(digitalRead(BUTTON_UP) &&
|
|
|
+ !digitalRead(BUTTON_RIGHT) &&
|
|
|
+ !digitalRead(BUTTON_DOWN) &&
|
|
|
+ !digitalRead(BUTTON_LEFT) &&
|
|
|
+ this->__buttons)
|
|
|
+ return 1;
|
|
|
+
|
|
|
+ // return 2, if only button "Right" is pressed and configured
|
|
|
+ if(!digitalRead(BUTTON_UP) &&
|
|
|
+ digitalRead(BUTTON_RIGHT) &&
|
|
|
+ !digitalRead(BUTTON_DOWN) &&
|
|
|
+ !digitalRead(BUTTON_LEFT) &&
|
|
|
+ this->__buttons)
|
|
|
+ return 2;
|
|
|
+
|
|
|
+ // return 3, if only button "Down" is pressed and configured
|
|
|
+ if(!digitalRead(BUTTON_UP) &&
|
|
|
+ !digitalRead(BUTTON_RIGHT) &&
|
|
|
+ digitalRead(BUTTON_DOWN) &&
|
|
|
+ !digitalRead(BUTTON_LEFT) &&
|
|
|
+ this->__buttons)
|
|
|
+ return 3;
|
|
|
+
|
|
|
+ // return 4, if only button "Left" is pressed and configured
|
|
|
+ if(!digitalRead(BUTTON_UP) &&
|
|
|
+ !digitalRead(BUTTON_RIGHT) &&
|
|
|
+ !digitalRead(BUTTON_DOWN) &&
|
|
|
+ digitalRead(BUTTON_LEFT) &&
|
|
|
+ this->__buttons)
|
|
|
+ return 4;
|
|
|
+
|
|
|
+ // return 0, if no button or more than one button is pressed
|
|
|
+ return 0;
|
|
|
+
|
|
|
+}
|
|
|
+
|
|
|
+//////////////////// Get the pressed Button ////////////////////
|
|
|
+//////////////////// Get the pressed Button ////////////////////
|