LCD1602.h 12 KB

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