HSA_LCD_Shield.cpp 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790
  1. ////////////////////////////////////////////////////////////////////////////////
  2. // //
  3. // Programname: HSA_LCD_Shield - Code //
  4. // Date: 16.11.2018 //
  5. // Description: Code-File of the LCD-Shield, which was designed and built in //
  6. // the Modul "Elektronikdesign". In this file you can find the //
  7. // code of all functions mentioned in the Header-File of the //
  8. // class. //
  9. // //
  10. // Author: Tobias Müller, M. Eng. //
  11. // //
  12. ////////////////////////////////////////////////////////////////////////////////
  13. ////////////////////////////////////////////////////////////////////////////////
  14. //////////////////// Include Header-File ////////////////////
  15. ////////////////////////////////////////////////////////////////////////////////
  16. #include "HSA_LCD_Shield.h"
  17. ////////////////////////////////////////////////////////////////////////////////
  18. //////////////////// Protected Functions ////////////////////
  19. ////////////////////////////////////////////////////////////////////////////////
  20. //////////////////// GPIO Configuration ////////////////////
  21. bool HSA_LCD_Shield::__gpioConfig(void) {
  22. // Save Pin configuration, depending of LCD-Shield version
  23. if(this->__version == LCD_VERSION_5) {
  24. // Save Pin configuration for buttons
  25. this->__buttonUp = BUTTON_UP_V5;
  26. this->__buttonRight = BUTTON_RIGHT_V5;
  27. this->__buttonDown = BUTTON_DOWN_V5;
  28. this->__buttonLeft = BUTTON_LEFT_V5;
  29. // Save Pin configuration for LEDs
  30. this->__ledGreen = LED_GREEN_V5;
  31. this->__ledRed = LED_RED_V5;
  32. // Save Pin configuration for LCD-Backlight
  33. this->__lcdBacklight = LCD_BACKLIGHT_V5;
  34. }
  35. else if(this->__version == LCD_VERSION_6) {
  36. // Save Pin configuration for buttons
  37. this->__buttonUp = BUTTON_UP_V6;
  38. this->__buttonRight = BUTTON_RIGHT_V6;
  39. this->__buttonDown = BUTTON_DOWN_V6;
  40. this->__buttonLeft = BUTTON_LEFT_V6;
  41. // Save Pin configuration for LEDs
  42. this->__ledGreen = LED_GREEN_V6;
  43. this->__ledRed = LED_RED_V6;
  44. // Save Pin configuration for LCD-Backlight
  45. this->__lcdBacklight = LCD_BACKLIGHT_V6;
  46. }
  47. // If LCD-Shield version is unknown, exit function with error
  48. else return false;
  49. // Check config-value and setup the LEDs, depending of config-value
  50. if(strcmp(this->__config,CONFIG_L1B0) == false ||
  51. strcmp(this->__config,CONFIG_L1B1) == false) {
  52. // Setup LEDs
  53. pinMode(this->__ledGreen,OUTPUT);
  54. pinMode(this->__ledRed,OUTPUT);
  55. digitalWrite(this->__ledGreen,HIGH);
  56. digitalWrite(this->__ledRed,HIGH);
  57. // Store the value "true", if LEDs are configured
  58. this->__leds = true;
  59. }
  60. else {
  61. // Store the value "false", if LEDs are not configured
  62. this->__leds = false;
  63. }
  64. // Check config-value and setup the Buttons depending of config-value
  65. if(strcmp(this->__config,CONFIG_L0B1) == false ||
  66. strcmp(this->__config,CONFIG_L1B1) == false) {
  67. // Setup Buttons
  68. pinMode(this->__buttonUp,INPUT);
  69. pinMode(this->__buttonRight,INPUT);
  70. pinMode(this->__buttonDown,INPUT);
  71. pinMode(this->__buttonLeft,INPUT);
  72. // Store the value "true", if buttons are configured
  73. this->__buttons = true;
  74. }
  75. else {
  76. // Store the value "false", if buttons are not configured
  77. this->__buttons = false;
  78. }
  79. // If config-value is unknown, quit configuration, otherwise configure Display
  80. if(strcmp(this->__config,CONFIG_L1B1) != false &&
  81. strcmp(this->__config,CONFIG_L0B1) != false &&
  82. strcmp(this->__config,CONFIG_L1B0) != false &&
  83. strcmp(this->__config,CONFIG_L0B0) != false) return false;
  84. else {
  85. // Setup LCD-Backlight
  86. pinMode(this->__lcdBacklight,OUTPUT);
  87. // Setup initial LCD-Brightness
  88. this->__lcdBrightess = 255;
  89. // Initialize I²C as Master
  90. Wire.begin();
  91. // Define an array of Bytes for configure the Display
  92. byte buffer[] = {CONTROL_BYTE_CB,
  93. LCD_PARA_FUNC1,
  94. LCD_PARA_EXT_FUNC,
  95. LCD_PARA_ENTRY_MODE,
  96. LCD_PARA_BIAS_SET,
  97. LCD_PARA_FUNC2,
  98. LCD_PARA_INT_OSC,
  99. LCD_PARA_FOL_CON,
  100. LCD_PARA_POW_CON,
  101. LCD_PARA_CONTRAST,
  102. LCD_PARA_FUNC3,
  103. LCD_PARA_DIS_CON,
  104. LCD_PARA_CLR_DIS};
  105. // Send array of bytes
  106. _sendMessage(buffer, sizeof(buffer));
  107. // Exit function with positive feedback
  108. return true;
  109. }
  110. }
  111. ////////////////////////////////////////////////////////////////////////////////
  112. //////////////////// Privat Functions ////////////////////
  113. ////////////////////////////////////////////////////////////////////////////////
  114. //////////////////// Send Message ////////////////////
  115. void HSA_LCD_Shield::_sendMessage(byte* bytes, byte sizeBytes) {
  116. // Small timeout before access the I²C-Bus
  117. delayMicroseconds(DELAY_TRANS_US);
  118. // Start I²C transmission
  119. Wire.beginTransmission(this->__i2cAddress);
  120. // Send an array of Bytes over I²C, depending of its size
  121. for(byte i = 0x00; i < sizeBytes; i++) Wire.write(bytes[i]);
  122. // Stop I²C transmission
  123. Wire.endTransmission();
  124. // Small timeout after access the I²C-Bus
  125. delayMicroseconds(DELAY_TRANS_US);
  126. // Exit function
  127. return;
  128. }
  129. ////////////////////////////////////////////////////////////////////////////////
  130. //////////////////// Public Functions ////////////////////
  131. ////////////////////////////////////////////////////////////////////////////////
  132. //////////////////// Constructor ////////////////////
  133. HSA_LCD_Shield::HSA_LCD_Shield(byte version, const char config[CONFIG_SIZE]) {
  134. // Save LCD-Shield version
  135. this->__version = version;
  136. // Save standard I²C-Address for LC-Display
  137. this->__i2cAddress = I2C_ADDRESS;
  138. // Save the configuration of Buttons/LEDs
  139. strcpy(this->__config,config);
  140. // Exit Constructor
  141. return;
  142. }
  143. HSA_LCD_Shield::HSA_LCD_Shield(byte version) {
  144. // Save LCD-Shield version
  145. this->__version = version;
  146. // Save standard I²C-Address for LC-Display
  147. this->__i2cAddress = I2C_ADDRESS;
  148. // Save the configuration of Buttons/LEDs
  149. strcpy(this->__config,CONFIG_L1B1);
  150. // Exit Constructor
  151. return;
  152. }
  153. HSA_LCD_Shield::HSA_LCD_Shield(const char config[CONFIG_SIZE]){
  154. // Save LCD-Shield version
  155. this->__version = LCD_VERSION_6;
  156. // Save standard I²C-Address for LC-Display
  157. this->__i2cAddress = I2C_ADDRESS;
  158. // Save the configuration of Buttons/LEDs
  159. strcpy(this->__config,config);
  160. // Exit Constructor
  161. return;
  162. }
  163. HSA_LCD_Shield::HSA_LCD_Shield(void){
  164. // Save LCD-Shield version
  165. this->__version = LCD_VERSION_6;
  166. // Save standard I²C-Address for LC-Display
  167. this->__i2cAddress = I2C_ADDRESS;
  168. // Save the configuration of Buttons/LEDs
  169. strcpy(this->__config,CONFIG_L1B1);
  170. // Exit Constructor
  171. return;
  172. }
  173. //////////////////// Deconstructor ////////////////////
  174. HSA_LCD_Shield::~HSA_LCD_Shield(void) {
  175. // Exit function
  176. return;
  177. }
  178. //////////////////// Start Configuration ////////////////////
  179. bool HSA_LCD_Shield::begin(void) {
  180. // Configure GPIOs
  181. this->__lcd = __gpioConfig();
  182. // Exit function
  183. return this->__lcd;
  184. }
  185. bool HSA_LCD_Shield::begin(byte address) {
  186. // Save I²C-Address of LC-Display
  187. this->__i2cAddress = address;
  188. // Configure GPIOs
  189. this->__lcd = __gpioConfig();
  190. // Exit function
  191. return this->__lcd;
  192. }
  193. //////////////////// LCD-Backlight ////////////////////
  194. bool HSA_LCD_Shield::lcdBacklight(bool value) {
  195. // check, whether LCD is configured
  196. if(this->__lcd == false) return false;
  197. // Turning on/off LCD-Backlight, depending of LCD-Version
  198. if(this->__version > LCD_VERSION_5) {
  199. // Turning on/off LCD-Backlight
  200. if(value) analogWrite(this->__lcdBacklight,this->__lcdBrightess);
  201. else analogWrite(this->__lcdBacklight,value);
  202. }
  203. else {
  204. // Turning on/off LCD-Backlight
  205. digitalWrite(this->__lcdBacklight,value);
  206. }
  207. // Exit function
  208. return true;
  209. }
  210. bool HSA_LCD_Shield::lcdBacklight(bool value, char brightness) {
  211. // check, whether LCD is configured
  212. if(this->__lcd == false) return false;
  213. // Turning on/off LCD-Backlight, depending of LCD-Version
  214. if(this->__version > LCD_VERSION_5) {
  215. // check, whether brightness value is between 0 and 100
  216. if(brightness < 0 || brightness > 100) return false;
  217. // store new brightness value
  218. this->__lcdBrightess = map(brightness,0,100,0,255);
  219. // Turning on/off LCD-Backlight
  220. if(value) analogWrite(this->__lcdBacklight,this->__lcdBrightess);
  221. else analogWrite(this->__lcdBacklight,value);
  222. }
  223. else {
  224. // Turning on/off LCD-Backlight
  225. digitalWrite(this->__lcdBacklight,value);
  226. }
  227. // Exit function
  228. return true;
  229. }
  230. //////////////////// Clear Display ////////////////////
  231. bool HSA_LCD_Shield::clearDisplay(void) {
  232. // check, whether LCD is configured
  233. if(this->__lcd == false) return false;
  234. // Define an array of Bytes for clearing the Display
  235. byte buffer[] = {CONTROL_BYTE_CB,
  236. LCD_PARA_CLR_DIS};
  237. // Send array of bytes
  238. _sendMessage(buffer, sizeof(buffer));
  239. // Exit function
  240. return true;
  241. }
  242. /////////////////// Return Version ////////////////////
  243. byte HSA_LCD_Shield::returnVersion(void) {
  244. // Exit function and return the configured Version for the LCD-Shield
  245. return this->__version;
  246. }
  247. //////////////////// Return Config ////////////////////
  248. char* HSA_LCD_Shield::returnConfig(void) {
  249. // Exit function and return the configuration value
  250. return this->__config;
  251. }
  252. //////////////////// Return I²C-Address ////////////////////
  253. byte HSA_LCD_Shield::returnAddress(void){
  254. // Exit function and return the value of the I²C-Address
  255. return this->__i2cAddress;
  256. }
  257. //////////////////// Control LEDs ////////////////////
  258. bool HSA_LCD_Shield::controlLED(byte ledPin, bool state) {
  259. // Checks, whether LED-Pins are configured
  260. if(this->__leds) {
  261. // Checks, whether LED-Color is known and control LED
  262. if(ledPin == LED_GREEN) {
  263. digitalWrite(this->__ledGreen,!state);
  264. return true;
  265. }
  266. if(ledPin == LED_RED) {
  267. digitalWrite(this->__ledRed,!state);
  268. return true;
  269. }
  270. }
  271. // Exit function with error, if LED-Pins are not configured or LED-Color is
  272. // unknown
  273. return false;
  274. }
  275. //////////////////// Get LED state ////////////////////
  276. bool HSA_LCD_Shield::getLED(byte ledPin) {
  277. // Exit function and return the value of chosen LED
  278. if(ledPin == LED_GREEN && this->__leds)
  279. return !digitalRead(this->__ledGreen);
  280. else if(ledPin == LED_RED && this->__leds)
  281. return !digitalRead(this->__ledRed);
  282. else return false;
  283. }
  284. //////////////////// Get the pressed Button ////////////////////
  285. byte HSA_LCD_Shield::getButton() {
  286. // return 1, if only button "Up" is pressed and configured
  287. if(digitalRead(this->__buttonUp) &&
  288. !digitalRead(this->__buttonRight) &&
  289. !digitalRead(this->__buttonDown) &&
  290. !digitalRead(this->__buttonLeft) &&
  291. this->__buttons)
  292. return BUTTON_UP;
  293. // return 2, if only button "Right" is pressed and configured
  294. if(!digitalRead(this->__buttonUp) &&
  295. digitalRead(this->__buttonRight) &&
  296. !digitalRead(this->__buttonDown) &&
  297. !digitalRead(this->__buttonLeft) &&
  298. this->__buttons)
  299. return BUTTON_RIGHT;
  300. // return 3, if only button "Down" is pressed and configured
  301. if(!digitalRead(this->__buttonUp) &&
  302. !digitalRead(this->__buttonRight) &&
  303. digitalRead(this->__buttonDown) &&
  304. !digitalRead(this->__buttonLeft) &&
  305. this->__buttons)
  306. return BUTTON_DOWN;
  307. // return 4, if only button "Left" is pressed and configured
  308. if(!digitalRead(this->__buttonUp) &&
  309. !digitalRead(this->__buttonRight) &&
  310. !digitalRead(this->__buttonDown) &&
  311. digitalRead(this->__buttonLeft) &&
  312. this->__buttons)
  313. return BUTTON_LEFT;
  314. // return false, if no button or more than one button is pressed or
  315. // buttons are not configured
  316. return false;
  317. }
  318. //////////////////// Write Row ////////////////////
  319. bool HSA_LCD_Shield::writeRow(byte row, const char* text) {
  320. // check, whether LCD is configured
  321. if(this->__lcd == false) return false;
  322. // If chosen Row does not exist, exit function with error
  323. if(!(row >= 0x01 && row <= 0x04)) return false;
  324. // Define buffer for test Message
  325. byte buffer[ARRAY_SIZE_ROW] = "";
  326. // Define variable to store a boolean value, if a control-byte was found
  327. bool controlByte = false;
  328. // Create data-array with message and send the message at the end
  329. for(byte i = 0x00; i < ARRAY_SIZE_ROW; i++) {
  330. // Set control-byte for changing parameter in the first iteration
  331. if(i == 0x00) buffer[i] = CONTROL_BYTE_CB;
  332. // Change the cursor position to row in the second iteration.
  333. if(i == 0x01 && row == 0x01) buffer[i] = LCD_PARA_DIS_ROW1;
  334. if(i == 0x01 && row == 0x02) buffer[i] = LCD_PARA_DIS_ROW2;
  335. if(i == 0x01 && row == 0x03) buffer[i] = LCD_PARA_DIS_ROW3;
  336. if(i == 0x01 && row == 0x04) buffer[i] = LCD_PARA_DIS_ROW4;
  337. // Set control-byte for writing to the display in the third iteration
  338. if(i == 0x02) buffer[i] = CONTROL_BYTE_DCB;
  339. // Copy text into the buffer between iteration 2 to 13
  340. if(i > 0x02 && i < ARRAY_SIZE_ROW) {
  341. // If no control-byte was found, copy byte into buffer
  342. if(!controlByte) {
  343. // Check byte for control-byte
  344. if(isControl(text[i - 0x03])) controlByte = true;
  345. // if not, copy byte into buffer
  346. else buffer[i] = text[i - 0x03];
  347. }
  348. // If control-byte was found, fill message with free space
  349. if(controlByte) {
  350. // Fill Buffer with free space
  351. buffer[i] = FREE_SPACE;
  352. }
  353. }
  354. }
  355. // Send message
  356. _sendMessage(buffer,sizeof(buffer));
  357. // Exit function with success
  358. return true;
  359. }
  360. bool HSA_LCD_Shield::writeRow(const char* text) {
  361. // check, whether LCD is configured
  362. if(this->__lcd == false) return false;
  363. // Define buffer for test Message
  364. char buffer[ARRAY_SIZE_ROW] = "";
  365. // Define variable to store the actual row position
  366. byte rowPosition = LCD_PARA_DIS_ROW1;
  367. // Define variable, which count the copied bytes
  368. byte countBytes = 0x00;
  369. // Create data-array with messages for 4 rows and send the messages
  370. for(byte i = 0x00; i < 0x28; i++){
  371. // If the position of the row is not selected, skip following code
  372. if(rowPosition == false) continue;
  373. // If first row is selected
  374. if(rowPosition == LCD_PARA_DIS_ROW1) {
  375. // If counted bytes has not reach max value, copy byte into buffer
  376. if(countBytes < 0x0A) buffer[countBytes] = text[i];
  377. // Check, if copied byte was control-byte
  378. if(isControl(text[i])) {
  379. // Check if control-byte was \n or \r or end of string,
  380. // set counted bytes to max value
  381. if(text[i] == BACKSLASH_N ||
  382. text[i] == BACKSLASH_R ||
  383. text[i] == STRING_END)
  384. countBytes = 0x0A;
  385. // Check if control-byte was end of the string, deactivate row position
  386. if(text[i] == STRING_END) rowPosition = false;
  387. }
  388. // Otherwise increase counted bytes
  389. else countBytes++;
  390. // If count bytes is max value
  391. if(countBytes == 0x0A) {
  392. // Reset count bytes
  393. countBytes = 0x00;
  394. // write first row
  395. writeRow(0x01, buffer);
  396. // If row position is deactivated
  397. if(rowPosition == false) {
  398. // clear following rows
  399. writeRow(0x02, &text[i]);
  400. writeRow(0x03, &text[i]);
  401. writeRow(0x04, &text[i]);
  402. }
  403. // Otherwise set row position the row 2
  404. else rowPosition = LCD_PARA_DIS_ROW2;
  405. // skip the rest of the code in this iteration
  406. continue;
  407. }
  408. }
  409. // If second row is selected
  410. if(rowPosition == LCD_PARA_DIS_ROW2) {
  411. // If counted bytes has not reach max value, copy byte into buffer
  412. if(countBytes < 0x0A) buffer[countBytes] = text[i];
  413. // Check, if copied byte was control-byte
  414. if(isControl(text[i])) {
  415. // Check if control-byte was \n or \r or end of string,
  416. // set counted bytes to max value
  417. if(text[i] == BACKSLASH_N ||
  418. text[i] == BACKSLASH_R ||
  419. text[i] == STRING_END)
  420. countBytes = 0x0A;
  421. // Check if control-byte was end of the string, deactivate row position
  422. if(text[i] == STRING_END) rowPosition = false;
  423. }
  424. // Otherwise increase counted bytes
  425. else countBytes++;
  426. // If count bytes is max value
  427. if(countBytes == 0x0A) {
  428. // Reset count bytes
  429. countBytes = 0x00;
  430. // write second row
  431. writeRow(0x02, buffer);
  432. // If row position is deactivated
  433. if(rowPosition == false) {
  434. // clear following rows
  435. writeRow(0x03, &text[i]);
  436. writeRow(0x04, &text[i]);
  437. }
  438. // Otherwise set row position the row 3
  439. else rowPosition = LCD_PARA_DIS_ROW3;
  440. // skip the rest of the code in this iteration
  441. continue;
  442. }
  443. }
  444. // If third row is selected
  445. if(rowPosition == LCD_PARA_DIS_ROW3) {
  446. // If counted bytes has not reach max value, copy byte into buffer
  447. if(countBytes < 0x0A) buffer[countBytes] = text[i];
  448. // Check, if copied byte was control-byte
  449. if(isControl(text[i])) {
  450. // Check if control-byte was \n or \r or end of string,
  451. // set counted bytes to max value
  452. if(text[i] == BACKSLASH_N ||
  453. text[i] == BACKSLASH_R ||
  454. text[i] == STRING_END)
  455. countBytes = 0x0A;
  456. // Check if control-byte was end of the string, deactivate row position
  457. if(text[i] == STRING_END) rowPosition = false;
  458. }
  459. // Otherwise increase counted bytes
  460. else countBytes++;
  461. // If count bytes is max value
  462. if(countBytes == 0x0A) {
  463. // Reset count bytes
  464. countBytes = 0x00;
  465. // write third row
  466. writeRow(0x03, buffer);
  467. // If row position is deactivated, clear following row
  468. if(rowPosition == false) writeRow(0x04, &text[i]);
  469. // Otherwise set row position the row 4
  470. else rowPosition = LCD_PARA_DIS_ROW4;
  471. // skip the rest of the code in this iteration
  472. continue;
  473. }
  474. }
  475. // If fourth row is selected
  476. if(rowPosition == LCD_PARA_DIS_ROW4) {
  477. // If counted bytes has not reach max value, copy byte into buffer
  478. if(countBytes < 0x0A) buffer[countBytes] = text[i];
  479. // Check, if copied byte was control-byte
  480. if(isControl(text[i])) {
  481. // Check if control-byte was \n or \r or end of string,
  482. // set counted bytes to max value
  483. if(text[i] == BACKSLASH_N ||
  484. text[i] == BACKSLASH_R ||
  485. text[i] == STRING_END)
  486. countBytes = 0x0A;
  487. // Check if control-byte was end of the string, deactivate row position
  488. if(text[i] == STRING_END) rowPosition = false;
  489. }
  490. // Otherwise increase counted bytes
  491. else countBytes++;
  492. // If count bytes is max value
  493. if(countBytes == 0x0A) {
  494. // Reset count bytes
  495. countBytes = 0x00;
  496. // write fourth row
  497. writeRow(0x04, buffer);
  498. // If row position is not deactivated, deaktivate row position
  499. if(rowPosition != false) rowPosition = false;
  500. // skip the rest of the code in this iteration
  501. continue;
  502. }
  503. }
  504. }
  505. // Exit function
  506. return true;
  507. }
  508. //////////////////// Write Position XY ////////////////////
  509. bool HSA_LCD_Shield::writeXY(byte row, byte column, const char* text) {
  510. // check, whether LCD is configured
  511. if(this->__lcd == false) return false;
  512. // If chosen Row does not exist, exit function with error
  513. if(!(row >= 0x01 && row <= 0x04)) return false;
  514. // If chosen Column does not exist, exit function with error
  515. if(!(column >= 0x01 && column <= 0x0A)) return false;
  516. // create variable to store count of chars
  517. byte count = 0x00;
  518. // Count chars inside of text
  519. for(byte i = 0x00; i < 0x0A && !isControl(text[i]); i++) count++;
  520. // Define buffer for text Message
  521. byte buffer[ARRAY_SIZE_ROW - (0x0A - count)] = "";
  522. // Create data-array with message and send the message at the end
  523. for(byte i = 0x00; i < sizeof(buffer); i++) {
  524. // Set control-byte for changing parameter in the first iteration
  525. if(i == 0x00) buffer[i] = CONTROL_BYTE_CB;
  526. // Change the cursor position to row/column in the second iteration.
  527. if(i == 0x01 && row == 0x01) buffer[i] = LCD_PARA_DIS_ROW1 | (column - 0x01);
  528. if(i == 0x01 && row == 0x02) buffer[i] = LCD_PARA_DIS_ROW2 | (column - 0x01);
  529. if(i == 0x01 && row == 0x03) buffer[i] = LCD_PARA_DIS_ROW3 | (column - 0x01);
  530. if(i == 0x01 && row == 0x04) buffer[i] = LCD_PARA_DIS_ROW4 | (column - 0x01);
  531. // Set control-byte for writing to the display
  532. if(i == 0x02) buffer[i] = CONTROL_BYTE_DCB;
  533. // Copy text into the buffer between iteration 2 to 13
  534. if(i >= 0x03 && i < sizeof(buffer)) buffer[i] = text[i - 0x03];
  535. }
  536. // Send message
  537. _sendMessage(buffer,sizeof(buffer));
  538. // Exit function with success
  539. return true;
  540. }