Back to Parent

int ledPin = D0;
int buttonPin = D1;
int buttonPinEnter = D3;
int buttonPinLeave = D2;
bool chapIn = FALSE;
int Aware_Timer = 0;

void setup()
{
  pinMode(buttonPin , INPUT_PULLUP);
  pinMode(buttonPinEnter , INPUT_PULLUP);
  pinMode(buttonPinLeave , INPUT_PULLUP);
  pinMode(ledPin , OUTPUT);
}
// If button is pressed, green light turned on and then off using a timer
void loop()
{
  int buttonState = digitalRead(buttonPin);
  int buttonStateEnter = digitalRead(buttonPinEnter);
  int buttonStateLeave = digitalRead(buttonPinLeave);

  // Handles case of RFID scan in
  if(buttonStateEnter == HIGH) {
    chapIn = TRUE;
    Particle.publish("DIOT2018yellow","HIGH");
    Particle.publish("DIOT2018blue","LOW");
  }
  //Handles case of chaperone leaving without the Aware button active
  if(buttonStateLeave == HIGH){
    chapIn = FALSE;
    Particle.publish("DIOT2018green","LOW");
    Particle.publish("DIOT2018yellow","LOW");
    Particle.publish("DIOT2018blue","HIGH");
  }
  //Handles case of Aware button press with interval checks to see if chaperone has left
  if(buttonState == HIGH) {
    Particle.publish("DIOT2018green","HIGH");
    Particle.publish("DIOT2018yellow","LOW");
    Particle.publish("DIOT2018blue","LOW");
    digitalWrite(ledPin, HIGH);
    while(Aware_Timer < 10000 && chapIn == TRUE){
      Aware_Timer += 100;
      char intervalCheck = digitalRead(buttonPinLeave);
      if (intervalCheck == 'HIGH') {
        Particle.publish("DIOT2018green","LOW");
        Particle.publish("DIOT2018yellow","LOW");
        Particle.publish("DIOT2018blue","HIGH");
        digitalWrite(ledPin, LOW);
        break;
      }
    }
    Aware_Timer = 0;
  }
}
Click to Expand

Content Rating

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

0