LCD1602.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313
  1. Queue<int> _LCD_print_queue = Queue<int>(5);
  2. const int LCD1602rs=12, LCD1602en=11, LCD1602db4=5, LCD1602db5=4, LCD1602db6=3, LCD1602db7=2; // lcd keypad shield pins
  3. LiquidCrystal lcd(LCD1602rs, LCD1602en, LCD1602db4, LCD1602db5, LCD1602db6, LCD1602db7);
  4. int lcdPos = 0 ;
  5. struct _LCD_print_bufforS {
  6. int screenID;
  7. int cursor1;
  8. int cursor2;
  9. int character ;
  10. long time_seq_id;
  11. long time_min_run;
  12. } ;
  13. typedef struct _LCD_print_bufforS _LCD_print_bufforT;
  14. //struct LCDarray1S {
  15. // char LCDarray1[16];
  16. //}
  17. struct _LCD_print_screenS {
  18. int screenID;
  19. char LCDarray1;
  20. char LCDarray2;
  21. long time_seq_id;
  22. long time_min_run;
  23. // _LCD_print_bufforT ;
  24. } ;
  25. typedef struct _LCD_print_screenS _LCD_print_screensT;
  26. //_LCD_print_buffor _LCD_print_buffors[] = { 0 , 0, "T", 10000, 50000 } ;
  27. //_LCD_print_screen _LCD_print_screens[] = { 1 , _LCD_print_buffors } ;
  28. //void LCD_print_background_add( int[], int , int , int , char ,long , long ) ;
  29. _LCD_print_bufforT _LCD_print_buffors[1];
  30. _LCD_print_screensT _LCD_print_screens[10];
  31. void LCD_print_background_add(_LCD_print_bufforT* _LCD_print_buffors, int screenID, int cursor1, int cursor2, char character ,long time_seq_id, long time_min_run ) {
  32. //time_seq_id - used to maintain single display context
  33. //time_max - used to how much time to keep in displayed text
  34. // Serial.println(" runned LCD_print_background_screen_add bbuf: ");
  35. // Serial.print(sizeof(_LCD_print_buffors));
  36. Serial.print("CB:");
  37. int curr_buf_ind;
  38. int i ;
  39. for(i=1;i<=100;i++) {
  40. if(_LCD_print_buffors[i].screenID<=0) {
  41. Serial.print("i<=0["); Serial.print(i); Serial.print("]");
  42. curr_buf_ind = i;
  43. //if(_LCD_print_buffors[i + 1].screenID<=0)
  44. break;
  45. }
  46. }
  47. Serial.print(curr_buf_ind); Serial.print(". ");
  48. //char b = character.charAt(0);
  49. Serial.print(" added lcd buf at ind "); Serial.println(curr_buf_ind );
  50. int b_ascii_value = character;
  51. _LCD_print_buffors[curr_buf_ind] = { screenID , cursor1 , cursor2, b_ascii_value, time_seq_id , time_min_run} ;
  52. /*
  53. _LCD_print_buffors[screenID].screenID=screenID ;
  54. _LCD_print_buffors[screenID].cursor1=cursor1 ;
  55. _LCD_print_buffors[screenID].cursor2=cursor2 ;
  56. _LCD_print_buffors[screenID].character=b_ascii_value ;
  57. _LCD_print_buffors[screenID].time_seq_id=time_seq_id ;
  58. _LCD_print_buffors[screenID].time_min_run=time_min_run ;
  59. */
  60. }
  61. void LCD_print_background_screen_add(_LCD_print_screensT* _LCD_print_screens, int screenID,long time_seq_id, long time_min_run, char LCDarray1, char LCDarray2 ) {
  62. //time_seq_id - used to maintain single display context
  63. //time_max - used to how much time to keep in displayed text
  64. _LCD_print_screens[screenID].screenID=screenID ;
  65. _LCD_print_screens[screenID].time_seq_id=time_seq_id ;
  66. _LCD_print_screens[screenID].time_min_run=time_min_run ;
  67. _LCD_print_screens[screenID].LCDarray1=LCDarray1 ;
  68. _LCD_print_screens[screenID].LCDarray2=LCDarray2 ;
  69. Serial.print(" added to screen a1 "); Serial.println(String(LCDarray1) );
  70. // unsigned char LCDarray2buf[16];
  71. // LCDarray2.toCharArray(LCDarray2buf, 15);
  72. /*
  73. for ( int positionCounter1 = 0;
  74. positionCounter1 < 24; positionCounter1++)
  75. {
  76. LCD_print_background_add( _LCD_print_buffors, screenID, positionCounter1, 0, LCDarray1[positionCounter1], time_seq_id, time_min_run);
  77. Serial.print("A.");
  78. }
  79. for ( int positionCounter2 = 0;
  80. positionCounter2 < 24; positionCounter2++)
  81. {
  82. LCD_print_background_add( _LCD_print_buffors, screenID, positionCounter2, 1, LCDarray2[positionCounter2], time_seq_id, time_min_run);
  83. }
  84. Serial.print(" :");
  85. Serial.print(sizeof(_LCD_print_buffors));
  86. Serial.print(" :");
  87. */
  88. }
  89. // _LCD_print_bufforT _LCD_print_bufforss[] = { 0 , 0, "T", 10000, 50000 } ;
  90. void LCD_print_background(int cursor1, int cursor2, int character ,long time_seq_id, long time_min_run ) {
  91. //time_seq_id - used to maintain single display context
  92. //time_max - used to how much time to keep in displayed text
  93. }
  94. void _LCD_print_screens_list(_LCD_print_screensT* _LCD_print_screens ) {
  95. int i;
  96. Serial.print("sizeof(_LCD_print_screens): ");
  97. Serial.println(sizeof(_LCD_print_screens));
  98. for(i=0;i<=10;i++) { //sizeof(_LCD_print_buffors)
  99. Serial.print(" $i[");
  100. Serial.print(i);
  101. Serial.print("] screenID: ");
  102. Serial.print(_LCD_print_screens[i].screenID);
  103. String str((char*) _LCD_print_screens[i].LCDarray1);
  104. Serial.print(" LCDarray1 ph: ");
  105. Serial.println( str);
  106. Serial.print(" LCDarray1 len: ");
  107. Serial.println( sizeof(str));
  108. Serial.print(" LCDarray1: ");
  109. Serial.println( Serial.println((char*) _LCD_print_screens[i].LCDarray1) );
  110. Serial.print(" LCDarray2: ");
  111. Serial.write(_LCD_print_screens[i].LCDarray2);
  112. Serial.print(" time_seq_id: ");
  113. Serial.write( _LCD_print_screens[i].time_seq_id );
  114. Serial.print(" time_seq_id: ");
  115. Serial.println(_LCD_print_screens[i].time_seq_id);
  116. }
  117. }
  118. void _LCD_print_buffors_list(_LCD_print_bufforT* _LCD_print_buffors, int LCDtim ) {
  119. int i;
  120. Serial.print("sizeof(_LCD_print_buffors): ");
  121. Serial.println(sizeof(_LCD_print_buffors));
  122. for(i=0;i<=100;i++) { //sizeof(_LCD_print_buffors)
  123. Serial.print(" $i[");
  124. Serial.print(i);
  125. Serial.print("] _LCD_print_buffors screenID: ");
  126. Serial.print(_LCD_print_buffors[i].screenID);
  127. Serial.print(" cursor1: ");
  128. Serial.print(_LCD_print_buffors[i].cursor1);
  129. Serial.print(" cursor2: ");
  130. Serial.print(_LCD_print_buffors[i].cursor2);
  131. Serial.print(" character: ");
  132. Serial.write( _LCD_print_buffors[i].character );
  133. Serial.print(" time_seq_id: ");
  134. Serial.print(_LCD_print_buffors[i].time_seq_id);
  135. Serial.print(" time_min_run: ");
  136. Serial.println(_LCD_print_buffors[i].time_min_run);
  137. }
  138. lcd.setCursor(0,0);
  139. lcd.print("print_buffors"); // Print a message to the LCD.
  140. lcd.setCursor(0,1);
  141. lcd.print(String( _LCD_print_buffors[0].character));
  142. lcd.print(" , ");
  143. lcd.print(String( _LCD_print_buffors[1].character));
  144. delay(LCDtim * 5);
  145. }
  146. void LCD_print(String LCDarray1, String LCDarray2 ,int LCDtim) {
  147. delay(LCDtim);
  148. unsigned char LCDarray1buf[16];
  149. LCDarray1.toCharArray(LCDarray1buf, 16);
  150. unsigned char LCDarray2buf[16];
  151. LCDarray2.toCharArray(LCDarray2buf, 16);
  152. // lcd.setCursor(0,0);
  153. // lcd.print(LCDarray1);
  154. // lcd.setCursor(0,1);
  155. // lcd.print(LCDarray1);
  156. lcd.setCursor(16,0);
  157. for ( int positionCounter1 = 0;
  158. positionCounter1 <= 24 ;//LCDarray1.length(); // 24;
  159. positionCounter1++)
  160. {
  161. lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
  162. if(positionCounter1 >= LCDarray1.length()) lcd.print(" ");
  163. else lcd.print(LCDarray1[positionCounter1]); // Print a message to the LCD.
  164. delay(LCDtim); //wait for 250 microseconds
  165. if(positionCounter1==10) delay(LCDtim *7 );
  166. }
  167. // lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
  168. lcd.setCursor(16,1);
  169. for ( int positionCounter2 = 0;
  170. positionCounter2 <= 24;//LCDarray2.length();//24;
  171. positionCounter2++)
  172. {
  173. lcd.scrollDisplayLeft(); //Scrolls the contents of the display one space to the left.
  174. if(positionCounter2 >= LCDarray2.length()) lcd.print(" ");
  175. else lcd.print(LCDarray2[positionCounter2]); // Print a message to the LCD.
  176. delay(LCDtim); //wait for 250 microseconds
  177. if(positionCounter2==10) delay(LCDtim *7 );
  178. }
  179. delay(LCDtim * 5); //wait for 250 microseconds
  180. // lcd.clear(); //Clears the LCD screen and positions the cursor in the upper-left corner.
  181. delay(LCDtim);
  182. /*
  183. struct record
  184. {
  185. int bookId;
  186. int qtyInStock;
  187. };
  188. typedef struct record Record;
  189. void sold(int id, Record* records) {
  190. int i;
  191. for(i=0;i<3;i++) {
  192. if(records[i].bookId == id) {
  193. records[i].qtyInStock--;
  194. }
  195. }
  196. }
  197. */
  198. /*
  199. void updateId(int id, int new_id, Record* records) {
  200. int i;
  201. for(i=0;i<3;i++) {
  202. if(records[i].bookId == id) {
  203. records[i].bookid = new_id;
  204. }
  205. }
  206. }
  207. */
  208. /*
  209. void updateQty(int id, int new_qty, Record* records) {
  210. int i;
  211. for(i=0;i<3;i++) {
  212. if(records[i].bookId == id) {
  213. records[i].qtyInStock = new_qty;
  214. }
  215. }
  216. }
  217. */
  218. }
  219. String make_str16(String str){
  220. for(int i = 0; i < (16 - str.length()); i++)
  221. str += ' ';
  222. return str;
  223. }