Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // This #include statement was automatically added by the Particle IDE.
- #include <Adafruit_HX8357.h>
- // This #include statement was automatically added by the Particle IDE.
- // Use software SPI
- Adafruit_HX8357 tft = Adafruit_HX8357(D6, D7, D5, D3, -1, D4); //(TFT_CS, TFT_DC, MOSI, SCK, TFT_RST, MISO);
- void setup() {
- Serial.begin(115200);
- Serial.println("HX8357D Test!");
- tft.begin(HX8357D);
- tft.setRotation(1); //choose 1-4
- // Lets listen for the hook response
- Particle.subscribe("hook-response/In_one", got43iData, MY_DEVICES);
- Particle.subscribe("hook-response/Out_Fourty_Three", got43oData, MY_DEVICES);
- Particle.subscribe("hook-response/In_Three", gotThree_i_Data, MY_DEVICES);
- Particle.subscribe("hook-response/Out_Three", gotThree_o_Data, MY_DEVICES);
- // Lets give ourselves 3 seconds before we actually start the program.
- // That will just give us a chance to open the serial monitor before the program sends the request
- for(int i=0;i<3;i++) {
- Serial.println("waiting " + String(3-i) + " seconds before we publish");
- tft.fillScreen(HX8357_BLACK);
- tft.setCursor(0, 0);
- tft.setTextSize(2);
- tft.println("waiting " + String(3-i) + " seconds before we publish");
- delay(1000);
- }
- tft.fillScreen(HX8357_BLACK);
- }
- void loop(void) {
- // publish the event that will trigger our Webhook
- Particle.publish("In_one");
- Particle.publish("Out_Fourty_Three");
- Particle.publish("In_Three");
- Particle.publish("Out_Three");
- // and wait at least 30 seconds before doing it again
- delay(30000);
- tft.fillScreen(HX8357_BLACK);
- }
- void got43iData(const char *name, const char *data) {
- String str = String(data);
- Serial.println(data);
- char dataBuffer[256]="";
- strcpy(dataBuffer, data);
- strtok(0,0);
- int muni1 = atof(strtok(dataBuffer, "*"));
- int muni2i = atof(strtok(NULL, "*"));
- Serial.println(muni1);
- tft.setCursor(0, 0);
- tft.setTextSize(5);
- tft.setTextColor(HX8357_GREEN);
- tft.print("1 inbound: ");
- tft.print(muni1);
- tft.print(",");
- tft.println(muni2i);
- }
- void got43oData(const char *name, const char *data) {
- String str = String(data);
- Serial.println(data);
- char dataBuffer[256]="";
- strcpy(dataBuffer, data);
- strtok(0,0);
- int muni2 = atof(strtok(dataBuffer, "*"));
- Serial.println(muni2);
- tft.setCursor(0,50);
- tft.setTextSize(5);
- tft.setTextColor(HX8357_WHITE);
- tft.print("43 outbound: ");
- tft.println(muni2);
- }
- // This function will get called when weather data comes in
- void gotThree_i_Data(const char *name, const char *data) {
- String str = String(data);
- Serial.println(data);
- char dataBuffer[256]="";
- strcpy(dataBuffer, data);
- strtok(0,0);
- int muni3 = atof(strtok(dataBuffer, "*"));
- Serial.println(muni3);
- tft.setCursor(0, 100);
- tft.setTextSize(5);
- tft.setTextColor(HX8357_YELLOW);
- tft.print("3 inbound: ");
- tft.println(muni3);
- }
- void gotThree_o_Data(const char *name, const char *data) {
- String str = String(data);
- Serial.println(data);
- char dataBuffer[256]="";
- strcpy(dataBuffer, data);
- strtok(0,0);
- int muni4 = atof(strtok(dataBuffer, "*"));
- Serial.println(muni4);
- tft.setCursor(0, 150);
- tft.setTextSize(5);
- tft.setTextColor(HX8357_CYAN);
- tft.print("3 outbound: ");
- tft.println(muni4);
- // tft.setCursor(0, 200);
- // tft.setTextSize(2);
- // tft.println(" .~~~~. ");
- // tft.println(" i====i_ ");
- // tft.println(" |cccc|_) ");
- // tft.println(" |cccc| ");
- // tft.println(" `-==-' ");
- // tft.setCursor (20,200);
- // tft.setTextSize(1);
- //tft.println(" __ ============================== ");
- // tft.println(" ALCATRAZ /__\ || ||<(.)>||<(.)>|| || ");
- // tft.println(" ____________| | || _|| || ||_ || ");
- // tft.println(" |_|_|_|_|_|_| | || (__D || C__) || ");
- // tft.println(" |_|_|_|_|_|_|__| || (__D || C__) || ");
- // tft.println(" A@\|_|_|_|_|_|/@@Aa || (__D || C__) || ");
- // tft.println(" aaA@@@@@@@@@@@@@@@@@@@aaaA || (__D || C__) || ");
- // tft.println(" A@@@@@@@@@@@@@@@@@@@@@@@@@@A || || || || || ");
- // tft.println("^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ============================== ");
- tft.setCursor (0, 190);
- tft.setTextSize(1);
- tft.println(" .-------------------------------------------------------------." );
- tft.println(" '------..-------------..----------..----------..----------..--.|" );
- tft.println(" | \\ || || || || ||" );
- tft.println(" | \\ || || || || || ");
- tft.println(" | .. || _ _ || _ _ || _ _ || _ _|| ||" );
- tft.println(" | || || // // || // // ||// // || // //|| /||" );
- tft.println(" |_.------'''----------''----------''----------''----------''--'|" );
- tft.println(" |)| | | | | | | ||==| |" );
- tft.println(" | | | _-_ | | | | .-. | ||==| C|" );
- tft.println(" | | __ |.'.-.' | _ | _ | |.'.-.'. | __ | ' __=='" );
- tft.println(" '---------'|( )|'----------------------'|( )|'----------" );
- tft.println(" '-' '-' " );
- //tft.println(" / |");
- // tft.println(" / / /___");
- // tft.println(" / '~~~~~__");
- // tft.println(" \_\_______________\_'_?");
- }
- // Returns any text found between a start and end string inside 'str'
- // example: startfooend -> returns foo
- String tryExtractString(String str, const char* start, const char* end) {
- if (str == NULL) {
- return "";
- }
- int idx = str.indexOf(start);
- if (idx < 0) {
- return "";
- }
- int endIdx = str.indexOf(end);
- if (endIdx < 0) {
- return "";
- }
- return str.substring(idx + strlen(start), endIdx);
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement