Back to Parent

int fanPIN = D0;
int sweatPIN = A0;
int buttonPush = A2;
int servoDelay = 100;
Servo massageServo;
int servoPos = 0;

void setup() {
 Serial.begin(9600);
 massageServo.attach(A5);
 // Set pins to input or output
 //pinMode(pulsePIN, INPUT);
 pinMode(sweatPIN, INPUT);
 pinMode(fanPIN, OUTPUT);
 digitalWrite(fanPIN, LOW);

 Particle.subscribe("cmu/diot2017/breakButtonStart" , buttonHandler);
  //Particle.subscribe("cmu/diot2017/breakButtonEnd" , buttonHandler);
  Particle.subscribe("diot2017/jamiecooldown" , fanHandler);

}

void loop() {
 int buttonState = analogRead(buttonPush);
 Serial.println(buttonState);
 int schweaty = analogRead(A0);
 //Serial.println(schweaty);
 delay(500);


 if (buttonState > 3000){
    digitalWrite(fanPIN, HIGH);
    massageroutine();
    Serial.print("fan on ");
 }else{
   digitalWrite(fanPIN, LOW);



if (schweaty > 3000){
    digitalWrite(fanPIN, HIGH);
}else{
    digitalWrite(fanPIN, LOW);
}
}}



void massageroutine(){
massageServo.write(5);
delay(1200);
massageServo.write(175);
delay(1200);
massageServo.write(5);
delay(1200);
massageServo.write(175);
delay(1200);
massageServo.write(5);
delay(1200);
massageServo.write(175);
delay(1200);
massageServo.write(5);
delay(1200);
massageServo.write(175);
delay(1200);
  }


void buttonHandler(const char *event,const char *data)
{ //this is the handler for receiving the subscribed event
  String apronButtonPushed = data;
  //apronButton = apronButtonPushed.toInt();
  massageroutine();
}

void fanHandler(const char *event,const char *data)
{ //this is the handler for receiving the subscribed event
  Serial.print("recieved event ");
  digitalWrite(fanPIN, HIGH);
  delay(5000);
  digitalWrite(fanPIN, LOW);

}
Click to Expand

Content Rating

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

0