Back to Parent

//SkillDev-4

int servoPin = A3;
int servoPos = 0;
int pushButton = D2;
int buttonState;        //store the reading from the button

bool calAlert_Status = false;       //to check if the calender alert occured
unsigned long lastUpdate = 0;       //to check track the time usin millis()
unsigned long now =0;           //to check track the time usin millis()

Servo myServo;

void setup() {
    //attaching servo Pin 'A3' to Servo object
    myServo.attach(A3);
    
    Particle.function("DrinkWater", setCalAlert);
    
    pinMode (pushButton, INPUT_PULLUP);

}

void loop() {
    
    buttonState = digitalRead( pushButton );
    if (buttonState == LOW){
       
        calAlert_Status = false;
        servoPos = 0;
        myServo.write(servoPos);
    }
    

    
    if (calAlert_Status == true){
        
     
        
        now = millis();
    
        if ((now - lastUpdate) < 2500) {
    
            servoPos = map ((now - lastUpdate), 0, 2500, 0, 90);
            myServo.write(servoPos);
        }else{
            
            if ((now - lastUpdate) < 5000) {
    
                servoPos = map ((now - lastUpdate), 2500, 5000, 0, 90);
                myServo.write((90 - servoPos));
                
            }else{
                delay(200);
                lastUpdate = millis();
            }
        }
    }
}

int setCalAlert(String command){
    
    if(command == "True") {
        calAlert_Status = true;
        //servoStart = 1;
        lastUpdate = millis();
        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