Back to Parent

int check_bed_new = 0;
int check_bed = 0;
int change = 0;
int off_speed = 92;
Servo bedmotor;

void setup() {
Serial.begin(9600);
Time.zone(-5);
pinMode(D0,OUTPUT);
pinMode(D1,INPUT);
pinMode(D3,INPUT);
pinMode(D4,INPUT);
pinMode(A0,INPUT);
bedmotor.attach(D2);
// bedmotor.write(off_speed);
}

void loop(){
  int pressuremain = digitalRead(D1);
  int pressureleft = digitalRead(D3);
  int pressureright = digitalRead(D4);
  int val = analogRead(A0);
  // Serial.println(val);



  if (pressuremain == HIGH){
    delay(400);
    if (pressuremain == HIGH){
      while(val>1750){
      bedmotor.write(80);
      delay(50);
      Particle.process();
      val = analogRead(A0);
      }
      bedmotor.write(off_speed);
      digitalWrite(D0,HIGH);
      check_bed_new = 1;
    }
  }
  else if(pressuremain == LOW && pressureleft == HIGH && pressureright == HIGH){
    delay(400);
    if(pressuremain == LOW && pressureleft == HIGH && pressureright == HIGH){
      while(val<1800){
      bedmotor.write(103);
      delay(50);
      Particle.process();
      val = analogRead(A0);
      }
      bedmotor.write(off_speed);
      digitalWrite(D0,LOW);
      check_bed_new = 0;
    }
  }
  else if(pressuremain == LOW && pressureleft == LOW && pressureright == LOW){
    delay(400);
    if(pressuremain == LOW && pressureleft == LOW && pressureright == LOW){
      while(val<1800){
      bedmotor.write(103);
      delay(50);
      Particle.process();
      val = analogRead(A0);
      }
      bedmotor.write(off_speed);
      digitalWrite(D0,LOW);
      check_bed_new = 0;
    }
  }



change = check_bed_new - check_bed;
if (change == 1){
  Particle.publish("justgotinbedmyhomie",PUBLIC);
}

if (change == -1){
  Particle.publish("justgotoutofbedfool",PUBLIC);
}

check_bed = check_bed_new;
}
Click to Expand

Content Rating

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

0