Back to Parent

//SERVER SETUP
int servoPin = A3; 
int servoPos = 0; 
Servo servo; //sets up servo instance

//SWITCH SETUP
int switchPin = D2; 
int switchState = LOW; 


// Set Countdown Period
bool setCountdown = FALSE; 

void setup() {
    
    // Set switch as input 
    pinMode(switchPin, INPUT_PULLUP); 
    
    //Server setup
    servo.attach(servoPin); 

    servo.write(0); //set to 0 degrees
    
    // Set up cloud particle function (IFTTT)
    Particle.function("eventAlert", handleEventAlert); 
    
}

void loop() {
    
    int switchState = digitalRead(switchPin); 
    
    if (switchState == LOW) {
  
        if (setCountdown == TRUE) {
            
            for (int i = 0; i <180; i++) {
                servo.write(i); 
                delay(333.33);
            }
        }
    }
}


// Define IFTTT Calendar Function Value
int handleEventAlert ( String cmd) {
    
    if(cmd == "TRUE") {
        setCountdown = TRUE; 

        return 1; 
    }

    return -1; 
}
Click to Expand

Content Rating

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

0