SkillDev4 - Rahul Jha
Made by Rahul Jha
Made by Rahul Jha
to create an interesting notification using a servo.
Created: December 4th, 2021
The video for the demonstration is below:
//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
1. Learned the implementation of servo and creating notifications using cloud triggers.
2. Definitely it's a simple project but it has been of great use for me since I often missed getting up to drink water for long durations while studying.
3. Due to time constraints could not look for more interesting notifications. However, in the future, I plan to connect the servo to some analog data to indicate cool effects happening over the internet.