Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.32 KB | None | 0 0
  1. // This #include statement was automatically added by the Particle IDE.
  2. #include <Adafruit_HX8357.h>
  3.  
  4. // This #include statement was automatically added by the Particle IDE.
  5.  
  6.  
  7. // Use software SPI
  8. Adafruit_HX8357 tft = Adafruit_HX8357(D6, D7, D5, D3, -1, D4); //(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST, MISO);
  9.  
  10.  
  11. void setup() {
  12. Serial.begin(115200);
  13. Serial.println("HX8357D Test!");
  14.  
  15. tft.begin(HX8357D);
  16. tft.setRotation(1); //choose 1-4
  17.  
  18. // Lets listen for the hook response
  19. Particle.subscribe("hook-response/In_one", got43iData, MY_DEVICES);
  20. Particle.subscribe("hook-response/Out_Fourty_Three", got43oData, MY_DEVICES);
  21. Particle.subscribe("hook-response/In_Three", gotThree_i_Data, MY_DEVICES);
  22. Particle.subscribe("hook-response/Out_Three", gotThree_o_Data, MY_DEVICES);
  23.  
  24. // Lets give ourselves 3 seconds before we actually start the program.
  25. // That will just give us a chance to open the serial monitor before the program sends the request
  26. for(int i=0;i<3;i++) {
  27. Serial.println("waiting " + String(3-i) + " seconds before we publish");
  28. tft.fillScreen(HX8357_BLACK);
  29. tft.setCursor(0, 0);
  30. tft.setTextSize(2);
  31. tft.println("waiting " + String(3-i) + " seconds before we publish");
  32. delay(1000);
  33. }
  34. tft.fillScreen(HX8357_BLACK);
  35.  
  36. }
  37.  
  38. void loop(void) {
  39. // publish the event that will trigger our Webhook
  40. Particle.publish("In_one");
  41. Particle.publish("Out_Fourty_Three");
  42. Particle.publish("In_Three");
  43. Particle.publish("Out_Three");
  44.  
  45. // and wait at least 30 seconds before doing it again
  46. delay(30000);
  47. tft.fillScreen(HX8357_BLACK);
  48. }
  49.  
  50. void got43iData(const char *name, const char *data) {
  51.  
  52. String str = String(data);
  53. Serial.println(data);
  54.  
  55. char dataBuffer[256]="";
  56. strcpy(dataBuffer, data);
  57. strtok(0,0);
  58. int muni1 = atof(strtok(dataBuffer, "*"));
  59. int muni2i = atof(strtok(NULL, "*"));
  60.  
  61. Serial.println(muni1);
  62.  
  63. tft.setCursor(0, 0);
  64. tft.setTextSize(5);
  65. tft.setTextColor(HX8357_GREEN);
  66. tft.print("1 inbound: ");
  67. tft.print(muni1);
  68. tft.print(",");
  69. tft.println(muni2i);
  70.  
  71. }
  72.  
  73. void got43oData(const char *name, const char *data) {
  74.  
  75. String str = String(data);
  76. Serial.println(data);
  77.  
  78. char dataBuffer[256]="";
  79. strcpy(dataBuffer, data);
  80. strtok(0,0);
  81. int muni2 = atof(strtok(dataBuffer, "*"));
  82.  
  83.  
  84. Serial.println(muni2);
  85.  
  86. tft.setCursor(0,50);
  87. tft.setTextSize(5);
  88. tft.setTextColor(HX8357_WHITE);
  89. tft.print("43 outbound: ");
  90. tft.println(muni2);
  91.  
  92. }
  93. // This function will get called when weather data comes in
  94. void gotThree_i_Data(const char *name, const char *data) {
  95.  
  96. String str = String(data);
  97. Serial.println(data);
  98.  
  99. char dataBuffer[256]="";
  100. strcpy(dataBuffer, data);
  101. strtok(0,0);
  102. int muni3 = atof(strtok(dataBuffer, "*"));
  103.  
  104. Serial.println(muni3);
  105.  
  106. tft.setCursor(0, 100);
  107. tft.setTextSize(5);
  108. tft.setTextColor(HX8357_YELLOW);
  109. tft.print("3 inbound: ");
  110. tft.println(muni3);
  111.  
  112. }
  113.  
  114. void gotThree_o_Data(const char *name, const char *data) {
  115.  
  116. String str = String(data);
  117. Serial.println(data);
  118.  
  119. char dataBuffer[256]="";
  120. strcpy(dataBuffer, data);
  121. strtok(0,0);
  122. int muni4 = atof(strtok(dataBuffer, "*"));
  123.  
  124. Serial.println(muni4);
  125.  
  126. tft.setCursor(0, 150);
  127. tft.setTextSize(5);
  128. tft.setTextColor(HX8357_CYAN);
  129. tft.print("3 outbound: ");
  130. tft.println(muni4);
  131.  
  132. // tft.setCursor(0, 200);
  133. // tft.setTextSize(2);
  134. // tft.println(" .~~~~. ");
  135. // tft.println(" i====i_ ");
  136. // tft.println(" |cccc|_) ");
  137. // tft.println(" |cccc| ");
  138. // tft.println(" `-==-' ");
  139.  
  140. // tft.setCursor (20,200);
  141. // tft.setTextSize(1);
  142. //tft.println(" __ ============================== ");
  143. // tft.println(" ALCATRAZ /__\ || ||<(.)>||<(.)>|| || ");
  144. // tft.println(" ____________| | || _|| || ||_ || ");
  145. // tft.println(" |_|_|_|_|_|_| | || (__D || C__) || ");
  146. // tft.println(" |_|_|_|_|_|_|__| || (__D || C__) || ");
  147. // tft.println(" A@\|_|_|_|_|_|/@@Aa || (__D || C__) || ");
  148. // tft.println(" aaA@@@@@@@@@@@@@@@@@@@aaaA || (__D || C__) || ");
  149. // tft.println(" A@@@@@@@@@@@@@@@@@@@@@@@@@@A || || || || || ");
  150. // tft.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ============================== ");
  151.  
  152. tft.setCursor (0, 190);
  153. tft.setTextSize(1);
  154. tft.println(" .-------------------------------------------------------------." );
  155. tft.println(" '------..-------------..----------..----------..----------..--.|" );
  156. tft.println(" | \\ || || || || ||" );
  157. tft.println(" | \\ || || || || || ");
  158. tft.println(" | .. || _ _ || _ _ || _ _ || _ _|| ||" );
  159. tft.println(" | || || // // || // // ||// // || // //|| /||" );
  160. tft.println(" |_.------'''----------''----------''----------''----------''--'|" );
  161. tft.println(" |)| | | | | | | ||==| |" );
  162. tft.println(" | | | _-_ | | | | .-. | ||==| C|" );
  163. tft.println(" | | __ |.'.-.' | _ | _ | |.'.-.'. | __ | ' __=='" );
  164. tft.println(" '---------'|( )|'----------------------'|( )|'----------" );
  165. tft.println(" '-' '-' " );
  166. //tft.println(" / |");
  167. // tft.println(" / / /___");
  168. // tft.println(" / '~~~~~__");
  169. // tft.println(" \_\_______________\_'_?");
  170. }
  171.  
  172. // Returns any text found between a start and end string inside 'str'
  173. // example: startfooend -> returns foo
  174. String tryExtractString(String str, const char* start, const char* end) {
  175. if (str == NULL) {
  176. return "";
  177. }
  178.  
  179. int idx = str.indexOf(start);
  180. if (idx < 0) {
  181. return "";
  182. }
  183.  
  184. int endIdx = str.indexOf(end);
  185. if (endIdx < 0) {
  186. return "";
  187. }
  188.  
  189. return str.substring(idx + strlen(start), endIdx);
  190. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement