Back to Parent

int switchState = 0;
int previousSwitchState = 0;

int floorState = 0;
int previousFloorState = 0;
int status = 0;

int ledPin = D1;
int switchPin = D0;
int floorPin = D6;

void setup()
{
  pinMode( switchPin , INPUT_PULLUP); // sets pin as input
  pinMode( floorPin , INPUT_PULLDOWN);
  pinMode( ledPin , OUTPUT ); // sets pin as output
}

void loop()
{

  if (status == 1)
    {
      digitalWrite( ledPin, HIGH);
    }
  else if (status == 0)
    {
      digitalWrite( ledPin, LOW);
    }

   int switchState = digitalRead( switchPin );
  floorState = digitalRead( floorPin);

//LIGHT AND SYSTEM STATUS
// set system status flag where 1 is ON, 0 is OFF
//status effects state of LED
  if(switchState == HIGH)
  {
     status = 1;
  } else if (switchState == LOW)
  {
    status = 0;
  }

if(previousFloorState == LOW && floorState == HIGH && status == 1 ){

Serial.println("DOWN");
Particle.publish("bed_status", "sleeping");
}

if(previousFloorState == HIGH && floorState == LOW && status == 1 ){

Serial.println("GOT UP");
Particle.publish("active_status", "not sleeping");

}
previousFloorState = floorState;

}
Click to Expand

Content Rating

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

0