Back to Parent

Code for the Kitchen Top
int servoPin = D2;
Servo steam;
int fanDraw = D3;
int angle = 0;   // servo position in degrees
int pumpPin = D1;
int pumpStrength = 255;

void setup()
{
  pinMode(fanDraw, OUTPUT);
  /*pinMode(leverButton, INPUT_PULLUP);*/
  steam.attach(servoPin);
  steam.write(0);
  delay(1000);
  Serial.begin(9600);
  Particle.subscribe("diotthanku2", Draw);
  steam.detach();
  Particle.variable("Strength", &pumpStrength, INT);
  pinMode(pumpPin, OUTPUT);
  /*Particle.subscribe("MoveLotus",MoveLotus);*/
  /*Particle.subscribe("StopLotus",StopLotus);*/
}

void loop()
{

}

/*void Draw(const char *event, const char *data)
{
  digitalWrite(fanDraw, HIGH);
  Serial.println("fanDraw");
  delay(3000);
  digitalWrite(fanDraw, LOW);
}*/

/*void MoveLotus(const char *event, const char *data)
{
  Serial.println("fanLotus");
  delay(10000);
  digitalWrite(fanLotus, HIGH);
  delay(10000);
  Serial.println("end");
}*/

/*void StopLotus(const char *event, const char *data)
{
  digitalWrite(fanLotus, LOW);
  Serial.println("StopLotus");
  delay(500);
}*/

void Draw(const char *event, const char *data)
{
  // scan from 0 to 180 degrees
  steam.attach(servoPin);
  delay(500);
  Serial.println("Draw Event Triggered");
  steam.write(30);
  digitalWrite(fanDraw, HIGH);
  /*Serial.println( pumpStrength);*/
  analogWrite( pumpPin, pumpStrength );
  delay(100) ;
  Serial.println("Door Opened, Fan moving and water pump woirking, will stay on for 10 seconds");
  delay(10000);
  steam.write(0);
  digitalWrite(fanDraw, LOW);
  analogWrite( pumpPin, 0 );
  Serial.println("Door Closed, fan stopped, water pump stopped, servo detached in 2 seconds");
  delay(2000);
    /*
  if (angle == 0){
    angle = 170;
    steam.write(angle);

  }
  if (angle >= 170){
    angle = 0;
    steam.write(angle);

    digitalWrite(fanDraw, HIGH);
    delay(2000);
    steam.detach();
    delay(8000);
    digitalWrite(fanDraw, LOW);
    Serial.println("Fan stopped");
  }*/
  steam.detach();
}
Click to Expand

Content Rating

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

0