//Final Code
//Test components
int ledPin = D2;
int testButton = D5;
//Actual components
int servoPin = A5;
int pirSensor = A2;
int pirValue = 0;
Servo myServo;
int servoAngle = 60;
void setup(){
pinMode(testButton, INPUT_PULLUP);
pinMode(pirSensor, INPUT);
pinMode(ledPin, OUTPUT);
pinMode(servoPin, OUTPUT);
myServo.attach(A5);
Serial.begin(9600);
// allows function to be used in IFTTT
Particle.function("emailSwitch", waterGunFirst);
}
void loop(){
//// FOR TESTING PURPOSES
// if (digitalRead(testButton) == LOW){
// digitalWrite(ledPin,HIGH);
// waterGunFirst("String");
// }
// if (digitalRead(testButton) == HIGH){
// digitalWrite(ledPin,LOW);
// }
}
int waterGunFirst(String){
//initial water to wake up user, 3 shots
for (int i=0; i<3;i++){
myServo.write(20);
delay(200);
myServo.write(180);
delay(200);
myServo.write(20);
}
//time for user to get out of bed
delay(10000);
//checks for motion of user getting out of bed
pirValue = digitalRead(pirSensor);
if (pirValue == HIGH){
//light goes on to signify "safety" from second volley
digitalWrite(ledPin, HIGH);
delay(10000);
digitalWrite(ledPin, LOW);
return 1;
}
else{
//Second volley sequence initiated
waterGunSecond("String");
return 1;
}
}
int waterGunSecond(String){
for (int i=0; i<100;i++){
//Button to stop the second volley
if (digitalRead(testButton) == LOW){
digitalWrite(ledPin, HIGH);
delay(5000);
digitalWrite(ledPin, LOW);
return 1;
}
else{
myServo.write(20);
delay(200);
myServo.write(180);
delay(200);
myServo.write(20);
}
}
return 1;
}
Click to Expand
Content Rating
Is this a good/useful/informative piece of content to include in the project? Have your say!
You must login before you can post a comment. .