Created
December 16, 2020 19:56
-
-
Save aaristov/75686ccd3c1b41941da9b17c95d097ce to your computer and use it in GitHub Desktop.
Arduino code for Tea Maker by Andrey Aristov
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <Servo.h> | |
Servo myservo; // create servo object to control a servo | |
// twelve servo objects can be created on most boards | |
int pos = 0; // variable to store the servo position | |
int max_pos = 150; | |
int cur_pos = 0; | |
long tea_time = 180000; | |
void goDown(){ | |
for (pos = cur_pos; pos <= max_pos; pos += 1) { // goes from 0 degrees to 180 degrees | |
// in steps of 1 degree | |
Serial.println(pos); | |
myservo.write(pos); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
cur_pos = max_pos; | |
} | |
void goUp(){ | |
if (cur_pos > 0){ | |
for (pos = cur_pos; pos >= 0; pos -= 1) { // goes from 180 degrees to 0 degrees | |
myservo.write(pos); | |
Serial.println(pos); // tell servo to go to position in variable 'pos' | |
delay(15); // waits 15ms for the servo to reach the position | |
} | |
} | |
cur_pos = 0; | |
} | |
void setup() { | |
Serial.begin(9600); | |
myservo.attach(9); // attaches the servo on pin 9 to the servo object | |
myservo.write(cur_pos); | |
} | |
void loop() { | |
goDown(); | |
delay(tea_time); | |
goUp(); | |
delay(50000000); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment