HSA_LCD_Shield.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // Programname: HSA_LCD_Shield - Header //
  4. // Date: 23.04.2018 //
  5. // Description: Header-File of the LCD-Shield, which was designed and built //
  6. // in the Modul "Elektronikdesign". In this file you can find //
  7. // the description of all functions of the class HSA_LCD_Shield. //
  8. // //
  9. // Author: Tobias Müller, M. Eng. //
  10. // //
  11. ////////////////////////////////////////////////////////////////////////////////
  12. ////////////////////////////////////////////////////////////////////////////////
  13. //////////////////// Create Header ////////////////////
  14. ////////////////////////////////////////////////////////////////////////////////
  15. #ifndef HSA_LCD_SHIELD
  16. #define HSA_LCD_SHIELD
  17. ////////////////////////////////////////////////////////////////////////////////
  18. //////////////////// Define Symbol ////////////////////
  19. ////////////////////////////////////////////////////////////////////////////////
  20. // I²C Addresse (Default)
  21. #ifndef I2C_ADDRESS
  22. #define I2C_ADDRESS 0x3C
  23. #endif
  24. // Button Right
  25. #ifndef BUTTON_RIGHT
  26. #define BUTTON_RIGHT 0x02
  27. #endif
  28. // Button Down
  29. #ifndef BUTTON_DOWN
  30. #define BUTTON_DOWN 0x03
  31. #endif
  32. // Button Up
  33. #ifndef BUTTON_UP
  34. #define BUTTON_UP 0x04
  35. #endif
  36. // Button Left
  37. #ifndef BUTTON_LEFT
  38. #define BUTTON_LEFT 0x05
  39. #endif
  40. // LED Red
  41. #ifndef LED_RED
  42. #define LED_RED 0x06
  43. #endif
  44. // LED Green
  45. #ifndef LED_GREEN
  46. #define LED_GREEN 0x07
  47. #endif
  48. // LCD-Backlight
  49. #ifndef LCD_BACKLIGHT
  50. #define LCD_BACKLIGHT 0x08
  51. #endif
  52. // Config: LEDs = On, Buttons = On (Default)
  53. #ifndef CONFIG_L1B1
  54. #define CONFIG_L1B1 "L1B1"
  55. #endif
  56. // Config: LEDs = On, Buttons = Off
  57. #ifndef CONFIG_L1B0
  58. #define CONFIG_L1B0 "L1B0"
  59. #endif
  60. // Config: LEDs = Off, Buttons = On
  61. #ifndef CONFIG_L0B1
  62. #define CONFIG_L0B1 "L0B1"
  63. #endif
  64. // Config: LEDs = Off, Buttons = Off
  65. #ifndef CONFIG_L0B0
  66. #define CONFIG_L0B0 "L0B0"
  67. #endif
  68. // Control Byte: Continue Bit
  69. #ifndef CONTROL_BYTE_CB
  70. #define CONTROL_BYTE_CB 0x80
  71. #endif
  72. // Control Byte: Data/Command Selection Bit
  73. #ifndef CONTROL_BYTE_DCB
  74. #define CONTROL_BYTE_DCB 0x40
  75. #endif
  76. // LCD-Parameter: Function Set 1
  77. #ifndef LCD_PARA_FUNC1
  78. #define LCD_PARA_FUNC1 0x3A // 8 Bit, RE = 1, IS = 0
  79. #endif
  80. // LCD-Parameter: Function Set 2
  81. #ifndef LCD_PARA_FUNC2
  82. #define LCD_PARA_FUNC2 0x39 // 8 Bit, RE = 0, IS = 1
  83. #endif
  84. // LCD-Parameter: Function Set 3
  85. #ifndef LCD_PARA_FUNC3
  86. #define LCD_PARA_FUNC3 0x38 // 8 Bit, RE = 0, IS = 0
  87. #endif
  88. // LCD-Parameter: Extended Function
  89. #ifndef LCD_PARA_EXT_FUNC
  90. #define LCD_PARA_EXT_FUNC 0x09 // 4-Line Display
  91. #endif
  92. // LCD-Parameter: Entry Mode
  93. #ifndef LCD_PARA_ENTRY_MODE
  94. #define LCD_PARA_ENTRY_MODE 0x06 // Bottom View
  95. #endif
  96. // LCD-Parameter: Bias Setting
  97. #ifndef LCD_PARA_BIAS_SET
  98. #define LCD_PARA_BIAS_SET 0x1E // BS1 = 1
  99. #endif
  100. // LCD-Parameter: Internal OSC
  101. #ifndef LCD_PARA_INT_OSC
  102. #define LCD_PARA_INT_OSC 0x1B // BS0 = 1, Bias = 1/6
  103. #endif
  104. // LCD-Parameter: Follower Control
  105. #ifndef LCD_PARA_FOL_CON
  106. #define LCD_PARA_FOL_CON 0x6E // Devider on, Set Value
  107. #endif
  108. // LCD-Parameter: Power Control
  109. #ifndef LCD_PARA_POW_CON
  110. #define LCD_PARA_POW_CON 0x56 // Booster on, Set Contrast
  111. #endif
  112. // LCD-Parameter: Contrast Set
  113. #ifndef LCD_PARA_CONTRAST
  114. #define LCD_PARA_CONTRAST 0x7A
  115. #endif
  116. // LCD-Parameter: Display on/off Control
  117. #ifndef LCD_PARA_DIS_CON
  118. #define LCD_PARA_DIS_CON 0x0F // Display on, Cursor on, Blink on
  119. #endif
  120. // LCD-Parameter: Clear Display
  121. #ifndef LCD_PARA_CLR_DIS
  122. #define LCD_PARA_CLR_DIS 0x01
  123. #endif
  124. // LCD-Parameter: Display Row 1
  125. #ifndef LCD_PARA_DIS_ROW1
  126. #define LCD_PARA_DIS_ROW1 0x80
  127. #endif
  128. // LCD-Parameter: Display Row 2
  129. #ifndef LCD_PARA_DIS_ROW2
  130. #define LCD_PARA_DIS_ROW2 0xA0
  131. #endif
  132. // LCD-Parameter: Display Row 3
  133. #ifndef LCD_PARA_DIS_ROW3
  134. #define LCD_PARA_DIS_ROW3 0xC0
  135. #endif
  136. // LCD-Parameter: Display Row 4
  137. #ifndef LCD_PARA_DIS_ROW4
  138. #define LCD_PARA_DIS_ROW4 0xE0
  139. #endif
  140. // Free Space
  141. #ifndef FREE_SPACE
  142. #define FREE_SPACE 0x20
  143. #endif
  144. // End of a String
  145. #ifndef STRING_END
  146. #define STRING_END 0x00
  147. #endif
  148. // Backslash n (\n)
  149. #ifndef BACKSLASH_N
  150. #define BACKSLASH_N 0x0A
  151. #endif
  152. // Backslash r (\r)
  153. #ifndef BACKSLASH_R
  154. #define BACKSLASH_R 0x0D
  155. #endif
  156. // Delay before and after transmission in µs
  157. #ifndef DELAY_TRANS_US
  158. #define DELAY_TRANS_US 0x64
  159. #endif
  160. // Array size for writing a row
  161. #ifndef ARRAY_SIZE_ROW
  162. #define ARRAY_SIZE_ROW 0x0D
  163. #endif
  164. ////////////////////////////////////////////////////////////////////////////////
  165. //////////////////// Include Header-File ////////////////////
  166. ////////////////////////////////////////////////////////////////////////////////
  167. #include <Arduino.h>
  168. #include <Wire.h>
  169. #include <stdio.h>
  170. ////////////////////////////////////////////////////////////////////////////////
  171. //////////////////// Define Class ////////////////////
  172. ////////////////////////////////////////////////////////////////////////////////
  173. /**
  174. * @brief LCD-Shield Class to control all functionalities of the Shield
  175. */
  176. class HSA_LCD_Shield {
  177. ////////////////////////////////////////////////////////////////////////////////
  178. //////////////////// protected Functions/Variables ////////////////////
  179. ////////////////////////////////////////////////////////////////////////////////
  180. protected:
  181. //////////////////// protected Variables ////////////////////
  182. char __i2cAddress; //! @brief Store the I²C-Address of the LC-Display
  183. char __config[0x05];//! @brief Store the Buttons/LEDs-Configuration
  184. bool __buttons; //! @brief Store the value "true", if the buttons configured
  185. bool __leds; //! @brief Store the value "true", if the LEDs configured
  186. ////////////////////////////////////////////////////////////////////////////////
  187. //////////////////// Privat Functions/Variables ////////////////////
  188. ////////////////////////////////////////////////////////////////////////////////
  189. private:
  190. //////////////////// Send Message ////////////////////
  191. /**
  192. * @brief Used, to send an array of bytes to the LC-Display
  193. *
  194. * @param bytes Array of bytes
  195. * @param sizeBytes Size of the array of Bytes
  196. */
  197. void _sendMessage(byte* bytes, byte sizeBytes);
  198. //////////////////// protected Variables ////////////////////
  199. ////////////////////////////////////////////////////////////////////////////////
  200. //////////////////// Public Functions/Variables ////////////////////
  201. ////////////////////////////////////////////////////////////////////////////////
  202. public:
  203. //////////////////// Constructor ////////////////////
  204. /**
  205. * @brief Construct a new HSA_LCD_Shield object with default I²C-Address/Config
  206. */
  207. HSA_LCD_Shield();
  208. /**
  209. * @brief Construct a new HSA_LCD_Shield object with different I²C-Address
  210. *
  211. * @param address Address of the LC-Display
  212. */
  213. HSA_LCD_Shield(char address);
  214. /**
  215. * @brief Construct a new HSA_LCD_Shield object with different Config
  216. *
  217. * @param config Configuration of Buttons and LEDs
  218. */
  219. HSA_LCD_Shield(const char config[0x05]);
  220. /**
  221. * @brief Construct a new HSA_LCD_Shield object with different I²C-Address/Config
  222. *
  223. * @param address Address of the LC-Display
  224. * @param config Configuration of Buttons and LEDs
  225. */
  226. HSA_LCD_Shield(char address,const char config[0x05]);
  227. //////////////////// Deconstructor ////////////////////
  228. /**
  229. * @brief Destroy the HSA_LCD_Shield object
  230. */
  231. ~HSA_LCD_Shield(void);
  232. //////////////////// Start Configuration ////////////////////
  233. /**
  234. * @brief Start Configuration of LC-Display and Buttons/LEDS
  235. *
  236. * @return true Configuration is accepted
  237. * @return false Configuration is not accepted, check construction
  238. */
  239. bool begin(void);
  240. //////////////////// LCD-Backlight ////////////////////
  241. /**
  242. * @brief Turning on/off the LCD-Backlight
  243. *
  244. * @param value Boolean value for turning on/off the LCD-Backlight
  245. */
  246. void lcdBacklight(bool value);
  247. //////////////////// Clear Display ////////////////////
  248. /**
  249. * @brief Clear the LC-Display
  250. */
  251. void clearDisplay(void);
  252. //////////////////// Return Config ////////////////////
  253. /**
  254. * @brief Return the Configuration of Buttons/LEDs
  255. *
  256. * @return char* Return the Address of the Configuration Buttons/LEDs
  257. */
  258. char* returnConfig(void);
  259. //////////////////// Return I²C-Address ////////////////////
  260. /**
  261. * @brief Return the I²C-Address of the LC-Display
  262. *
  263. * @return char Return the I²C-Address of the LC-Display
  264. */
  265. char returnAddress(void);
  266. //////////////////// Control LEDs ////////////////////
  267. /**
  268. * @brief Function to control the state of a LED
  269. *
  270. * @param ledPin Pin-Number/Name of the LED
  271. * @param state State of the LED
  272. */
  273. void controlLed(char ledPin, bool state);
  274. //////////////////// Get the pressed Button ////////////////////
  275. /**
  276. * @brief Return the number of the button, which is pressed
  277. *
  278. * @return char 0x00, if no or more than one button is pressed
  279. * @return char 0x01, if only button "Up" is pressed
  280. * @return char 0x02, if only button "Right" is pressed
  281. * @return char 0x03, if only button "Down" is pressed
  282. * @return char 0x04, if only button "Left" is pressed
  283. */
  284. char getButton();
  285. //////////////////// Write Row 1 ////////////////////
  286. /**
  287. * @brief Write words in the first row.
  288. *
  289. * @param bytes Array of bytes, which should be written to the first row.
  290. */
  291. void writeRow1(const char* bytes);
  292. //////////////////// Write Row 2 ////////////////////
  293. /**
  294. * @brief Write words in the second row.
  295. *
  296. * @param bytes Array of bytes, which should be written to the second row.
  297. */
  298. void writeRow2(const char* bytes);
  299. //////////////////// Write Row 3 ////////////////////
  300. /**
  301. * @brief Write words in the third row.
  302. *
  303. * @param bytes Array of bytes, which should be written to the third row.
  304. */
  305. void writeRow3(const char* bytes);
  306. //////////////////// Write Row 4 ////////////////////
  307. /**
  308. * @brief Write words in the fourth row.
  309. *
  310. * @param bytes Array of bytes, which should be written to the fourth row.
  311. */
  312. void writeRow4(const char* bytes);
  313. //////////////////// Write 4 Rows ////////////////////
  314. /**
  315. * @brief Write words to all four rows.
  316. *
  317. * @param bytes Array of bytes, which should be written to the four rows.
  318. */
  319. void write4Rows(const char* bytes);
  320. ////////////////////////////////////////////////////////////////////////////////
  321. //////////////////// close Header ////////////////////
  322. ////////////////////////////////////////////////////////////////////////////////
  323. };
  324. #endif