123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211 |
- ////////////////////////////////////////////////////////////////////////////////
- // //
- // Programname: Test_HSA_LCD_Shield //
- // Date: 04.05.2018 //
- // Description: Program to test the LCD-Shield, which was build in Elektro- //
- // nikdesign. //
- // //
- // Author: Tobias Müller, M. Eng. //
- // //
- ////////////////////////////////////////////////////////////////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- //////////////////// Include Header-File ////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- #include <HSA_LCD_Shield.h>
- ////////////////////////////////////////////////////////////////////////////////
- //////////////////// Define Symbols ////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- #define BAUDRATE 9600
- ////////////////////////////////////////////////////////////////////////////////
- //////////////////// Global Variable ////////////////////
- ////////////////////////////////////////////////////////////////////////////////
- HSA_LCD_Shield LCD = HSA_LCD_Shield(); // 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.write4Rows("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.write4Rows("Hochschule Anhalt\n FB EMW\nPress Key!");
- // Animate the third and fourth row
- LCD.writeRow4("");
- delay(200);
- LCD.writeRow3("> FB EMW <");
- delay(200);
- LCD.writeRow3(">>FB EMW<<");
- LCD.writeRow4("Press Key!");
- delay(200);
- LCD.writeRow3(" >FB EMW<");
- delay(200);
-
- }
- // while button up is pressed
- while(LCD.getButton() == BUTTON_UP) {
- // Show which button is pressed
- LCD.writeRow1("button");
- LCD.writeRow2("up *");
- LCD.writeRow3(" 0 0");
- LCD.writeRow4(" 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.writeRow1("button");
- LCD.writeRow2("right 0");
- LCD.writeRow3(" 0 *");
- LCD.writeRow4(" 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.writeRow1("button");
- LCD.writeRow2("down 0");
- LCD.writeRow3(" 0 0");
- LCD.writeRow4(" *");
- // 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.writeRow1("button");
- LCD.writeRow2("left 0");
- LCD.writeRow3(" * 0");
- LCD.writeRow4(" 0");
- // Let LED green blink
- LCD.controlLed(LED_GREEN,true);
- delay(200);
- LCD.controlLed(LED_GREEN,false);
- delay(200);
- }
- }
|