Test_HSA_LCD_Shield_V5.ino 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // Programname: Test_HSA_LCD_Shield_V5 //
  4. // Date: 28.11.2018 //
  5. // Description: Program to test the LCD-Shield, which was build in Elektro- //
  6. // nikdesign. //
  7. // //
  8. // Author: Tobias Müller, M. Eng. //
  9. // //
  10. ////////////////////////////////////////////////////////////////////////////////
  11. ////////////////////////////////////////////////////////////////////////////////
  12. //////////////////// Include Header-File ////////////////////
  13. ////////////////////////////////////////////////////////////////////////////////
  14. #include <HSA_LCD_Shield.h>
  15. ////////////////////////////////////////////////////////////////////////////////
  16. //////////////////// Define Symbols ////////////////////
  17. ////////////////////////////////////////////////////////////////////////////////
  18. #define BAUDRATE 9600
  19. ////////////////////////////////////////////////////////////////////////////////
  20. //////////////////// Global Variable ////////////////////
  21. ////////////////////////////////////////////////////////////////////////////////
  22. HSA_LCD_Shield LCD(LCD_VERSION_5); // Create object of class HSA_LCD_Shield
  23. ////////////////////////////////////////////////////////////////////////////////
  24. //////////////////// Setup Function ////////////////////
  25. ////////////////////////////////////////////////////////////////////////////////
  26. void setup(void) {
  27. //////////////////////////////////////////////////////////////////////
  28. //////////////////// Local Variable ////////////////////
  29. //////////////////////////////////////////////////////////////////////
  30. bool config; // Store the answer from the "HSA_LCD_Shield.begin"
  31. //////////////////////////////////////////////////////////////////////
  32. //////////////////// GPIO Setup ////////////////////
  33. //////////////////////////////////////////////////////////////////////
  34. // Setup serial interface
  35. Serial.begin(BAUDRATE);
  36. // Wait until serial interface is not initialized
  37. while(!Serial);
  38. // Setup LCD-Shield
  39. config = LCD.begin();
  40. //////////////////////////////////////////////////////////////////////
  41. //////////////////// One run tasks ////////////////////
  42. //////////////////////////////////////////////////////////////////////
  43. // Print answer from LCD-Setup
  44. if(config) Serial.println("LCD-Shield setup was successful!");
  45. else Serial.println("LCD-Shield setup was not successful!");
  46. // Print I²C-address of the LC-Display
  47. Serial.print("The I2C-address of the LC-Display is: 0x");
  48. Serial.println(LCD.returnAddress(),HEX);
  49. // Print I²C-Config of buttons and LEDs
  50. Serial.print("The LCD-Shield configuration for buttons & LEDs is: ");
  51. Serial.println(LCD.returnConfig());
  52. // Show startup process on LC-Display, if setup was successful
  53. if(config) {
  54. // Print welcome message on LC-Display
  55. LCD.writeRow("Hochschule Anhalt\n FB EMW\nPress Key!");
  56. // Turn LCD-Backlight on
  57. LCD.lcdBacklight(true);
  58. // For four times turn LCD-Backlight on/off
  59. for(int i = 0; i<4; i++) {
  60. // Turn LCD-Backlight off
  61. LCD.lcdBacklight(false);
  62. // Wait 500 ms
  63. delay(500);
  64. // Turn LCD-Backlight on
  65. LCD.lcdBacklight(true);
  66. // Wait 500 ms
  67. delay(500);
  68. }
  69. }
  70. // Otherwise stop Program
  71. else while(true);
  72. // Exit Setup-Function
  73. return;
  74. }
  75. ////////////////////////////////////////////////////////////////////////////////
  76. //////////////////// Loop Function ////////////////////
  77. ////////////////////////////////////////////////////////////////////////////////
  78. void loop(void) {
  79. //////////////////////////////////////////////////////////////////////
  80. //////////////////// Main Program ////////////////////
  81. //////////////////////////////////////////////////////////////////////
  82. // while no or more than one button is pressed
  83. while(LCD.getButton() == false) {
  84. // Turn off LEDs
  85. LCD.controlLED(LED_GREEN,false);
  86. LCD.controlLED(LED_RED,false);
  87. // Print welcome message on LC-Display
  88. LCD.writeRow("Hochschule Anhalt\n FB EMW\nPress Key!");
  89. // Animate the third and fourth row
  90. LCD.writeRow(0x03, "");
  91. delay(200);
  92. LCD.writeRow(0x03, "> FB EMW <");
  93. delay(200);
  94. LCD.writeRow(0x03, ">>FB EMW<<");
  95. LCD.writeRow(0x04, "Press Key!");
  96. delay(200);
  97. LCD.writeRow(0x03, " >FB EMW<");
  98. delay(200);
  99. }
  100. // while button up is pressed
  101. while(LCD.getButton() == BUTTON_UP) {
  102. // Show which button is pressed
  103. LCD.writeRow(0x01, "button");
  104. LCD.writeRow(0x02, "up *");
  105. LCD.writeRow(0x03, " 0 0");
  106. LCD.writeRow(0x04, " 0");
  107. // Let LED red and green blink
  108. LCD.controlLED(LED_GREEN,true);
  109. LCD.controlLED(LED_RED,true);
  110. delay(200);
  111. LCD.controlLED(LED_GREEN,false);
  112. LCD.controlLED(LED_RED,false);
  113. delay(200);
  114. }
  115. // while button righ is pressed
  116. while(LCD.getButton() == BUTTON_RIGHT) {
  117. // Show which button is pressed
  118. LCD.writeRow(0x01, "button");
  119. LCD.writeRow(0x02, "right 0");
  120. LCD.writeRow(0x03, " 0 *");
  121. LCD.writeRow(0x04, " 0");
  122. // Let LED red blink
  123. LCD.controlLED(LED_RED,true);
  124. delay(200);
  125. LCD.controlLED(LED_RED,false);
  126. delay(200);
  127. }
  128. // while button down is pressed
  129. while(LCD.getButton() == BUTTON_DOWN) {
  130. // Show which button is pressed
  131. LCD.writeRow(0x01, "button");
  132. LCD.writeRow(0x02, "down 0");
  133. LCD.writeRow(0x03, " 0 0");
  134. LCD.writeRow(0x04, " *");
  135. // Let LED red and green blink differently
  136. LCD.controlLED(LED_GREEN,false);
  137. LCD.controlLED(LED_RED,true);
  138. delay(200);
  139. LCD.controlLED(LED_GREEN,true);
  140. LCD.controlLED(LED_RED,false);
  141. delay(200);
  142. }
  143. // while button left is pressed
  144. while(LCD.getButton() == BUTTON_LEFT) {
  145. // Show which left is pressed
  146. LCD.writeRow(0x01, "button");
  147. LCD.writeRow(0x02, "left 0");
  148. LCD.writeRow(0x03, " * 0");
  149. LCD.writeRow(0x04, " 0");
  150. // Let LED green blink
  151. LCD.controlLED(LED_GREEN,true);
  152. delay(200);
  153. LCD.controlLED(LED_GREEN,false);
  154. delay(200);
  155. }
  156. }