//////////////////////////////////////////////////////////////////////////////// // // // Programname: Test_HSA_LCD_Shield_V6 // // Date: 28.11.2018 // // Description: Program to test the LCD-Shield, which was build in Elektro- // // nikdesign. // // // // Author: Tobias Müller, M. Eng. // // // //////////////////////////////////////////////////////////////////////////////// //////////////////////////////////////////////////////////////////////////////// //////////////////// Include Header-File //////////////////// //////////////////////////////////////////////////////////////////////////////// #include //////////////////////////////////////////////////////////////////////////////// //////////////////// Define Symbols //////////////////// //////////////////////////////////////////////////////////////////////////////// #define BAUDRATE 9600 //////////////////////////////////////////////////////////////////////////////// //////////////////// Global Variable //////////////////// //////////////////////////////////////////////////////////////////////////////// HSA_LCD_Shield LCD(LCD_VERSION_6); // Create object of class HSA_LCD_Shield //////////////////////////////////////////////////////////////////////////////// //////////////////// Setup Function //////////////////// //////////////////////////////////////////////////////////////////////////////// void setup(void) { ////////////////////////////////////////////////////////////////////// //////////////////// Local Variable //////////////////// ////////////////////////////////////////////////////////////////////// bool config; // Store the answer from the "HSA_LCD_Shield.begin" ////////////////////////////////////////////////////////////////////// //////////////////// GPIO Setup //////////////////// ////////////////////////////////////////////////////////////////////// // Setup serial interface Serial.begin(BAUDRATE); // Wait until serial interface is not initialized while(!Serial); // Setup LCD-Shield config = LCD.begin(); ////////////////////////////////////////////////////////////////////// //////////////////// One run tasks //////////////////// ////////////////////////////////////////////////////////////////////// // Print answer from LCD-Setup if(config) Serial.println("LCD-Shield setup was successful!"); else Serial.println("LCD-Shield setup was not successful!"); // Print I²C-address of the LC-Display Serial.print("The I2C-address of the LC-Display is: 0x"); Serial.println(LCD.returnAddress(),HEX); // Print I²C-Config of buttons and LEDs Serial.print("The LCD-Shield configuration for buttons & LEDs is: "); Serial.println(LCD.returnConfig()); // Show startup process on LC-Display, if setup was successful if(config) { // Print welcome message on LC-Display LCD.writeRow("Hochschule Anhalt\n FB EMW\nPress Key!"); // Turn LCD-Backlight on LCD.lcdBacklight(true); // For four times turn LCD-Backlight on/off for(int i = 0; i<4; i++) { // Turn LCD-Backlight off LCD.lcdBacklight(false); // Wait 500 ms delay(500); // Turn LCD-Backlight on LCD.lcdBacklight(true); // Wait 500 ms delay(500); } } // Otherwise stop Program else while(true); // Exit Setup-Function return; } //////////////////////////////////////////////////////////////////////////////// //////////////////// Loop Function //////////////////// //////////////////////////////////////////////////////////////////////////////// void loop(void) { ////////////////////////////////////////////////////////////////////// //////////////////// Main Program //////////////////// ////////////////////////////////////////////////////////////////////// // while no or more than one button is pressed while(LCD.getButton() == false) { // Turn off LEDs LCD.controlLED(LED_GREEN,false); LCD.controlLED(LED_RED,false); // Print welcome message on LC-Display LCD.writeRow("Hochschule Anhalt\n FB EMW\nPress Key!"); // Animate the third and fourth row LCD.writeRow(0x03, ""); delay(200); LCD.writeRow(0x03, "> FB EMW <"); delay(200); LCD.writeRow(0x03, ">>FB EMW<<"); LCD.writeRow(0x04, "Press Key!"); delay(200); LCD.writeRow(0x03, " >FB EMW<"); delay(200); } // while button up is pressed while(LCD.getButton() == BUTTON_UP) { // Show which button is pressed LCD.writeRow(0x01, "button"); LCD.writeRow(0x02, "up *"); LCD.writeRow(0x03, " 0 0"); LCD.writeRow(0x04, " 0"); // Let LED red and green blink LCD.controlLED(LED_GREEN,true); LCD.controlLED(LED_RED,true); delay(200); LCD.controlLED(LED_GREEN,false); LCD.controlLED(LED_RED,false); delay(200); } // while button righ is pressed while(LCD.getButton() == BUTTON_RIGHT) { // Show which button is pressed LCD.writeRow(0x01, "button"); LCD.writeRow(0x02, "right 0"); LCD.writeRow(0x03, " 0 *"); LCD.writeRow(0x04, " 0"); // Let LED red blink LCD.controlLED(LED_RED,true); delay(200); LCD.controlLED(LED_RED,false); delay(200); } // while button down is pressed while(LCD.getButton() == BUTTON_DOWN) { // Show which button is pressed LCD.writeRow(0x01, "button"); LCD.writeRow(0x02, "down 0"); LCD.writeRow(0x03, " 0 0"); LCD.writeRow(0x04, " *"); // Let LED red and green blink differently LCD.controlLED(LED_GREEN,false); LCD.controlLED(LED_RED,true); delay(200); LCD.controlLED(LED_GREEN,true); LCD.controlLED(LED_RED,false); delay(200); } // while button left is pressed while(LCD.getButton() == BUTTON_LEFT) { // Show which left is pressed LCD.writeRow(0x01, "button"); LCD.writeRow(0x02, "left 0"); LCD.writeRow(0x03, " * 0"); LCD.writeRow(0x04, " 0"); // Let LED green blink LCD.controlLED(LED_GREEN,true); delay(200); LCD.controlLED(LED_GREEN,false); delay(200); } }