Back to Parent

//COMMUNICATING VARIABLES


// This value will store the last time we published an event
long lastPublishedAt = 0;
// this is the time delay before we should publish a new event
// from this device
int publishAfter = 10000;

int location1 = D4;
int location2 = D6;

String color = "";


void setup()
{

Particle.function("flashToggle1", flashToggle);
Particle.variable("colorStatus",color);

Particle.function("lostBrello", lostBrello);

  Serial.println("hi");
  // vibrator actions
  pinMode( location1, OUTPUT );
  digitalWrite( location1, LOW);

  pinMode( location2, OUTPUT );
  digitalWrite( location2, LOW);
  // button actions
  Particle.subscribe(  "diot/2018/brello/umbrella_status" , handleSharedEvent);
}


void loop()
{
}

int flashToggle(String command) {


    Particle.publish("diot/2018/brello/umbrella_status", command);

      return 1;
  }

int lostBrello(String command) {
  Particle.publish("diot/2018/paired/");
return 1;
}

// Our event handlde requires two bits of information
// This gives us:
// A character array that consists of the event name
// A character array that contains the data published in the event we're responding to.
void handleSharedEvent(const char *event, const char *data)
{

  Serial.println("handle event");
    
    String umbrella_status = String( event );
    String update = String( data ); // convert to a string object
    
    updateStatus(update);
}

void updateStatus(const char* getData) {

Serial.println(getData);

  if ((String)getData == "returned") {
  digitalWrite( location1, LOW);
  digitalWrite( location2, HIGH);
  Serial.println("RETURNNNNNNED");
  color = "green";
  }
  else if ((String)getData == "taken") {
    digitalWrite( location1, HIGH);
    digitalWrite( location2, LOW);
    color = "red";

  }
}



// FUNCTION THAT takes info from rfid scanner and turns
//LED green or blue
// update variable that controls rgb values
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0