Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <SparkJson.h>
- #include <LiquidCrystal.h>
- LiquidCrystal lcd(5, 4, 3, 2, 1, 0);
- unsigned long lastTime = 0;
- void setup() {
- Serial.begin(9600);
- Particle.subscribe("hook-response/PubTrans", parseData, MY_DEVICES);
- lcd.begin(20, 4);
- }
- void parseData(const char *event, const char *data) {
- lcd.clear();
- lcd.setCursor(0, 0);
- lcd.print("Next buses:");
- char *mutableCopy = strdup(data);
- int numFound = 0;
- char *record = strtok(mutableCopy, ";");
- while(record) {
- if (strncmp(record, "2,", 2) == 0) {
- // Begins with 2,
- if (++numFound <= 3) {
- Serial.println(&record[2]);
- lcd.setCursor(0, numFound);
- lcd.print(&record[2]);
- }
- }
- record = strtok(NULL, ";");
- }
- free(mutableCopy); //not showing all 3 times but just the next time??
- }
- void loop() {
- unsigned long now = millis();
- if ((now - lastTime) >= 60000) {
- String data = String(10);
- Particle.publish("PubTrans", data, PRIVATE);
- lcd.setCursor(15, 3);
- Serial.println(Time.now());
- lastTime = now;
- } // End 1-minute
- } // End Loop
Add Comment
Please, Sign In to add comment