Servo myservo; // create servo object to control a servo
// a maximum of eight servo objects can be created
// variable to store the servo position
int startpos = 165;
int pos = startpos;
int endpos = 35;
int drink = 0;
void setup() {
Serial.begin(9600);
myservo.attach(D4); // attach the servo on the D0 pin to the servo object
myservo.write(startpos); // test the servo by moving it to 25°
pinMode(D5, INPUT);
attachInterrupt(D5, did_drink, CHANGE);
}
void loop() {
// begin API calls on loop, parse and raise or lower servo arm
if (pos > endpos){
pos--;
myservo.write(pos);
}
delay(100);
}
void did_drink() {
pos = startpos;
myservo.write(pos);
}
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. .